mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-04-24 04:58:59 -05:00
Merge branch 'feature/interactionhandler' into develop
Conflicts: include/openspace/engine/openspaceengine.h include/openspace/interaction/interactionhandler.h src/engine/openspaceengine.cpp src/interaction/interactionhandler.cpp src/rendering/renderengine.cpp
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014 *
|
||||
* *
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
|
||||
* software and associated documentation files (the "Software"), to deal in the Software *
|
||||
* without restriction, including without limitation the rights to use, copy, modify, *
|
||||
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
|
||||
* permit persons to whom the Software is furnished to do so, subject to the following *
|
||||
* conditions: *
|
||||
* *
|
||||
* The above copyright notice and this permission notice shall be included in all copies *
|
||||
* or substantial portions of the Software. *
|
||||
* *
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
|
||||
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
|
||||
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
|
||||
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
|
||||
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
|
||||
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
|
||||
****************************************************************************************/
|
||||
|
||||
#ifndef __CONTROLLER_H__
|
||||
#define __CONTROLLER_H__
|
||||
|
||||
#include <openspace/scenegraph/scenegraphnode.h>
|
||||
|
||||
#include <ghoul/glm.h>
|
||||
#include <glm/gtx/vector_angle.hpp>
|
||||
|
||||
namespace openspace {
|
||||
namespace interaction {
|
||||
|
||||
class InteractionHandler;
|
||||
|
||||
class Controller {
|
||||
public:
|
||||
Controller() :
|
||||
_handler(nullptr)
|
||||
{}
|
||||
|
||||
void setHandler(InteractionHandler* handler);
|
||||
|
||||
protected:
|
||||
InteractionHandler* _handler;
|
||||
};
|
||||
|
||||
} // namespace interaction
|
||||
} // namespace openspace
|
||||
|
||||
#endif // __CONTROLLER_H__
|
||||
@@ -22,65 +22,109 @@
|
||||
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
|
||||
****************************************************************************************/
|
||||
|
||||
#ifndef INTERACTIONHANDLER_H
|
||||
#define INTERACTIONHANDLER_H
|
||||
//<<<<<<< HEAD
|
||||
//#ifndef INTERACTIONHANDLER_H
|
||||
//#define INTERACTIONHANDLER_H
|
||||
//
|
||||
//#include <openspace/scripting/scriptengine.h>
|
||||
//#include <openspace/util/powerscaledcoordinate.h>
|
||||
//#include <openspace/util/powerscaledscalar.h>
|
||||
//
|
||||
//// std includes
|
||||
//#include <vector>
|
||||
//#include <mutex>
|
||||
//#include <map>
|
||||
//#include <functional>
|
||||
//
|
||||
//namespace openspace {
|
||||
//
|
||||
//// Forward declare to minimize dependencies
|
||||
//class Camera;
|
||||
//class SceneGraphNode;
|
||||
//class ExternalControl;
|
||||
//
|
||||
//class InteractionHandler {
|
||||
//public:
|
||||
// InteractionHandler(void);
|
||||
// InteractionHandler(const InteractionHandler& src);
|
||||
// InteractionHandler& operator=(const InteractionHandler& rhs);
|
||||
// virtual ~InteractionHandler();
|
||||
//
|
||||
// void enable();
|
||||
// void disable();
|
||||
// const bool isEnabled() const;
|
||||
//
|
||||
// void connectDevices();
|
||||
// void addExternalControl(ExternalControl* controller);
|
||||
//
|
||||
// void setCamera(Camera *camera = nullptr);
|
||||
// void setOrigin(SceneGraphNode* node);
|
||||
//
|
||||
// Camera* getCamera() const;
|
||||
// const psc getOrigin() const;
|
||||
// void lockControls();
|
||||
// void unlockControls();
|
||||
//
|
||||
// void setFocusNode(SceneGraphNode *node);
|
||||
//
|
||||
// void orbit(const glm::quat &rotation);
|
||||
// void rotate(const glm::quat &rotation);
|
||||
// void distance(const PowerScaledScalar &distance, size_t iterations = 0);
|
||||
//=======
|
||||
#ifndef __INTERACTIONHANDLER_H__
|
||||
#define __INTERACTIONHANDLER_H__
|
||||
|
||||
#include <openspace/scripting/scriptengine.h>
|
||||
#include <openspace/util/powerscaledcoordinate.h>
|
||||
#include <openspace/util/powerscaledscalar.h>
|
||||
#include <openspace/interaction/keyboardcontroller.h>
|
||||
#include <openspace/interaction/mousecontroller.h>
|
||||
|
||||
// std includes
|
||||
#include <vector>
|
||||
#include <mutex>
|
||||
#include <map>
|
||||
#include <functional>
|
||||
|
||||
namespace openspace {
|
||||
|
||||
// Forward declare to minimize dependencies
|
||||
class Camera;
|
||||
class SceneGraphNode;
|
||||
class ExternalControl;
|
||||
|
||||
namespace interaction {
|
||||
|
||||
class InteractionHandler {
|
||||
public:
|
||||
InteractionHandler(void);
|
||||
InteractionHandler(const InteractionHandler& src);
|
||||
InteractionHandler& operator=(const InteractionHandler& rhs);
|
||||
virtual ~InteractionHandler();
|
||||
InteractionHandler();
|
||||
|
||||
void enable();
|
||||
void disable();
|
||||
const bool isEnabled() const;
|
||||
~InteractionHandler();
|
||||
|
||||
void connectDevices();
|
||||
void addExternalControl(ExternalControl* controller);
|
||||
void setKeyboardController(KeyboardController* controller);
|
||||
void setMouseController(MouseController* controller);
|
||||
void addController(Controller* controller);
|
||||
|
||||
void setCamera(Camera *camera = nullptr);
|
||||
void setOrigin(SceneGraphNode* node);
|
||||
|
||||
Camera* getCamera() const;
|
||||
const psc getOrigin() const;
|
||||
void lockControls();
|
||||
void unlockControls();
|
||||
|
||||
void setFocusNode(SceneGraphNode *node);
|
||||
|
||||
void orbit(const glm::quat &rotation);
|
||||
void rotate(const glm::quat &rotation);
|
||||
void distance(const PowerScaledScalar &distance, size_t iterations = 0);
|
||||
void update(double deltaTime);
|
||||
|
||||
void lookAt(const glm::quat &rotation);
|
||||
void setRotation(const glm::quat &rotation);
|
||||
|
||||
void update(const double dt);
|
||||
|
||||
double dt();
|
||||
void setFocusNode(SceneGraphNode* node);
|
||||
const SceneGraphNode* const focusNode() const;
|
||||
void setCamera(Camera* camera);
|
||||
const Camera* const camera() const;
|
||||
|
||||
void keyboardCallback(int key, int action);
|
||||
void mouseButtonCallback(int key, int action);
|
||||
void mousePositionCallback(int x, int y);
|
||||
void mouseScrollWheelCallback(int pos);
|
||||
void mouseButtonCallback(int button, int action);
|
||||
void mousePositionCallback(int x, int y);
|
||||
void mouseScrollWheelCallback(int pos);
|
||||
|
||||
//<<<<<<< HEAD
|
||||
//double dt();
|
||||
//=======
|
||||
double deltaTime() const;
|
||||
|
||||
void orbitDelta(const glm::quat& rotation);
|
||||
|
||||
void rotateDelta(const glm::quat& rotation);
|
||||
|
||||
void distanceDelta(const PowerScaledScalar& distance);
|
||||
|
||||
void lookAt(const glm::quat& rotation);
|
||||
|
||||
void setRotation(const glm::quat& rotation);
|
||||
|
||||
void resetKeyBindings();
|
||||
void bindKey(int key, const std::string& lua);
|
||||
@@ -95,30 +139,47 @@ public:
|
||||
static scripting::ScriptEngine::LuaLibrary luaLibrary();
|
||||
|
||||
private:
|
||||
glm::vec3 mapToTrackball(glm::vec2 mousePos);
|
||||
glm::vec3 mapToCamera(glm::vec3 trackballPos);
|
||||
void trackballRotate(int x, int y);
|
||||
friend class Controller;
|
||||
|
||||
//<<<<<<< HEAD
|
||||
// Camera* _camera;
|
||||
// bool _enabled;
|
||||
// SceneGraphNode* _node;
|
||||
//
|
||||
// double _dt;
|
||||
//=======
|
||||
InteractionHandler(const InteractionHandler&) = delete;
|
||||
InteractionHandler& operator=(const InteractionHandler&) = delete;
|
||||
InteractionHandler(InteractionHandler&&) = delete;
|
||||
InteractionHandler& operator=(InteractionHandler&&) = delete;
|
||||
|
||||
Camera* _camera;
|
||||
bool _enabled;
|
||||
SceneGraphNode* _node;
|
||||
|
||||
double _dt;
|
||||
SceneGraphNode* _focusNode;
|
||||
|
||||
glm::vec3 _lastTrackballPos;
|
||||
bool _leftMouseButtonDown, _isMouseBeingPressedAndHeld;
|
||||
double _deltaTime;
|
||||
std::mutex _mutex;
|
||||
|
||||
// used for calling when updating and deallocation
|
||||
std::vector<ExternalControl*> _controllers;
|
||||
|
||||
// for locking and unlocking
|
||||
std::mutex _cameraGuard;
|
||||
//<<<<<<< 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;
|
||||
|
||||
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
|
||||
} // namespace openspace
|
||||
|
||||
#endif
|
||||
#endif // __INTERACTIONHANDLER_H__
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014 *
|
||||
* *
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
|
||||
* software and associated documentation files (the "Software"), to deal in the Software *
|
||||
* without restriction, including without limitation the rights to use, copy, modify, *
|
||||
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
|
||||
* permit persons to whom the Software is furnished to do so, subject to the following *
|
||||
* conditions: *
|
||||
* *
|
||||
* The above copyright notice and this permission notice shall be included in all copies *
|
||||
* or substantial portions of the Software. *
|
||||
* *
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
|
||||
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
|
||||
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
|
||||
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
|
||||
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
|
||||
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
|
||||
****************************************************************************************/
|
||||
|
||||
#ifndef __KEYBOARDCONTROLLER_H__
|
||||
#define __KEYBOARDCONTROLLER_H__
|
||||
|
||||
#include <openspace/interaction/controller.h>
|
||||
|
||||
#include <openspace/interaction/keys.h>
|
||||
|
||||
namespace openspace {
|
||||
namespace interaction {
|
||||
|
||||
class KeyboardController : public Controller {
|
||||
public:
|
||||
virtual void keyPressed(KeyAction action, Key key, KeyModifier modifier) = 0;
|
||||
};
|
||||
|
||||
class KeyboardControllerFixed : public KeyboardController {
|
||||
public:
|
||||
void keyPressed(KeyAction action, Key key, KeyModifier modifier);
|
||||
};
|
||||
|
||||
class KeyboardControllerLua : public KeyboardController {
|
||||
public:
|
||||
void keyPressed(KeyAction action, Key key, KeyModifier modifier);
|
||||
|
||||
protected:
|
||||
std::string keyToString(Key key, KeyModifier mod) const;
|
||||
};
|
||||
|
||||
} // namespace interaction
|
||||
} // namespace openspace
|
||||
|
||||
#endif // __KEYBOARDCONTROLLER_H__
|
||||
@@ -0,0 +1,174 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014 *
|
||||
* *
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
|
||||
* software and associated documentation files (the "Software"), to deal in the Software *
|
||||
* without restriction, including without limitation the rights to use, copy, modify, *
|
||||
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
|
||||
* permit persons to whom the Software is furnished to do so, subject to the following *
|
||||
* conditions: *
|
||||
* *
|
||||
* The above copyright notice and this permission notice shall be included in all copies *
|
||||
* or substantial portions of the Software. *
|
||||
* *
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
|
||||
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
|
||||
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
|
||||
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
|
||||
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
|
||||
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
|
||||
****************************************************************************************/
|
||||
|
||||
#ifndef __KEYS_H__
|
||||
#define __KEYS_H__
|
||||
|
||||
#include <sgct.h>
|
||||
|
||||
namespace openspace {
|
||||
namespace interaction {
|
||||
|
||||
enum class KeyAction {
|
||||
Press = SGCT_PRESS,
|
||||
Release = SGCT_RELEASE,
|
||||
Repeat = SGCT_REPEAT
|
||||
};
|
||||
|
||||
enum class KeyModifier {
|
||||
None = 0,
|
||||
Shift = GLFW_MOD_SHIFT,
|
||||
Control = GLFW_MOD_CONTROL,
|
||||
Alt = GLFW_MOD_ALT,
|
||||
Super = GLFW_MOD_SUPER
|
||||
};
|
||||
|
||||
enum class Key {
|
||||
Unknown = SGCT_KEY_UNKNOWN,
|
||||
Space = SGCT_KEY_SPACE,
|
||||
Apostrophe = SGCT_KEY_APOSTROPHE,
|
||||
Comma = SGCT_KEY_COMMA,
|
||||
Minus = SGCT_KEY_MINUS,
|
||||
Period = SGCT_KEY_PERIOD,
|
||||
Slash = SGCT_KEY_SLASH,
|
||||
Num0 = SGCT_KEY_0,
|
||||
Num1 = SGCT_KEY_1,
|
||||
Num2 = SGCT_KEY_2,
|
||||
Num3 = SGCT_KEY_3,
|
||||
Num4 = SGCT_KEY_4,
|
||||
Num5 = SGCT_KEY_5,
|
||||
Num6 = SGCT_KEY_6,
|
||||
Num7 = SGCT_KEY_7,
|
||||
Num8 = SGCT_KEY_8,
|
||||
Num9 = SGCT_KEY_9,
|
||||
SemiColon = SGCT_KEY_SEMICOLON,
|
||||
Equal = SGCT_KEY_EQUAL,
|
||||
A = SGCT_KEY_A,
|
||||
B = SGCT_KEY_B,
|
||||
C = SGCT_KEY_C,
|
||||
D = SGCT_KEY_D,
|
||||
E = SGCT_KEY_E,
|
||||
F = SGCT_KEY_F,
|
||||
G = SGCT_KEY_G,
|
||||
H = SGCT_KEY_H,
|
||||
I = SGCT_KEY_I,
|
||||
J = SGCT_KEY_J,
|
||||
K = SGCT_KEY_K,
|
||||
L = SGCT_KEY_L,
|
||||
M = SGCT_KEY_M,
|
||||
N = SGCT_KEY_N,
|
||||
O = SGCT_KEY_O,
|
||||
P = SGCT_KEY_P,
|
||||
Q = SGCT_KEY_Q,
|
||||
R = SGCT_KEY_R,
|
||||
S = SGCT_KEY_S,
|
||||
T = SGCT_KEY_T,
|
||||
U = SGCT_KEY_U,
|
||||
V = SGCT_KEY_V,
|
||||
W = SGCT_KEY_W,
|
||||
X = SGCT_KEY_X,
|
||||
Y = SGCT_KEY_Y,
|
||||
Z = SGCT_KEY_Z,
|
||||
LeftBracket = SGCT_KEY_LEFT_BRACKET,
|
||||
BackSlash = SGCT_KEY_BACKSLASH,
|
||||
RightBracket = SGCT_KEY_RIGHT_BRACKET,
|
||||
GraveAccent = SGCT_KEY_GRAVE_ACCENT,
|
||||
World1 = SGCT_KEY_WORLD_1,
|
||||
World2 = SGCT_KEY_WORLD_2,
|
||||
Escape = SGCT_KEY_ESC,
|
||||
Enter = SGCT_KEY_ENTER,
|
||||
Tab = SGCT_KEY_TAB,
|
||||
BackSpace = SGCT_KEY_BACKSPACE,
|
||||
Insert = SGCT_KEY_INSERT,
|
||||
Delete = SGCT_KEY_DELETE,
|
||||
Right = SGCT_KEY_RIGHT,
|
||||
Left = SGCT_KEY_LEFT,
|
||||
Down = SGCT_KEY_DOWN,
|
||||
Up = SGCT_KEY_UP,
|
||||
PageUp = SGCT_KEY_PAGE_UP,
|
||||
PageDown = SGCT_KEY_PAGE_DOWN,
|
||||
Home = SGCT_KEY_HOME,
|
||||
End = SGCT_KEY_END,
|
||||
CapsLock = SGCT_KEY_CAPS_LOCK,
|
||||
ScrollLock = SGCT_KEY_SCROLL_LOCK,
|
||||
NumLock = SGCT_KEY_NUM_LOCK,
|
||||
PrintScreen = SGCT_KEY_PRINT_SCREEN,
|
||||
Pause = SGCT_KEY_PAUSE,
|
||||
F1 = SGCT_KEY_F1,
|
||||
F2 = SGCT_KEY_F2,
|
||||
F3 = SGCT_KEY_F3,
|
||||
F4 = SGCT_KEY_F4,
|
||||
F5 = SGCT_KEY_F5,
|
||||
F6 = SGCT_KEY_F6,
|
||||
F7 = SGCT_KEY_F7,
|
||||
F8 = SGCT_KEY_F8,
|
||||
F9 = SGCT_KEY_F9,
|
||||
F10 = SGCT_KEY_F10,
|
||||
F11 = SGCT_KEY_F11,
|
||||
F12 = SGCT_KEY_F12,
|
||||
F13 = SGCT_KEY_F13,
|
||||
F14 = SGCT_KEY_F14,
|
||||
F15 = SGCT_KEY_F15,
|
||||
F16 = SGCT_KEY_F16,
|
||||
F17 = SGCT_KEY_F17,
|
||||
F18 = SGCT_KEY_F18,
|
||||
F19 = SGCT_KEY_F19,
|
||||
F20 = SGCT_KEY_F20,
|
||||
F21 = SGCT_KEY_F21,
|
||||
F22 = SGCT_KEY_F22,
|
||||
F23 = SGCT_KEY_F23,
|
||||
F24 = SGCT_KEY_F24,
|
||||
F25 = SGCT_KEY_F25,
|
||||
Keypad0 = SGCT_KEY_KP_0,
|
||||
Keypad1 = SGCT_KEY_KP_1,
|
||||
Keypad2 = SGCT_KEY_KP_2,
|
||||
Keypad3 = SGCT_KEY_KP_3,
|
||||
Keypad4 = SGCT_KEY_KP_4,
|
||||
Keypad5 = SGCT_KEY_KP_5,
|
||||
Keypad6 = SGCT_KEY_KP_6,
|
||||
Keypad7 = SGCT_KEY_KP_7,
|
||||
Keypad8 = SGCT_KEY_KP_8,
|
||||
Keypad9 = SGCT_KEY_KP_9,
|
||||
KeypadDecimal = SGCT_KEY_KP_DECIMAL,
|
||||
KeypadDivide = SGCT_KEY_KP_DIVIDE,
|
||||
KeypadMultiply = SGCT_KEY_KP_MULTIPLY,
|
||||
KeypadSubtract = SGCT_KEY_KP_SUBTRACT,
|
||||
KeypadAdd = SGCT_KEY_KP_ADD,
|
||||
KeypadEnter = SGCT_KEY_KP_ENTER,
|
||||
LeftShift = SGCT_KEY_LEFT_SHIFT,
|
||||
LeftControl = SGCT_KEY_LEFT_CONTROL,
|
||||
LeftAlt = SGCT_KEY_LEFT_ALT,
|
||||
LeftSuper = SGCT_KEY_LEFT_SUPER,
|
||||
RightShift = SGCT_KEY_RIGHT_SHIFT,
|
||||
RightControl = SGCT_KEY_RIGHT_CONTROL,
|
||||
RightAlt = SGCT_KEY_RIGHT_ALT,
|
||||
RightSuper = SGCT_KEY_RIGHT_SUPER,
|
||||
Menu = SGCT_KEY_MENU,
|
||||
Last = SGCT_KEY_LAST
|
||||
};
|
||||
|
||||
} // namespace interaction
|
||||
} // namespace openspace
|
||||
|
||||
#endif // __KEYS_H__
|
||||
@@ -0,0 +1,57 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014 *
|
||||
* *
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
|
||||
* software and associated documentation files (the "Software"), to deal in the Software *
|
||||
* without restriction, including without limitation the rights to use, copy, modify, *
|
||||
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
|
||||
* permit persons to whom the Software is furnished to do so, subject to the following *
|
||||
* conditions: *
|
||||
* *
|
||||
* The above copyright notice and this permission notice shall be included in all copies *
|
||||
* or substantial portions of the Software. *
|
||||
* *
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
|
||||
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
|
||||
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
|
||||
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
|
||||
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
|
||||
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
|
||||
****************************************************************************************/
|
||||
|
||||
#ifndef __MOUSE_H__
|
||||
#define __MOUSE_H__
|
||||
|
||||
#include <sgct.h>
|
||||
|
||||
namespace openspace {
|
||||
namespace interaction {
|
||||
|
||||
enum class MouseAction {
|
||||
Press = SGCT_PRESS,
|
||||
Release = SGCT_RELEASE,
|
||||
Repeat = SGCT_REPEAT
|
||||
};
|
||||
|
||||
enum class MouseButton {
|
||||
Left = SGCT_MOUSE_BUTTON_LEFT,
|
||||
Right = SGCT_MOUSE_BUTTON_RIGHT,
|
||||
Middle = SGCT_MOUSE_BUTTON_MIDDLE,
|
||||
Button1 = SGCT_MOUSE_BUTTON_1,
|
||||
Button2 = SGCT_MOUSE_BUTTON_2,
|
||||
Button3 = SGCT_MOUSE_BUTTON_3,
|
||||
Button4 = SGCT_MOUSE_BUTTON_4,
|
||||
Button5 = SGCT_MOUSE_BUTTON_5,
|
||||
Button6 = SGCT_MOUSE_BUTTON_6,
|
||||
Button7 = SGCT_MOUSE_BUTTON_7,
|
||||
Button8 = SGCT_MOUSE_BUTTON_8,
|
||||
ButtonLast = SGCT_MOUSE_BUTTON_LAST,
|
||||
};
|
||||
|
||||
} // namespace interaction
|
||||
} // namespace openspace
|
||||
|
||||
#endif // __MOUSE_H__
|
||||
@@ -0,0 +1,73 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014 *
|
||||
* *
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
|
||||
* software and associated documentation files (the "Software"), to deal in the Software *
|
||||
* without restriction, including without limitation the rights to use, copy, modify, *
|
||||
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
|
||||
* permit persons to whom the Software is furnished to do so, subject to the following *
|
||||
* conditions: *
|
||||
* *
|
||||
* The above copyright notice and this permission notice shall be included in all copies *
|
||||
* or substantial portions of the Software. *
|
||||
* *
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
|
||||
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
|
||||
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
|
||||
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
|
||||
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
|
||||
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
|
||||
****************************************************************************************/
|
||||
|
||||
#ifndef __MOUSECONTROLLER_H__
|
||||
#define __MOUSECONTROLLER_H__
|
||||
|
||||
#include <openspace/interaction/controller.h>
|
||||
|
||||
#include <openspace/interaction/mouse.h>
|
||||
|
||||
#include <ghoul/glm.h>
|
||||
|
||||
namespace openspace {
|
||||
namespace interaction {
|
||||
|
||||
class MouseController : public Controller {
|
||||
public:
|
||||
MouseController();
|
||||
|
||||
virtual void button(MouseAction action, MouseButton button) = 0;
|
||||
virtual void move(float x, float y) = 0;
|
||||
virtual void scrollWheel(int pos) = 0;
|
||||
|
||||
protected:
|
||||
glm::vec3 _lastTrackballPos;
|
||||
bool _isMouseBeingPressedAndHeld;
|
||||
|
||||
glm::vec3 mapToTrackball(glm::vec2 mousePos);
|
||||
|
||||
glm::vec3 mapToCamera(glm::vec3 trackballPos);
|
||||
|
||||
void trackballRotate(int x, int y);
|
||||
};
|
||||
|
||||
class TrackballMouseController : public MouseController {
|
||||
public:
|
||||
TrackballMouseController();
|
||||
|
||||
void button(MouseAction action, MouseButton button);
|
||||
|
||||
void move(float x, float y);
|
||||
|
||||
void scrollWheel(int pos);
|
||||
|
||||
protected:
|
||||
bool _leftMouseButtonDown;
|
||||
};
|
||||
|
||||
} // namespace interaction
|
||||
} // namespace openspace
|
||||
|
||||
#endif // __MOUSECONTROLLER_H__
|
||||
Reference in New Issue
Block a user