3
0
Fork 0
mirror of https://github.com/lubosz/overte.git synced 2025-04-12 10:02:25 +02:00

restore camera lookAt and keepLookingAt features

This commit is contained in:
ZappoMan 2015-01-07 13:41:07 -08:00
parent 23559743d9
commit 806e691bbf
3 changed files with 68 additions and 14 deletions
examples/example/avatarcontrol
interface/src

View file

@ -22,7 +22,7 @@ var oldMode = Camera.mode;
function cancelLookAt() {
if (lookingAtSomething) {
lookingAtSomething = false;
//Camera.stopLooking();
Camera.stopLooking();
Camera.mode = oldMode;
releaseMovementKeys();
}
@ -74,7 +74,7 @@ function mousePressEvent(event) {
Camera.mode = "independent";
// tell the camera to fix it's look at on the point we clicked
//Camera.keepLookingAt(intersection.intersection);
Camera.keepLookingAt(intersection.intersection);
// keep track of the fact that we're in this looking at mode
lookingAtSomething = true;

View file

@ -55,16 +55,44 @@ Camera::Camera() :
_farClip(DEFAULT_FAR_CLIP), // default
_hmdPosition(),
_hmdRotation(),
_targetPosition(),
_targetRotation(),
_scale(1.0f)
_scale(1.0f),
_isKeepLookingAt(false),
_lookingAt(0.0f, 0.0f, 0.0f)
{
}
void Camera::update(float deltaTime) {
if (_isKeepLookingAt) {
lookAt(_lookingAt);
}
return;
}
void Camera::setPosition(const glm::vec3& position) {
_position = position;
}
void Camera::setRotation(const glm::quat& rotation) {
_rotation = rotation;
if (_isKeepLookingAt) {
lookAt(_lookingAt);
}
}
void Camera::setHmdPosition(const glm::vec3& hmdPosition) {
_hmdPosition = hmdPosition;
if (_isKeepLookingAt) {
lookAt(_lookingAt);
}
}
void Camera::setHmdRotation(const glm::quat& hmdRotation) {
_hmdRotation = hmdRotation;
if (_isKeepLookingAt) {
lookAt(_lookingAt);
}
}
float Camera::getFarClip() const {
return (_scale * _farClip < std::numeric_limits<int16_t>::max())
? _scale * _farClip
@ -81,15 +109,15 @@ void Camera::setFieldOfView(float f) {
_fieldOfView = f;
}
void Camera::setAspectRatio(float a) {
void Camera::setAspectRatio(float a) {
_aspectRatio = a;
}
void Camera::setNearClip(float n) {
void Camera::setNearClip(float n) {
_nearClip = n;
}
void Camera::setFarClip(float f) {
void Camera::setFarClip(float f) {
_farClip = f;
}
@ -136,3 +164,17 @@ void Camera::setModeString(const QString& mode) {
QString Camera::getModeString() const {
return modeToString(_mode);
}
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
_rotation = rotation;
}
void Camera::keepLookingAt(const glm::vec3& point) {
lookAt(point);
_isKeepLookingAt = true;
_lookingAt = point;
}

View file

@ -43,9 +43,9 @@ public:
void update( float deltaTime );
void setRotation(const glm::quat& rotation) { _rotation = rotation; };
void setHmdPosition(const glm::vec3& hmdPosition) { _hmdPosition = hmdPosition; }
void setHmdRotation(const glm::quat& hmdRotation) { _hmdRotation = hmdRotation; };
void setRotation(const glm::quat& rotation);
void setHmdPosition(const glm::vec3& hmdPosition);
void setHmdRotation(const glm::quat& hmdRotation);
void setMode(CameraMode m);
void setFieldOfView(float f);
@ -73,13 +73,25 @@ public slots:
void setModeString(const QString& mode);
glm::vec3 getPosition() const { return _position + _hmdPosition; }
void setPosition(const glm::vec3& position) { _position = position; }
void setPosition(const glm::vec3& position);
void setOrientation(const glm::quat& orientation) { setRotation(orientation); }
glm::quat getOrientation() const { return getRotation(); }
PickRay computePickRay(float x, float y);
PickRay computeViewPickRay(float xRatio, float yRatio);
// 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 stopLooking() { _isKeepLookingAt = false; }
signals:
void modeUpdated(const QString& newMode);
@ -95,9 +107,9 @@ private:
glm::quat _rotation;
glm::vec3 _hmdPosition;
glm::quat _hmdRotation;
glm::vec3 _targetPosition;
glm::quat _targetRotation;
float _scale;
bool _isKeepLookingAt;
glm::vec3 _lookingAt;
};
#endif // hifi_Camera_h