diff --git a/data/scene/osirisrex.scene b/data/scene/osirisrex.scene index 4de5d71080..4b9821a2e4 100644 --- a/data/scene/osirisrex.scene +++ b/data/scene/osirisrex.scene @@ -27,9 +27,9 @@ function preInitialization() openspace.spice.loadKernel("${SPICE}/OsirisRexKernels/background/ik/orx_otes_v00.ti") openspace.spice.loadKernel("${SPICE}/OsirisRexKernels/background/ik/orx_rexis_v00.ti") openspace.spice.loadKernel("${SPICE}/OsirisRexKernels/background/ik/orx_struct_v00.ti") - openspace.spice.loadKernel("${SPICE}/OsirisRexKernels/background/ik/orx_navcam_v00.ti ") + openspace.spice.loadKernel("${SPICE}/OsirisRexKernels/background/ik/orx_navcam_v00.ti") openspace.spice.loadKernel("${SPICE}/OsirisRexKernels/background/ik/orx_ola_v00.ti") - openspace.spice.loadKernel("${SPICE}/OsirisRexKernels/background/ik/orx_ovirs_v00.ti ") + openspace.spice.loadKernel("${SPICE}/OsirisRexKernels/background/ik/orx_ovirs_v00.ti") openspace.spice.loadKernel("${SPICE}/OsirisRexKernels/background/ik/orx_stowcam_v00.ti") openspace.spice.loadKernel("${SPICE}/OsirisRexKernels/background/lsk/naif0011.tls") openspace.spice.loadKernel("${SPICE}/OsirisRexKernels/background/pck/bennu_SPH250m.tpc") diff --git a/include/openspace/interaction/interactionhandler.h b/include/openspace/interaction/interactionhandler.h index d8fe42faa2..a87a13b899 100644 --- a/include/openspace/interaction/interactionhandler.h +++ b/include/openspace/interaction/interactionhandler.h @@ -173,7 +173,13 @@ public: void lockControls(); void unlockControls(); - void update(double deltaTime); + //void update(double deltaTime); + + void preSynchronization(double deltaTime); + void postSynchronizationPreDraw(); + + void serialize(SyncBuffer* syncBuffer); + void deserialize(SyncBuffer* syncBuffer); // Accessors ghoul::Dictionary getCameraStateDictionary(); @@ -214,8 +220,6 @@ private: std::map> _interactionModes; std::shared_ptr _mouseStates; - //std::shared_ptr _orbitalInteractionMode; - //std::shared_ptr _globebrowsingInteractionMode; // Properties properties::StringProperty _origin; diff --git a/include/openspace/interaction/interactionmode.h b/include/openspace/interaction/interactionmode.h index a978d529a7..15d70014db 100644 --- a/include/openspace/interaction/interactionmode.h +++ b/include/openspace/interaction/interactionmode.h @@ -95,7 +95,12 @@ public: // Accessors SceneGraphNode* focusNode(); - virtual void update(Camera& camera, const InputState& inputState, double deltaTime) = 0; + virtual void updateMouseStatesFromInput(const InputState& inputState, double deltaTime) = 0; + virtual void updateCameraStateFromMouseStates(Camera& camera) = 0; + + virtual void serialize(SyncBuffer* syncBuffer) = 0; + virtual void deserialize(SyncBuffer* syncBuffer) = 0; + protected: /** Inner class that acts as a smoothing filter to a variable. The filter has a step @@ -163,8 +168,13 @@ public: KeyframeInteractionMode(); ~KeyframeInteractionMode(); - virtual void update(double deltaTime); + virtual void updateMouseStatesFromInput(const InputState& inputState, double deltaTime); + virtual void updateCameraStateFromMouseStates(Camera& camera); + // Need implementation + + virtual void serialize(SyncBuffer* syncBuffer) {}; + virtual void deserialize(SyncBuffer* syncBuffer) {}; private: double _currentKeyframeTime; }; @@ -178,7 +188,6 @@ public: { public: /*! - \param inputState \param sensitivity \param velocityScalefactor can be set to 60 to remove the inertia of the interaction. Lower value will make it harder to move the camera. @@ -190,9 +199,19 @@ public: void setVerticalFriction(double friction); void setSensitivity(double sensitivity); void setVelocityScaleFactor(double scaleFactor); + + glm::dvec2 synchedGlobalRotationMouseVelocity(); + glm::dvec2 synchedLocalRotationMouseVelocity(); + glm::dvec2 synchedTruckMovementMouseVelocity(); + glm::dvec2 synchedLocalRollMouseVelocity(); + glm::dvec2 synchedGlobalRollMouseVelocity(); + + void preSynchronization(); + void postSynchronizationPreDraw(); + + void serialize(SyncBuffer* syncBuffer); + void deserialize(SyncBuffer* syncBuffer); private: - friend class OrbitalInteractionMode; - friend class GlobeBrowsingInteractionMode; double _sensitivity; MouseState _globalRotationMouseState; @@ -200,15 +219,34 @@ public: MouseState _truckMovementMouseState; MouseState _localRollMouseState; MouseState _globalRollMouseState; + + // MouseStates have synched variables + glm::dvec2 _sharedGlobalRotationMouseVelocity; + glm::dvec2 _sharedLocalRotationMouseVelocity; + glm::dvec2 _sharedTruckMovementMouseVelocity; + glm::dvec2 _sharedLocalRollMouseVelocity; + glm::dvec2 _sharedGlobalRollMouseVelocity; + + glm::dvec2 _synchedGlobalRotationMouseVelocity; + glm::dvec2 _synchedLocalRotationMouseVelocity; + glm::dvec2 _synchedTruckMovementMouseVelocity; + glm::dvec2 _synchedLocalRollMouseVelocity; + glm::dvec2 _synchedGlobalRollMouseVelocity; }; OrbitalInteractionMode(std::shared_ptr mouseStates); ~OrbitalInteractionMode(); - virtual void update(Camera& camera, const InputState& inputState, double deltaTime); + //virtual void update(Camera& camera, const InputState& inputState, double deltaTime); + + virtual void updateMouseStatesFromInput(const InputState& inputState, double deltaTime); + virtual void updateCameraStateFromMouseStates(Camera& camera); + + virtual void serialize(SyncBuffer* syncBuffer); + virtual void deserialize(SyncBuffer* syncBuffer); protected: - void updateCameraStateFromMouseStates(Camera& camera); + //void updateCameraStateFromMouseStates(Camera& camera); std::shared_ptr _mouseStates; }; @@ -219,9 +257,11 @@ public: ~GlobeBrowsingInteractionMode(); virtual void setFocusNode(SceneGraphNode* focusNode); - virtual void update(Camera& camera, const InputState& inputState, double deltaTime); + //virtual void update(Camera& camera, const InputState& inputState, double deltaTime); + virtual void updateCameraStateFromMouseStates(Camera& camera); + private: - void updateCameraStateFromMouseStates(Camera& camera); + //void updateCameraStateFromMouseStates(Camera& camera); RenderableGlobe* _globe; }; diff --git a/openspace.cfg b/openspace.cfg index 4cde909b3a..137b02be9e 100644 --- a/openspace.cfg +++ b/openspace.cfg @@ -1,9 +1,9 @@ return { -- Determines which SGCT configuration file is loaded, that is, if there rendering -- occurs in a single window, a fisheye projection, or a dome cluster system - SGCTConfig = "${SGCT}/single.xml", + --SGCTConfig = "${SGCT}/single.xml", --SGCTConfig = "${SGCT}/single_fisheye.xml", - --SGCTConfig = "${SGCT}/two_nodes.xml", + SGCTConfig = "${SGCT}/two_nodes.xml", -- Sets the scene that is to be loaded by OpenSpace. A scene file is a description -- of all entities that will be visible during an instance of OpenSpace diff --git a/src/engine/openspaceengine.cpp b/src/engine/openspaceengine.cpp index 0e821e6f06..4559501554 100644 --- a/src/engine/openspaceengine.cpp +++ b/src/engine/openspaceengine.cpp @@ -737,18 +737,24 @@ void OpenSpaceEngine::preSynchronization() { FileSys.triggerFilesystemEvents(); if (_isMaster) { double dt = _windowWrapper->averageDeltaTime(); - _interactionHandler->update(dt); + //_interactionHandler->update(dt); + _interactionHandler->preSynchronization(dt); + _interactionHandler->postSynchronizationPreDraw(); Time::ref().advanceTime(dt); Time::ref().preSynchronization(); - + _scriptEngine->preSynchronization(); + _renderEngine->preSynchronization(); + _renderEngine->camera()->preSynchronization(); + _parallelConnection->preSynchronization(); } } void OpenSpaceEngine::postSynchronizationPreDraw() { + if (_isInShutdownMode) { if (_shutdownCountdown <= 0.f) { _windowWrapper->terminate(); @@ -759,8 +765,12 @@ void OpenSpaceEngine::postSynchronizationPreDraw() { Time::ref().postSynchronizationPreDraw(); _scriptEngine->postSynchronizationPreDraw(); + _renderEngine->postSynchronizationPreDraw(); - + _renderEngine->camera()->postSynchronizationPreDraw(); + + //_renderEngine->camera()->preSynchronization(); + //_renderEngine->camera()->postSynchronizationPreDraw(); #ifdef OPENSPACE_MODULE_ONSCREENGUI_ENABLED if (_isMaster && _gui->isEnabled() && _windowWrapper->isRegularRendering()) { @@ -801,6 +811,7 @@ void OpenSpaceEngine::postSynchronizationPreDraw() { LWARNINGC("Logging", "Number of Fatals raised: " << fatalCounter); LogMgr.resetMessageCounters(); + } void OpenSpaceEngine::render(const glm::mat4& projectionMatrix, const glm::mat4& viewMatrix) { @@ -900,6 +911,7 @@ void OpenSpaceEngine::encode() { Time::ref().serialize(_syncBuffer.get()); _scriptEngine->serialize(_syncBuffer.get()); _renderEngine->serialize(_syncBuffer.get()); + _interactionHandler->serialize(_syncBuffer.get()); _syncBuffer->write(); } @@ -914,6 +926,8 @@ void OpenSpaceEngine::decode() { Time::ref().deserialize(_syncBuffer.get()); _scriptEngine->deserialize(_syncBuffer.get()); _renderEngine->deserialize(_syncBuffer.get()); + _interactionHandler->deserialize(_syncBuffer.get()); + } } diff --git a/src/interaction/interactionhandler.cpp b/src/interaction/interactionhandler.cpp index 91e765b103..6f6149222e 100644 --- a/src/interaction/interactionhandler.cpp +++ b/src/interaction/interactionhandler.cpp @@ -769,7 +769,7 @@ void InteractionHandler::unlockControls() { } -void InteractionHandler::update(double deltaTime) { +void InteractionHandler::preSynchronization(double deltaTime) { ghoul_assert(_inputState != nullptr, "InputState cannot be null!"); ghoul_assert(_camera != nullptr, "Camera cannot be null!"); @@ -777,10 +777,23 @@ void InteractionHandler::update(double deltaTime) { _cameraUpdatedFromScript = false; } else { - _currentInteractionMode->update(*_camera, *_inputState, deltaTime); + _currentInteractionMode->updateMouseStatesFromInput(*_inputState, deltaTime); } } +void InteractionHandler::postSynchronizationPreDraw() { + ghoul_assert(_inputState != nullptr, "InputState cannot be null!"); + ghoul_assert(_camera != nullptr, "Camera cannot be null!"); + + if (_cameraUpdatedFromScript) { + _cameraUpdatedFromScript = false; + } + else { + _currentInteractionMode->updateCameraStateFromMouseStates(*_camera); + } +} + + SceneGraphNode* const InteractionHandler::focusNode() const { return _currentInteractionMode->focusNode(); } @@ -999,6 +1012,20 @@ void InteractionHandler::clearKeyframes() { _inputState->clearKeyframes(); } +void InteractionHandler::serialize(SyncBuffer* syncBuffer) { + for each (auto var in _interactionModes) + { + var.second->serialize(syncBuffer); + } +} + +void InteractionHandler::deserialize(SyncBuffer* syncBuffer) { + for each (auto var in _interactionModes) + { + var.second->deserialize(syncBuffer); + } +} + #endif // USE_OLD_INTERACTIONHANDLER } // namespace interaction diff --git a/src/interaction/interactionmode.cpp b/src/interaction/interactionmode.cpp index 257cc243f2..4a76d3ba26 100644 --- a/src/interaction/interactionmode.cpp +++ b/src/interaction/interactionmode.cpp @@ -167,8 +167,12 @@ KeyframeInteractionMode::~KeyframeInteractionMode() { } -void KeyframeInteractionMode::update(double deltaTime) { - // TODO : Get keyframes from input state and use them to position and rotate the camera +void KeyframeInteractionMode::updateMouseStatesFromInput(const InputState& inputState, double deltaTime) { + +} + +void KeyframeInteractionMode::updateCameraStateFromMouseStates(Camera& camera) { + } // OrbitalInteractionMode @@ -279,6 +283,58 @@ void OrbitalInteractionMode::MouseStates::setVelocityScaleFactor(double scaleFac _globalRollMouseState.setVelocityScaleFactor(scaleFactor); } +glm::dvec2 OrbitalInteractionMode::MouseStates::synchedGlobalRotationMouseVelocity() { + return _synchedGlobalRotationMouseVelocity; +} + +glm::dvec2 OrbitalInteractionMode::MouseStates::synchedLocalRotationMouseVelocity() { + return _synchedLocalRotationMouseVelocity; +} + +glm::dvec2 OrbitalInteractionMode::MouseStates::synchedTruckMovementMouseVelocity() { + return _synchedTruckMovementMouseVelocity; +} + +glm::dvec2 OrbitalInteractionMode::MouseStates::synchedLocalRollMouseVelocity() { + return _synchedLocalRollMouseVelocity; +} + +glm::dvec2 OrbitalInteractionMode::MouseStates::synchedGlobalRollMouseVelocity() { + return _synchedGlobalRollMouseVelocity; +} + +void OrbitalInteractionMode::MouseStates::preSynchronization() { + _sharedGlobalRotationMouseVelocity = _globalRotationMouseState.velocity.get(); + _sharedLocalRotationMouseVelocity = _localRotationMouseState.velocity.get(); + _sharedTruckMovementMouseVelocity = _truckMovementMouseState.velocity.get(); + _sharedLocalRollMouseVelocity = _localRollMouseState.velocity.get(); + _sharedGlobalRollMouseVelocity = _globalRollMouseState.velocity.get(); +} + +void OrbitalInteractionMode::MouseStates::postSynchronizationPreDraw() { + _synchedGlobalRotationMouseVelocity = _sharedGlobalRotationMouseVelocity; + _synchedLocalRotationMouseVelocity = _sharedLocalRotationMouseVelocity; + _synchedTruckMovementMouseVelocity = _sharedTruckMovementMouseVelocity; + _synchedLocalRollMouseVelocity = _sharedLocalRollMouseVelocity; + _synchedGlobalRollMouseVelocity = _sharedGlobalRollMouseVelocity; +} + +void OrbitalInteractionMode::MouseStates::serialize(SyncBuffer* syncBuffer) { + syncBuffer->encode(_sharedGlobalRotationMouseVelocity); + syncBuffer->encode(_sharedLocalRotationMouseVelocity); + syncBuffer->encode(_sharedTruckMovementMouseVelocity); + syncBuffer->encode(_sharedLocalRollMouseVelocity); + syncBuffer->encode(_sharedGlobalRollMouseVelocity); +} + +void OrbitalInteractionMode::MouseStates::deserialize(SyncBuffer* syncBuffer) { + syncBuffer->decode(_sharedGlobalRotationMouseVelocity); + syncBuffer->decode(_sharedLocalRotationMouseVelocity); + syncBuffer->decode(_sharedTruckMovementMouseVelocity); + syncBuffer->decode(_sharedLocalRollMouseVelocity); + syncBuffer->decode(_sharedGlobalRollMouseVelocity); +} + OrbitalInteractionMode::OrbitalInteractionMode(std::shared_ptr mouseStates) : InteractionMode() , _mouseStates(mouseStates){ @@ -290,6 +346,9 @@ OrbitalInteractionMode::~OrbitalInteractionMode() { } void OrbitalInteractionMode::updateCameraStateFromMouseStates(Camera& camera) { + // Update synched data + _mouseStates->postSynchronizationPreDraw(); + using namespace glm; if (_focusNode) { // Read the current state of the camera and focus node @@ -322,17 +381,17 @@ void OrbitalInteractionMode::updateCameraStateFromMouseStates(Camera& camera) { { // Do local roll glm::dquat cameraRollRotation = - glm::angleAxis(_mouseStates->_localRollMouseState.velocity.get().x, dvec3(0, 0, 1)); + glm::angleAxis(_mouseStates->synchedLocalRollMouseVelocity().x, dvec3(0, 0, 1)); localCameraRotation = localCameraRotation * cameraRollRotation; } { // Do local rotation - dvec3 eulerAngles(_mouseStates->_localRotationMouseState.velocity.get().y, _mouseStates->_localRotationMouseState.velocity.get().x, 0); + dvec3 eulerAngles(_mouseStates->synchedLocalRotationMouseVelocity().y, _mouseStates->synchedLocalRotationMouseVelocity().x, 0); dquat rotationDiff = dquat(eulerAngles); localCameraRotation = localCameraRotation * rotationDiff; } { // Do global rotation - dvec2 smoothMouseVelocity = _mouseStates->_globalRotationMouseState.velocity.get(); + dvec2 smoothMouseVelocity = _mouseStates->synchedGlobalRotationMouseVelocity(); dvec3 eulerAngles(-smoothMouseVelocity.y, -smoothMouseVelocity.x, 0); dquat rotationDiffCamSpace = dquat(eulerAngles); @@ -357,11 +416,11 @@ void OrbitalInteractionMode::updateCameraStateFromMouseStates(Camera& camera) { -directionToCenter * boundingSphere; camPos += -(centerToCamera - centerToBoundingSphere) * - _mouseStates->_truckMovementMouseState.velocity.get().y; + _mouseStates->synchedTruckMovementMouseVelocity().y; } { // Roll around sphere normal dquat cameraRollRotation = - angleAxis(_mouseStates->_globalRollMouseState.velocity.get().x, -directionToCenter); + angleAxis(_mouseStates->synchedGlobalRollMouseVelocity().x, -directionToCenter); globalCameraRotation = cameraRollRotation * globalCameraRotation; } { // Push up to surface @@ -378,9 +437,17 @@ void OrbitalInteractionMode::updateCameraStateFromMouseStates(Camera& camera) { } } -void OrbitalInteractionMode::update(Camera& camera, const InputState& inputState, double deltaTime) { +void OrbitalInteractionMode::updateMouseStatesFromInput(const InputState& inputState, double deltaTime) { _mouseStates->updateMouseStatesFromInput(inputState, deltaTime); - updateCameraStateFromMouseStates(camera); + _mouseStates->preSynchronization(); +} + +void OrbitalInteractionMode::serialize(SyncBuffer* syncBuffer) { + _mouseStates->serialize(syncBuffer); +} + +void OrbitalInteractionMode::deserialize(SyncBuffer* syncBuffer) { + _mouseStates->deserialize(syncBuffer); } GlobeBrowsingInteractionMode::GlobeBrowsingInteractionMode(std::shared_ptr mouseStates) @@ -408,6 +475,9 @@ void GlobeBrowsingInteractionMode::setFocusNode(SceneGraphNode* focusNode) { } void GlobeBrowsingInteractionMode::updateCameraStateFromMouseStates(Camera& camera) { + // Update synched data + _mouseStates->postSynchronizationPreDraw(); + using namespace glm; if (_focusNode && _globe) { // Declare variables to use in interaction calculations @@ -467,19 +537,19 @@ void GlobeBrowsingInteractionMode::updateCameraStateFromMouseStates(Camera& came { // Do local roll glm::dquat cameraRollRotation = - glm::angleAxis(_mouseStates->_localRollMouseState.velocity.get().x, dvec3(0, 0, 1)); + glm::angleAxis(_mouseStates->synchedLocalRollMouseVelocity().x, dvec3(0, 0, 1)); localCameraRotation = localCameraRotation * cameraRollRotation; } { // Do local rotation - glm::dvec3 eulerAngles(_mouseStates->_localRotationMouseState.velocity.get().y, _mouseStates->_localRotationMouseState.velocity.get().x, 0); + glm::dvec3 eulerAngles(_mouseStates->synchedLocalRotationMouseVelocity().y, _mouseStates->synchedLocalRotationMouseVelocity().x, 0); glm::dquat rotationDiff = glm::dquat(eulerAngles); localCameraRotation = localCameraRotation * rotationDiff; } { // Do global rotation (horizontal movement) glm::dvec3 eulerAngles = glm::dvec3( - -_mouseStates->_globalRotationMouseState.velocity.get().y, - -_mouseStates->_globalRotationMouseState.velocity.get().x, + -_mouseStates->synchedGlobalRotationMouseVelocity().y, + -_mouseStates->synchedGlobalRotationMouseVelocity().x, 0) * glm::clamp(distFromEllipsoidSurfaceToCamera / distFromCenterToSurface, 0.0, 1.0); glm::dquat rotationDiffCamSpace = glm::dquat(eulerAngles); @@ -528,11 +598,11 @@ void GlobeBrowsingInteractionMode::updateCameraStateFromMouseStates(Camera& came { // Move position towards or away from focus node distFromEllipsoidSurfaceToCamera = glm::length(ellipsoidSurfaceToCamera); camPos += -directionFromSurfaceToCamera * distFromEllipsoidSurfaceToCamera * - _mouseStates->_truckMovementMouseState.velocity.get().y; + _mouseStates->synchedTruckMovementMouseVelocity().y; } { // Roll around ellipsoid normal glm::dquat cameraRollRotation = - glm::angleAxis(_mouseStates->_globalRollMouseState.velocity.get().x, directionFromSurfaceToCamera); + glm::angleAxis(_mouseStates->synchedGlobalRollMouseVelocity().x, directionFromSurfaceToCamera); globalCameraRotation = cameraRollRotation * globalCameraRotation; } { // Push up to surface @@ -558,10 +628,5 @@ void GlobeBrowsingInteractionMode::updateCameraStateFromMouseStates(Camera& came } } -void GlobeBrowsingInteractionMode::update(Camera& camera, const InputState& inputState, double deltaTime) { - _mouseStates->updateMouseStatesFromInput(inputState, deltaTime); - updateCameraStateFromMouseStates(camera); -} - } // namespace interaction } // namespace openspace diff --git a/src/rendering/renderengine.cpp b/src/rendering/renderengine.cpp index cc8b7d4a7e..3382d4ad3b 100644 --- a/src/rendering/renderengine.cpp +++ b/src/rendering/renderengine.cpp @@ -319,8 +319,8 @@ bool RenderEngine::initializeGL() { } void RenderEngine::preSynchronization() { - if (_mainCamera) - _mainCamera->preSynchronization(); + //if (_mainCamera) + // _mainCamera->preSynchronization(); } void RenderEngine::postSynchronizationPreDraw() { @@ -339,8 +339,8 @@ void RenderEngine::postSynchronizationPreDraw() { } } - if (_mainCamera) - _mainCamera->postSynchronizationPreDraw(); + //if (_mainCamera) + // _mainCamera->postSynchronizationPreDraw(); bool windowResized = OsEng.windowWrapper().windowHasResized();