mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-03-06 04:18:36 -06:00
Remove Camera pointer from all InteractionModes. Pass it into update() instead
This commit is contained in:
@@ -192,13 +192,11 @@ public:
|
||||
|
||||
// Mutators
|
||||
virtual void setFocusNode(SceneGraphNode* focusNode);
|
||||
void setCamera(Camera* camera);
|
||||
|
||||
// Accessors
|
||||
SceneGraphNode* focusNode();
|
||||
Camera* camera();
|
||||
|
||||
virtual void update(const InputState& inputState, double deltaTime) = 0;
|
||||
virtual void update(Camera& camera, const InputState& inputState, double deltaTime) = 0;
|
||||
protected:
|
||||
/**
|
||||
Inner class that acts as a smoothing filter to a variable. The filter has a step
|
||||
@@ -234,7 +232,6 @@ protected:
|
||||
};
|
||||
|
||||
SceneGraphNode* _focusNode = nullptr;
|
||||
Camera* _camera = nullptr;
|
||||
};
|
||||
|
||||
class KeyframeInteractionMode : public InteractionMode
|
||||
@@ -260,10 +257,10 @@ public:
|
||||
OrbitalInteractionMode(double sensitivity, double velocityScaleFactor);
|
||||
~OrbitalInteractionMode();
|
||||
|
||||
virtual void update(const InputState& inputState, double deltaTime);
|
||||
virtual void update(Camera& camera, const InputState& inputState, double deltaTime);
|
||||
protected:
|
||||
void updateMouseStatesFromInput(const InputState& inputState, double deltaTime);
|
||||
void updateCameraStateFromMouseStates();
|
||||
void updateCameraStateFromMouseStates(Camera& camera);
|
||||
|
||||
double _sensitivity;
|
||||
|
||||
@@ -283,9 +280,9 @@ public:
|
||||
~GlobeBrowsingInteractionMode();
|
||||
|
||||
virtual void setFocusNode(SceneGraphNode* focusNode);
|
||||
virtual void update(const InputState& inputState, double deltaTime);
|
||||
virtual void update(Camera& camera, const InputState& inputState, double deltaTime);
|
||||
private:
|
||||
void updateCameraStateFromMouseStates();
|
||||
void updateCameraStateFromMouseStates(Camera& camera);
|
||||
RenderableGlobe* _globe;
|
||||
};
|
||||
|
||||
@@ -341,6 +338,7 @@ private:
|
||||
std::multimap<KeyWithModifier, std::string > _keyLua;
|
||||
|
||||
std::unique_ptr<InputState> _inputState;
|
||||
Camera* _camera;
|
||||
|
||||
std::shared_ptr<InteractionMode> _currentInteractionMode;
|
||||
|
||||
@@ -350,6 +348,7 @@ private:
|
||||
// Properties
|
||||
properties::StringProperty _origin;
|
||||
properties::StringProperty _coordinateSystem;
|
||||
|
||||
};
|
||||
|
||||
#endif // USE_OLD_INTERACTIONHANDLER
|
||||
|
||||
@@ -717,18 +717,10 @@ void InteractionMode::setFocusNode(SceneGraphNode* focusNode) {
|
||||
_focusNode = focusNode;
|
||||
}
|
||||
|
||||
void InteractionMode::setCamera(Camera* camera) {
|
||||
_camera = camera;
|
||||
}
|
||||
|
||||
SceneGraphNode* InteractionMode::focusNode() {
|
||||
return _focusNode;
|
||||
}
|
||||
|
||||
Camera* InteractionMode::camera() {
|
||||
return _camera;
|
||||
}
|
||||
|
||||
// KeyframeInteractionMode
|
||||
KeyframeInteractionMode::KeyframeInteractionMode(){
|
||||
|
||||
@@ -811,11 +803,11 @@ void OrbitalInteractionMode::updateMouseStatesFromInput(const InputState& inputS
|
||||
}
|
||||
}
|
||||
|
||||
void OrbitalInteractionMode::updateCameraStateFromMouseStates() {
|
||||
void OrbitalInteractionMode::updateCameraStateFromMouseStates(Camera& camera) {
|
||||
if (_focusNode) {
|
||||
// Declare variables to use in interaction calculations
|
||||
glm::dvec3 centerPos = _focusNode->worldPosition().dvec3();
|
||||
glm::dvec3 camPos = _camera->positionVec3();
|
||||
glm::dvec3 camPos = camera.positionVec3();
|
||||
glm::dvec3 posDiff = camPos - centerPos;
|
||||
glm::dvec3 newPosition = camPos;
|
||||
|
||||
@@ -844,7 +836,7 @@ void OrbitalInteractionMode::updateCameraStateFromMouseStates() {
|
||||
glm::dvec3 directionToCenter = glm::normalize(centerPos - newPosition);
|
||||
|
||||
glm::dvec3 lookUpWhenFacingCenter =
|
||||
_globalCameraRotation * glm::dvec3(_camera->lookUpVectorCameraSpace());
|
||||
_globalCameraRotation * glm::dvec3(camera.lookUpVectorCameraSpace());
|
||||
glm::dmat4 lookAtMat = glm::lookAt(
|
||||
glm::dvec3(0, 0, 0),
|
||||
directionToCenter,
|
||||
@@ -867,14 +859,14 @@ void OrbitalInteractionMode::updateCameraStateFromMouseStates() {
|
||||
}
|
||||
|
||||
// Update the camera state
|
||||
_camera->setRotation(_globalCameraRotation * _localCameraRotation);
|
||||
_camera->setPositionVec3(newPosition);
|
||||
camera.setRotation(_globalCameraRotation * _localCameraRotation);
|
||||
camera.setPositionVec3(newPosition);
|
||||
}
|
||||
}
|
||||
|
||||
void OrbitalInteractionMode::update(const InputState& inputState, double deltaTime) {
|
||||
void OrbitalInteractionMode::update(Camera& camera, const InputState& inputState, double deltaTime) {
|
||||
updateMouseStatesFromInput(inputState, deltaTime);
|
||||
updateCameraStateFromMouseStates();
|
||||
updateCameraStateFromMouseStates(camera);
|
||||
}
|
||||
|
||||
GlobeBrowsingInteractionMode::GlobeBrowsingInteractionMode(double sensitivity, double velocityScaleFactor)
|
||||
@@ -902,11 +894,11 @@ void GlobeBrowsingInteractionMode::setFocusNode(SceneGraphNode* focusNode) {
|
||||
}
|
||||
|
||||
|
||||
void GlobeBrowsingInteractionMode::updateCameraStateFromMouseStates() {
|
||||
void GlobeBrowsingInteractionMode::updateCameraStateFromMouseStates(Camera& camera) {
|
||||
if (_focusNode && _globe) {
|
||||
// Declare variables to use in interaction calculations
|
||||
glm::dvec3 centerPos = _focusNode->worldPosition().dvec3();
|
||||
glm::dvec3 camPos = _camera->positionVec3();
|
||||
glm::dvec3 camPos = camera.positionVec3();
|
||||
glm::dvec3 posDiff = camPos - centerPos;
|
||||
glm::dvec3 newPosition = camPos;
|
||||
|
||||
@@ -950,7 +942,7 @@ void GlobeBrowsingInteractionMode::updateCameraStateFromMouseStates() {
|
||||
glm::dvec3 newDirectionFromSurfaceToCamera = glm::normalize(newSurfaceToCamera);
|
||||
|
||||
glm::dvec3 lookUpWhenFacingSurface =
|
||||
_globalCameraRotation * glm::dvec3(_camera->lookUpVectorCameraSpace());
|
||||
_globalCameraRotation * glm::dvec3(camera.lookUpVectorCameraSpace());
|
||||
glm::dmat4 lookAtMat = glm::lookAt(
|
||||
glm::dvec3(0, 0, 0),
|
||||
-newDirectionFromSurfaceToCamera,
|
||||
@@ -969,14 +961,14 @@ void GlobeBrowsingInteractionMode::updateCameraStateFromMouseStates() {
|
||||
}
|
||||
|
||||
// Update the camera state
|
||||
_camera->setRotation(_globalCameraRotation * _localCameraRotation);
|
||||
_camera->setPositionVec3(newPosition);
|
||||
camera.setRotation(_globalCameraRotation * _localCameraRotation);
|
||||
camera.setPositionVec3(newPosition);
|
||||
}
|
||||
}
|
||||
|
||||
void GlobeBrowsingInteractionMode::update(const InputState& inputState, double deltaTime) {
|
||||
void GlobeBrowsingInteractionMode::update(Camera& camera, const InputState& inputState, double deltaTime) {
|
||||
updateMouseStatesFromInput(inputState, deltaTime);
|
||||
updateCameraStateFromMouseStates();
|
||||
updateCameraStateFromMouseStates(camera);
|
||||
}
|
||||
|
||||
// InteractionHandler
|
||||
@@ -1018,19 +1010,17 @@ void InteractionHandler::setFocusNode(SceneGraphNode* node) {
|
||||
}
|
||||
|
||||
void InteractionHandler::setCamera(Camera* camera) {
|
||||
_currentInteractionMode->setCamera(camera);
|
||||
_camera = camera;
|
||||
}
|
||||
|
||||
void InteractionHandler::setInteractionMode(std::shared_ptr<InteractionMode> interactionMode) {
|
||||
// Camera and focus node is passed over from the previous interaction mode
|
||||
Camera* camera = _currentInteractionMode->camera();
|
||||
// Focus node is passed over from the previous interaction mode
|
||||
SceneGraphNode* focusNode = _currentInteractionMode->focusNode();
|
||||
|
||||
// Set the interaction mode
|
||||
_currentInteractionMode = interactionMode;
|
||||
|
||||
// Update the camera and focusnode for the new interaction mode
|
||||
_currentInteractionMode->setCamera(camera);
|
||||
// Update the focusnode for the new interaction mode
|
||||
_currentInteractionMode->setFocusNode(focusNode);
|
||||
}
|
||||
|
||||
@@ -1051,8 +1041,9 @@ void InteractionHandler::unlockControls() {
|
||||
}
|
||||
|
||||
void InteractionHandler::update(double deltaTime) {
|
||||
ghoul_assert(_inputState != nullptr, "InputState cannot is null!");
|
||||
_currentInteractionMode->update(*_inputState, deltaTime);
|
||||
ghoul_assert(_inputState != nullptr, "InputState cannot be null!");
|
||||
ghoul_assert(_camera != nullptr, "Camera cannot be null!");
|
||||
_currentInteractionMode->update(*_camera, *_inputState, deltaTime);
|
||||
}
|
||||
|
||||
SceneGraphNode* const InteractionHandler::focusNode() const {
|
||||
@@ -1060,7 +1051,7 @@ SceneGraphNode* const InteractionHandler::focusNode() const {
|
||||
}
|
||||
|
||||
Camera* const InteractionHandler::camera() const {
|
||||
return _currentInteractionMode->camera();
|
||||
return _camera;
|
||||
}
|
||||
|
||||
const InputState& InteractionHandler::inputState() const {
|
||||
|
||||
Reference in New Issue
Block a user