Added interaction speed modifiers/inverters

Disable cotire
Enable Xcursor and Xinerama libraries on Linux builds
This commit is contained in:
Alexander Bock
2015-02-23 15:58:05 +01:00
parent 3ba9cbdb96
commit b6e0bd1043
6 changed files with 184 additions and 43 deletions
+4 -1
View File
@@ -46,7 +46,7 @@ set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${OPENSPACE_LIBRARY_DIR})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${OPENSPACE_BINARY_DIR})
include(cotire)
#include(cotire)
# Make sure a build type is set. Default is Debug.
if(NOT CMAKE_BUILD_TYPE)
@@ -91,6 +91,9 @@ include_directories(${GHOUL_ROOT_DIR}/ext/boost)
find_package(SGCT REQUIRED)
include_directories(${SGCT_INCLUDE_DIRECTORIES})
set(DEPENDENT_LIBS ${DEPENDENT_LIBS} ${SGCT_LIBRARIES})
if (UNIX)
set(DEPENDENT_LIBS ${DEPENDENT_LIBS} Xcursor Xinerama)
endif ()
# GLM
set(GLM_ROOT_DIR "${GHOUL_ROOT_DIR}/ext/glm")
@@ -111,9 +111,6 @@ public:
void mousePositionCallback(int x, int y);
void mouseScrollWheelCallback(int pos);
//<<<<<<< HEAD
//double dt();
//=======
double deltaTime() const;
void orbitDelta(const glm::quat& rotation);
@@ -133,6 +130,15 @@ public:
void resetKeyBindings();
void bindKey(int key, const std::string& lua);
void setInteractionSensitivity(float sensitivity);
float interactionSensitivity() const;
void setInvertRoll(bool invert);
bool invertRoll() const;
void setInvertRotation(bool invert);
bool invertRotation() const;
/**
* Returns the Lua library that contains all Lua functions available to affect the
* interaction. The functions contained are
@@ -145,13 +151,6 @@ public:
private:
friend class Controller;
//<<<<<<< HEAD
// Camera* _camera;
// bool _enabled;
// SceneGraphNode* _node;
//
// double _dt;
//=======
InteractionHandler(const InteractionHandler&) = delete;
InteractionHandler& operator=(const InteractionHandler&) = delete;
InteractionHandler(InteractionHandler&&) = delete;
@@ -163,24 +162,16 @@ private:
double _deltaTime;
std::mutex _mutex;
//<<<<<<< HEAD
// // used for calling when updating and deallocation
// std::vector<ExternalControl*> _controllers;
//
// // for locking and unlocking
// std::mutex _cameraGuard;
bool _validKeyLua;
std::multimap<int, std::string > _keyLua;
float _controllerSensitivity;
bool _invertRoll;
bool _invertRotation;
KeyboardController* _keyboardController;
MouseController* _mouseController;
std::vector<Controller*> _controllers;
// glm::vec3 mapToTrackball(glm::vec2 mousePos);
// glm::vec3 mapToCamera(glm::vec3 trackballPos);
// void trackballRotate(int x, int y);
};
} // namespace interaction
+1 -1
View File
@@ -1,4 +1,4 @@
--openspace.setPropertyValue('Earth.renderable.colorTexture', '${OPENSPACE_DATA}/modules/mars/textures/mars.png')
openspace.setInvertRoll(true);
openspace.time.setTime("2015-07-14T10:50:00.00") -- PLUTO
-- NH takes series of images from visible to dark side (across terminator)
+3 -3
View File
@@ -155,9 +155,9 @@ include_directories("${HEADER_ROOT_DIR}")
add_executable(OpenSpace ${SOURCE_ROOT_DIR}/main.cpp ${OPENSPACE_HEADER} ${OPENSPACE_SOURCE})
target_link_libraries(OpenSpace ${DEPENDENT_LIBS})
if (NOT UNIX)
cotire(OpenSpace)
endif ()
#if (NOT UNIX)
#cotire(OpenSpace)
#endif ()
GhoulCopySharedLibraries(OpenSpace)
add_subdirectory(tests)
+147 -5
View File
@@ -298,6 +298,84 @@ int distance(lua_State* L) {
return 0;
}
/**
* \ingroup LuaScripts
* setInteractionSensitivity(double):
* Changes the global interaction sensitivity to the passed value
*/
int setInteractionSensitivity(lua_State* L) {
int nArguments = lua_gettop(L);
if (nArguments != 1)
return luaL_error(L, "Expected %i arguments, got %i", 1, nArguments);
double sensitivity = luaL_checknumber(L, -1);
OsEng.interactionHandler()->setInteractionSensitivity(sensitivity);
return 0;
}
/**
* \ingroup LuaScripts
* interactionSensitivity():
* Returns the current, global interaction sensitivity
*/
int interactionSensitivity(lua_State* L) {
float sensitivity = OsEng.interactionHandler()->interactionSensitivity();
lua_pushnumber(L, sensitivity);
return 1;
}
/**
* \ingroup LuaScripts
* setInvertRoll(bool):
* Determines if the roll movement is inverted
*/
int setInvertRoll(lua_State* L) {
int nArguments = lua_gettop(L);
if (nArguments != 1)
return luaL_error(L, "Expected %i arguments, got %i", 1, nArguments);
bool invert = lua_toboolean(L, -1);
OsEng.interactionHandler()->setInvertRoll(invert);
return 0;
}
/**
* \ingroup LuaScripts
* invertRoll():
* Returns the current setting for inversion of roll movement
*/
int invertRoll(lua_State* L) {
bool invert = OsEng.interactionHandler()->invertRoll();
lua_pushboolean(L, invert);
return 1;
}
/**
* \ingroup LuaScripts
* setInvertRotation(bool):
* Determines if the rotation movement is inverted
*/
int setInvertRotation(lua_State* L) {
int nArguments = lua_gettop(L);
if (nArguments != 1)
return luaL_error(L, "Expected %i arguments, got %i", 1, nArguments);
bool invert = lua_toboolean(L, -1);
OsEng.interactionHandler()->setInvertRotation(invert);
return 0;
}
/**
* \ingroup LuaScripts
* invertRotation():
* Returns the current setting for inversion of rotation movement
*/
int invertRotation(lua_State* L) {
bool invert = OsEng.interactionHandler()->invertRotation();
lua_pushboolean(L, invert);
return 1;
}
} // namespace luascriptfunctions
//InteractionHandler::InteractionHandler() {
@@ -360,6 +438,9 @@ namespace interaction {
InteractionHandler::InteractionHandler()
: _camera(nullptr)
, _focusNode(nullptr)
, _controllerSensitivity(10.f)
, _invertRoll(false)
, _invertRotation(false)
, _keyboardController(nullptr)
, _mouseController(nullptr)
{
@@ -528,9 +609,9 @@ void InteractionHandler::orbit(const float &dx, const float &dy, const float &dz
glm::vec3 cameraRight = glm::cross(_camera->viewDirection(), cameraUp);
glm::mat4 transform;
transform = glm::rotate(dx * 10, cameraUp) * transform;
transform = glm::rotate(dy * 10, cameraRight) * transform;
transform = glm::rotate(dz * 10, _camera->viewDirection()) * transform;
transform = glm::rotate(dx * 10.f, cameraUp) * transform;
transform = glm::rotate(dy * 10.f, cameraRight) * transform;
transform = glm::rotate(dz * 10.f, _camera->viewDirection()) * transform;
//get "old" focus position
@@ -794,7 +875,7 @@ void InteractionHandler::lookAt(const glm::quat& rotation)
//
void InteractionHandler::keyboardCallback(int key, int action) {
// TODO package in script
const float speed = 2.75f;
const float speed = _controllerSensitivity;
const float dt = static_cast<float>(_deltaTime);
if (action == SGCT_PRESS || action == SGCT_REPEAT) {
@@ -947,7 +1028,44 @@ scripting::ScriptEngine::LuaLibrary InteractionHandler::luaLibrary() {
&luascriptfunctions::distance,
"number",
"Change distance to origin"
}
},
{
"setInteractionSensitivity",
&luascriptfunctions::setInteractionSensitivity,
"number",
"Sets the global interaction sensitivity"
},
{
"interactionSensitivity",
&luascriptfunctions::interactionSensitivity,
"",
"Gets the current global interaction sensitivity"
},
{
"setInvertRoll",
&luascriptfunctions::setInvertRoll,
"bool",
"Sets the setting if roll movements are inverted"
},
{
"invertRoll",
&luascriptfunctions::invertRoll,
"",
"Returns the status of roll movement inversion"
},
{
"setInvertRotation",
&luascriptfunctions::setInvertRotation,
"bool",
"Sets the setting if rotation movements are inverted"
},
{
"invertRotation",
&luascriptfunctions::invertRotation,
"",
"Returns the status of rotation movement inversion"
}
}
};
}
@@ -962,6 +1080,30 @@ double InteractionHandler::deltaTime() const {
return _deltaTime;
}
void InteractionHandler::setInteractionSensitivity(float sensitivity) {
_controllerSensitivity = sensitivity;
}
float InteractionHandler::interactionSensitivity() const {
return _controllerSensitivity;
}
void InteractionHandler::setInvertRoll(bool invert) {
_invertRoll = invert;
}
bool InteractionHandler::invertRoll() const {
return _invertRoll;
}
void InteractionHandler::setInvertRotation(bool invert) {
_invertRotation = invert;
}
bool InteractionHandler::invertRotation() const {
return _invertRotation;
}
} // namespace interaction
//>>>>>>> feature/interactionhandler
} // namespace openspace
+15 -10
View File
@@ -24,6 +24,8 @@
#include <openspace/interaction/mousecontroller.h>
#include <openspace/engine/openspaceengine.h>
#include <openspace/interaction/interactionhandler.h>
namespace openspace {
@@ -147,13 +149,13 @@ void TrackballMouseController::update(const double& dt){
OrbitalMouseController::OrbitalMouseController()
: MouseController()
, _leftMouseButtonDown(false)
, _rightMouseButtonDown(false)
, _middleMouseButtonDown(false)
, _currentCursorPos(0)
, _rotationSpeed(10.f)
, _navigationSpeed(3.f)
: MouseController()
, _leftMouseButtonDown(false)
, _rightMouseButtonDown(false)
, _middleMouseButtonDown(false)
, _currentCursorPos(0)
, _rotationSpeed(10.f)
, _navigationSpeed(3.f)
{
for (int n = 0; n < 3; ++n){
_previousCursorPos[n] = glm::vec2(0);
@@ -222,12 +224,15 @@ void OrbitalMouseController::scrollWheel(int pos) {
}
void OrbitalMouseController::update(const double& dt){
const float interactionSpeed = OsEng.interactionHandler()->interactionSensitivity();
const bool rotationInvert = OsEng.interactionHandler()->invertRotation();
const bool rollInvert = OsEng.interactionHandler()->invertRoll();
//if (_leftMouseButtonDown || _rightMouseButtonDown || _middleMouseButtonDown){
_handler->orbit(
static_cast<float>(_leftMouseButtonDown) * static_cast<float>(dt) * _currentCursorDiff[MouseButtons::ButtonLeft].x * _rotationSpeed,
static_cast<float>(_leftMouseButtonDown) * static_cast<float>(dt) * _currentCursorDiff[MouseButtons::ButtonLeft].y * _rotationSpeed,
static_cast<float>(_middleMouseButtonDown) * static_cast<float>(dt) * _currentCursorDiff[MouseButtons::ButtonMiddle].x * _rotationSpeed,
static_cast<float>(_leftMouseButtonDown) * static_cast<float>(dt) * _currentCursorDiff[MouseButtons::ButtonLeft].x * interactionSpeed * (rotationInvert ? -1.f : 1.f),
static_cast<float>(_leftMouseButtonDown) * static_cast<float>(dt) * _currentCursorDiff[MouseButtons::ButtonLeft].y * interactionSpeed * (rotationInvert ? -1.f : 1.f),
static_cast<float>(_middleMouseButtonDown) * static_cast<float>(dt) * _currentCursorDiff[MouseButtons::ButtonMiddle].x * interactionSpeed * (rollInvert ? -1.f : 1.f),
static_cast<float>(_rightMouseButtonDown) * static_cast<float>(dt) * _currentCursorDiff[MouseButtons::ButtonRight].y * _navigationSpeed);
//}