mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-01-05 19:19:39 -06:00
Improve interaction.
This commit is contained in:
@@ -30,6 +30,7 @@
|
||||
#include <openspace/network/parallelconnection.h>
|
||||
#include <openspace/properties/propertyowner.h>
|
||||
#include <openspace/properties/stringproperty.h>
|
||||
#include <openspace/util/mouse.h>
|
||||
#include <openspace/util/keys.h>
|
||||
|
||||
#include <mutex>
|
||||
@@ -155,19 +156,29 @@ public:
|
||||
void mousePositionCallback(double mouseX, double mouseY);
|
||||
void mouseScrollWheelCallback(double mouseScrollDelta);
|
||||
|
||||
// Mutators
|
||||
void addKeyframe(const network::datamessagestructures::PositionKeyframe &kf);
|
||||
void clearKeyframes();
|
||||
|
||||
// Accessors
|
||||
const std::list<std::pair<Key, KeyModifier> >& getPressedKeys();
|
||||
const std::list<MouseButton>& getPressedMouseButtons();
|
||||
glm::dvec2 getMousePosition();
|
||||
double getMouseScrollDelta();
|
||||
std::vector<network::datamessagestructures::PositionKeyframe>& getKeyFrames();
|
||||
|
||||
bool isKeyPressed(std::pair<Key, KeyModifier> keyModPair);
|
||||
bool isMouseButtonPressed(MouseButton mouseButton);
|
||||
private:
|
||||
// Input from keyboard and mouse
|
||||
std::list<std::pair<Key, KeyModifier> > _keysDown;
|
||||
std::list<MouseButton> _mouseButtonsDown;
|
||||
glm::dvec2 _mousePosition;
|
||||
double _mouseScrollDelta;
|
||||
|
||||
// Remote input via keyframes
|
||||
std::vector<network::datamessagestructures::PositionKeyframe> _keyframes;
|
||||
std::mutex _keyframeMutex;
|
||||
};
|
||||
|
||||
class InteractionMode
|
||||
@@ -223,6 +234,17 @@ protected:
|
||||
Camera* _camera;
|
||||
};
|
||||
|
||||
class KeyframeInteractionMode : public InteractionMode
|
||||
{
|
||||
public:
|
||||
KeyframeInteractionMode(std::shared_ptr<InputState> inputState);
|
||||
~KeyframeInteractionMode();
|
||||
|
||||
virtual void update(double deltaTime);
|
||||
private:
|
||||
double _currentKeyframeTime;
|
||||
};
|
||||
|
||||
class OrbitalInteractionMode : public InteractionMode
|
||||
{
|
||||
public:
|
||||
@@ -256,8 +278,6 @@ public:
|
||||
~InteractionHandler();
|
||||
|
||||
// Mutators
|
||||
void setKeyboardController(KeyboardController* controller);
|
||||
void setMouseController(MouseController* controller);
|
||||
void setFocusNode(SceneGraphNode* node);
|
||||
void setCamera(Camera* camera);
|
||||
|
||||
|
||||
@@ -22,6 +22,10 @@
|
||||
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
|
||||
****************************************************************************************/
|
||||
|
||||
|
||||
//#define USE_OLD_INTERACTIONHANDLER
|
||||
#ifdef USE_OLD_INTERACTIONHANDLER
|
||||
|
||||
#ifndef __MOUSECONTROLLER_H__
|
||||
#define __MOUSECONTROLLER_H__
|
||||
|
||||
@@ -101,4 +105,7 @@ private:
|
||||
} // namespace interaction
|
||||
} // namespace openspace
|
||||
|
||||
#endif // __MOUSECONTROLLER_H__
|
||||
#endif // __MOUSECONTROLLER_H__
|
||||
|
||||
|
||||
#endif // USE_OLD_INTERACTIONHANDLER
|
||||
|
||||
@@ -603,6 +603,24 @@ InputState::~InputState() {
|
||||
|
||||
}
|
||||
|
||||
void InputState::addKeyframe(const network::datamessagestructures::PositionKeyframe &kf) {
|
||||
_keyframeMutex.lock();
|
||||
|
||||
//save a maximum of 10 samples (1 seconds of buffer)
|
||||
if (_keyframes.size() >= 10) {
|
||||
_keyframes.erase(_keyframes.begin());
|
||||
}
|
||||
_keyframes.push_back(kf);
|
||||
|
||||
_keyframeMutex.unlock();
|
||||
}
|
||||
|
||||
void InputState::clearKeyframes() {
|
||||
_keyframeMutex.lock();
|
||||
_keyframes.clear();
|
||||
_keyframeMutex.unlock();
|
||||
}
|
||||
|
||||
void InputState::keyboardCallback(Key key, KeyModifier modifier, KeyAction action) {
|
||||
if (action == KeyAction::Press) {
|
||||
_keysDown.push_back(std::pair<Key, KeyModifier>(key, modifier));
|
||||
@@ -695,6 +713,20 @@ Camera* InteractionMode::camera() {
|
||||
return _camera;
|
||||
}
|
||||
|
||||
// KeyframeInteractionMode
|
||||
KeyframeInteractionMode::KeyframeInteractionMode(std::shared_ptr<InputState> inputState)
|
||||
: InteractionMode(inputState) {
|
||||
|
||||
}
|
||||
|
||||
KeyframeInteractionMode::~KeyframeInteractionMode() {
|
||||
|
||||
}
|
||||
|
||||
void KeyframeInteractionMode::update(double deltaTime) {
|
||||
// TODO : Get keyframes from input state and use them to position and rotate the camera
|
||||
}
|
||||
|
||||
// OrbitalInteractionMode
|
||||
OrbitalInteractionMode::OrbitalInteractionMode(
|
||||
std::shared_ptr<InputState> inputState,
|
||||
@@ -728,19 +760,25 @@ void OrbitalInteractionMode::updateMouseStatesFromInput(double deltaTime) {
|
||||
glm::dvec2 mousePositionDelta =
|
||||
_localRotationMouseState.previousPosition - mousePosition;
|
||||
_localRotationMouseState.velocity.set(mousePositionDelta * deltaTime * _sensitivity);
|
||||
|
||||
_globalRotationMouseState.previousPosition = mousePosition;
|
||||
_globalRotationMouseState.velocity.set(glm::dvec2(0, 0));
|
||||
}
|
||||
else {
|
||||
glm::dvec2 mousePositionDelta =
|
||||
_globalRotationMouseState.previousPosition - mousePosition;
|
||||
_globalRotationMouseState.velocity.set(mousePositionDelta * deltaTime * _sensitivity);
|
||||
|
||||
_localRotationMouseState.previousPosition = mousePosition;
|
||||
_localRotationMouseState.velocity.set(glm::dvec2(0, 0));
|
||||
}
|
||||
}
|
||||
else { //!button1Pressed
|
||||
_globalRotationMouseState.previousPosition = mousePosition;
|
||||
else { // !button1Pressed
|
||||
_localRotationMouseState.previousPosition = mousePosition;
|
||||
|
||||
_globalRotationMouseState.velocity.set(glm::dvec2(0, 0));
|
||||
_localRotationMouseState.velocity.set(glm::dvec2(0, 0));
|
||||
|
||||
_globalRotationMouseState.previousPosition = mousePosition;
|
||||
_globalRotationMouseState.velocity.set(glm::dvec2(0, 0));
|
||||
}
|
||||
if (button2Pressed) {
|
||||
glm::dvec2 mousePositionDelta =
|
||||
@@ -857,14 +895,6 @@ InteractionHandler::~InteractionHandler() {
|
||||
|
||||
}
|
||||
|
||||
void InteractionHandler::setKeyboardController(KeyboardController* controller) {
|
||||
//_interactor->setKeyboardController(controller);
|
||||
}
|
||||
|
||||
void InteractionHandler::setMouseController(MouseController* controller) {
|
||||
//_interactor->setMouseController(controller);
|
||||
}
|
||||
|
||||
void InteractionHandler::setFocusNode(SceneGraphNode* node) {
|
||||
_interactor->setFocusNode(node);
|
||||
}
|
||||
@@ -1000,11 +1030,11 @@ scripting::ScriptEngine::LuaLibrary InteractionHandler::luaLibrary() {
|
||||
}
|
||||
|
||||
void InteractionHandler::addKeyframe(const network::datamessagestructures::PositionKeyframe &kf) {
|
||||
|
||||
_inputState->addKeyframe(kf);
|
||||
}
|
||||
|
||||
void InteractionHandler::clearKeyframes() {
|
||||
|
||||
_inputState->clearKeyframes();
|
||||
}
|
||||
|
||||
#endif // USE_OLD_INTERACTIONHANDLER
|
||||
|
||||
@@ -22,6 +22,11 @@
|
||||
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
|
||||
****************************************************************************************/
|
||||
|
||||
|
||||
|
||||
//#define USE_OLD_INTERACTIONHANDLER
|
||||
#ifdef USE_OLD_INTERACTIONHANDLER
|
||||
|
||||
#include <openspace/interaction/mousecontroller.h>
|
||||
|
||||
#include <openspace/engine/openspaceengine.h>
|
||||
@@ -248,3 +253,5 @@ void OrbitalMouseController::update(const double& dt){
|
||||
|
||||
} // namespace interaction
|
||||
} // namespace openspace
|
||||
|
||||
#endif // USE_OLD_INTERACTIONHANDLER
|
||||
|
||||
Reference in New Issue
Block a user