From c64a530be4e3d33dc163866c4b9f1341650c8e12 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Sun, 9 Feb 2014 16:24:38 -0800 Subject: [PATCH] first cut at lookAt --- interface/src/Camera.cpp | 16 +++++++++++++++- interface/src/Camera.h | 26 ++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/interface/src/Camera.cpp b/interface/src/Camera.cpp index 87725967b9..6dd327a3c3 100644 --- a/interface/src/Camera.cpp +++ b/interface/src/Camera.cpp @@ -58,7 +58,9 @@ Camera::Camera() : _modeShift(1.0f), _linearModeShift(0.0f), _modeShiftRate(1.0f), - _scale(1.0f) + _scale(1.0f), + _lookingAt(0.0f, 0.0f, 0.0f), + _isKeepLookingAt(false) { } @@ -222,6 +224,18 @@ void Camera::setFrustumWasReshaped() { _frustumNeedsReshape = false; } +void Camera::lookAt(const glm::vec3& lookAt) { + glm::vec3 up = IDENTITY_UP; + glm::mat4 lookAtMatrix = glm::lookAt(_position, lookAt, up); + glm::quat rotation = glm::quat_cast(lookAtMatrix); + rotation.w = -rotation.w; // Rosedale approved + setTargetRotation(rotation); +} + +void Camera::keepLookingAt(const glm::vec3& value) { + lookAt(value); + _isKeepLookingAt = true; +} CameraScriptableObject::CameraScriptableObject(Camera* camera, ViewFrustum* viewFrustum) : _camera(camera), _viewFrustum(viewFrustum) diff --git a/interface/src/Camera.h b/interface/src/Camera.h index 075f1a7ed6..5f34dbfe6c 100644 --- a/interface/src/Camera.h +++ b/interface/src/Camera.h @@ -10,6 +10,7 @@ #include #include +#include #include #include @@ -68,6 +69,17 @@ public: bool getFrustumNeedsReshape() const; // call to find out if the view frustum needs to be reshaped void setFrustumWasReshaped(); // call this after reshaping the view frustum. + + // These only work on independent cameras + /// one time change to what the camera is looking at + void lookAt(const glm::vec3& value); + + /// fix what the camera is looking at, and keep the camera looking at this even if position changes + void keepLookingAt(const glm::vec3& value); + + /// stops the keep looking at feature, doesn't change what's being looked at, but will stop camera from + /// continuing to update it's orientation to keep looking at the item + void stopKeepLookingAt() { _isKeepLookingAt = false; } private: @@ -99,6 +111,9 @@ private: float _linearModeShift; float _modeShiftRate; float _scale; + + glm::vec3 _lookingAt; + bool _isKeepLookingAt; void updateFollowMode(float deltaTime); }; @@ -119,6 +134,17 @@ public slots: void setOrientation(const glm::quat& value) { _camera->setTargetRotation(value); } glm::quat getOrientation() const { return _camera->getRotation(); } + // These only work on independent cameras + /// one time change to what the camera is looking at + void lookAt(const glm::vec3& value) { _camera->lookAt(value);} + + /// fix what the camera is looking at, and keep the camera looking at this even if position changes + void keepLookingAt(const glm::vec3& value) { _camera->keepLookingAt(value);} + + /// stops the keep looking at feature, doesn't change what's being looked at, but will stop camera from + /// continuing to update it's orientation to keep looking at the item + void stopKeepLookingAt() { _camera->stopKeepLookingAt();} + PickRay computePickRay(float x, float y); private: