mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 18:42:58 +02:00
restore camera lookAt and keepLookingAt features
This commit is contained in:
parent
23559743d9
commit
806e691bbf
3 changed files with 68 additions and 14 deletions
|
@ -22,7 +22,7 @@ var oldMode = Camera.mode;
|
||||||
function cancelLookAt() {
|
function cancelLookAt() {
|
||||||
if (lookingAtSomething) {
|
if (lookingAtSomething) {
|
||||||
lookingAtSomething = false;
|
lookingAtSomething = false;
|
||||||
//Camera.stopLooking();
|
Camera.stopLooking();
|
||||||
Camera.mode = oldMode;
|
Camera.mode = oldMode;
|
||||||
releaseMovementKeys();
|
releaseMovementKeys();
|
||||||
}
|
}
|
||||||
|
@ -74,7 +74,7 @@ function mousePressEvent(event) {
|
||||||
Camera.mode = "independent";
|
Camera.mode = "independent";
|
||||||
|
|
||||||
// tell the camera to fix it's look at on the point we clicked
|
// 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
|
// keep track of the fact that we're in this looking at mode
|
||||||
lookingAtSomething = true;
|
lookingAtSomething = true;
|
||||||
|
|
|
@ -55,16 +55,44 @@ Camera::Camera() :
|
||||||
_farClip(DEFAULT_FAR_CLIP), // default
|
_farClip(DEFAULT_FAR_CLIP), // default
|
||||||
_hmdPosition(),
|
_hmdPosition(),
|
||||||
_hmdRotation(),
|
_hmdRotation(),
|
||||||
_targetPosition(),
|
_scale(1.0f),
|
||||||
_targetRotation(),
|
_isKeepLookingAt(false),
|
||||||
_scale(1.0f)
|
_lookingAt(0.0f, 0.0f, 0.0f)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void Camera::update(float deltaTime) {
|
void Camera::update(float deltaTime) {
|
||||||
|
if (_isKeepLookingAt) {
|
||||||
|
lookAt(_lookingAt);
|
||||||
|
}
|
||||||
return;
|
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 {
|
float Camera::getFarClip() const {
|
||||||
return (_scale * _farClip < std::numeric_limits<int16_t>::max())
|
return (_scale * _farClip < std::numeric_limits<int16_t>::max())
|
||||||
? _scale * _farClip
|
? _scale * _farClip
|
||||||
|
@ -136,3 +164,17 @@ void Camera::setModeString(const QString& mode) {
|
||||||
QString Camera::getModeString() const {
|
QString Camera::getModeString() const {
|
||||||
return modeToString(_mode);
|
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;
|
||||||
|
}
|
||||||
|
|
|
@ -43,9 +43,9 @@ public:
|
||||||
|
|
||||||
void update( float deltaTime );
|
void update( float deltaTime );
|
||||||
|
|
||||||
void setRotation(const glm::quat& rotation) { _rotation = rotation; };
|
void setRotation(const glm::quat& rotation);
|
||||||
void setHmdPosition(const glm::vec3& hmdPosition) { _hmdPosition = hmdPosition; }
|
void setHmdPosition(const glm::vec3& hmdPosition);
|
||||||
void setHmdRotation(const glm::quat& hmdRotation) { _hmdRotation = hmdRotation; };
|
void setHmdRotation(const glm::quat& hmdRotation);
|
||||||
|
|
||||||
void setMode(CameraMode m);
|
void setMode(CameraMode m);
|
||||||
void setFieldOfView(float f);
|
void setFieldOfView(float f);
|
||||||
|
@ -73,13 +73,25 @@ public slots:
|
||||||
void setModeString(const QString& mode);
|
void setModeString(const QString& mode);
|
||||||
|
|
||||||
glm::vec3 getPosition() const { return _position + _hmdPosition; }
|
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); }
|
void setOrientation(const glm::quat& orientation) { setRotation(orientation); }
|
||||||
glm::quat getOrientation() const { return getRotation(); }
|
glm::quat getOrientation() const { return getRotation(); }
|
||||||
|
|
||||||
PickRay computePickRay(float x, float y);
|
PickRay computePickRay(float x, float y);
|
||||||
PickRay computeViewPickRay(float xRatio, float yRatio);
|
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:
|
signals:
|
||||||
void modeUpdated(const QString& newMode);
|
void modeUpdated(const QString& newMode);
|
||||||
|
|
||||||
|
@ -95,9 +107,9 @@ private:
|
||||||
glm::quat _rotation;
|
glm::quat _rotation;
|
||||||
glm::vec3 _hmdPosition;
|
glm::vec3 _hmdPosition;
|
||||||
glm::quat _hmdRotation;
|
glm::quat _hmdRotation;
|
||||||
glm::vec3 _targetPosition;
|
|
||||||
glm::quat _targetRotation;
|
|
||||||
float _scale;
|
float _scale;
|
||||||
|
bool _isKeepLookingAt;
|
||||||
|
glm::vec3 _lookingAt;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // hifi_Camera_h
|
#endif // hifi_Camera_h
|
||||||
|
|
Loading…
Reference in a new issue