mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 09:48:44 +02:00
first cut at lookAt
This commit is contained in:
parent
e30e1ffe28
commit
c64a530be4
2 changed files with 41 additions and 1 deletions
|
@ -58,7 +58,9 @@ Camera::Camera() :
|
||||||
_modeShift(1.0f),
|
_modeShift(1.0f),
|
||||||
_linearModeShift(0.0f),
|
_linearModeShift(0.0f),
|
||||||
_modeShiftRate(1.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;
|
_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) :
|
CameraScriptableObject::CameraScriptableObject(Camera* camera, ViewFrustum* viewFrustum) :
|
||||||
_camera(camera), _viewFrustum(viewFrustum)
|
_camera(camera), _viewFrustum(viewFrustum)
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
|
|
||||||
#include <glm/glm.hpp>
|
#include <glm/glm.hpp>
|
||||||
#include <glm/gtc/quaternion.hpp>
|
#include <glm/gtc/quaternion.hpp>
|
||||||
|
#include <glm/gtc/matrix_transform.hpp>
|
||||||
#include <RegisteredMetaTypes.h>
|
#include <RegisteredMetaTypes.h>
|
||||||
#include <ViewFrustum.h>
|
#include <ViewFrustum.h>
|
||||||
|
|
||||||
|
@ -68,6 +69,17 @@ public:
|
||||||
|
|
||||||
bool getFrustumNeedsReshape() const; // call to find out if the view frustum needs to be reshaped
|
bool getFrustumNeedsReshape() const; // call to find out if the view frustum needs to be reshaped
|
||||||
void setFrustumWasReshaped(); // call this after reshaping the view frustum.
|
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:
|
private:
|
||||||
|
|
||||||
|
@ -99,6 +111,9 @@ private:
|
||||||
float _linearModeShift;
|
float _linearModeShift;
|
||||||
float _modeShiftRate;
|
float _modeShiftRate;
|
||||||
float _scale;
|
float _scale;
|
||||||
|
|
||||||
|
glm::vec3 _lookingAt;
|
||||||
|
bool _isKeepLookingAt;
|
||||||
|
|
||||||
void updateFollowMode(float deltaTime);
|
void updateFollowMode(float deltaTime);
|
||||||
};
|
};
|
||||||
|
@ -119,6 +134,17 @@ public slots:
|
||||||
void setOrientation(const glm::quat& value) { _camera->setTargetRotation(value); }
|
void setOrientation(const glm::quat& value) { _camera->setTargetRotation(value); }
|
||||||
glm::quat getOrientation() const { return _camera->getRotation(); }
|
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);
|
PickRay computePickRay(float x, float y);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
Loading…
Reference in a new issue