Showing the changes to interface/src/Camera.cpp (1 of 6 files). Show all
Unified · Split
| @@ -53,24 +53,42 @@ Camera::Camera() : · 52 unmodified lines | ||
| 53 | 53 | _nearClip(DEFAULT_NEAR_CLIP), // default |
| 54 | 54 | _farClip(DEFAULT_FAR_CLIP), // default |
| 55 | 55 | _hmdPosition(), |
| 56 | − _hmdRotation() | |
| 56 | + _hmdRotation(), | |
| 57 | + _isKeepLookingAt(false), | |
| 58 | + _lookingAt(0.0f, 0.0f, 0.0f) | |
| 57 | 59 | { |
| 58 | 60 | } |
| 59 | 61 | |
| 62 | +void Camera::update(float deltaTime) { | |
| 63 | + if (_isKeepLookingAt) { | |
| 64 | + lookAt(_lookingAt); | |
| 65 | + } | |
| 66 | + return; | |
| 67 | +} | |
| 68 | + | |
| 60 | 69 | void Camera::setPosition(const glm::vec3& position) { |
| 61 | 70 | _position = position; |
| 62 | 71 | } |
| 63 | 72 | |
| 64 | 73 | void Camera::setRotation(const glm::quat& rotation) { |
| 65 | 74 | _rotation = rotation; |
| 75 | + if (_isKeepLookingAt) { | |
| 76 | + lookAt(_lookingAt); | |
| 77 | + } | |
| 66 | 78 | } |
| 67 | 79 | |
| 68 | 80 | void Camera::setHmdPosition(const glm::vec3& hmdPosition) { |
| 69 | 81 | _hmdPosition = hmdPosition; |
| 82 | + if (_isKeepLookingAt) { | |
| 83 | + lookAt(_lookingAt); | |
| 84 | + } | |
| 70 | 85 | } |
| 71 | 86 | |
| 72 | 87 | void Camera::setHmdRotation(const glm::quat& hmdRotation) { |
| 73 | 88 | _hmdRotation = hmdRotation; |
| 89 | + if (_isKeepLookingAt) { | |
| 90 | + lookAt(_lookingAt); | |
| 91 | + } | |
| 74 | 92 | } |
| 75 | 93 | |
| 76 | 94 | float Camera::getFarClip() const { |
| @@ -101,6 +119,10 @@ void Camera::setFarClip(float f) { · 24 unmodified lines | ||
| 101 | 119 | _farClip = f; |
| 102 | 120 | } |
| 103 | 121 | |
| 122 | +PickRay Camera::computePickRay(float x, float y) { | |
| 123 | + return qApp->computePickRay(x, y); | |
| 124 | +} | |
| 125 | + | |
| 104 | 126 | void Camera::setModeString(const QString& mode) { |
| 105 | 127 | CameraMode targetMode = stringToMode(mode); |
| 106 | 128 | |
| @@ -129,3 +151,17 @@ void Camera::setModeString(const QString& mode) { · 22 unmodified lines | ||
| 129 | 151 | QString Camera::getModeString() const { |
| 130 | 152 | return modeToString(_mode); |
| 131 | 153 | } |
| 154 | + | |
| 155 | +void Camera::lookAt(const glm::vec3& lookAt) { | |
| 156 | + glm::vec3 up = IDENTITY_UP; | |
| 157 | + glm::mat4 lookAtMatrix = glm::lookAt(_position, lookAt, up); | |
| 158 | + glm::quat rotation = glm::quat_cast(lookAtMatrix); | |
| 159 | + rotation.w = -rotation.w; // Rosedale approved | |
| 160 | + _rotation = rotation; | |
| 161 | +} | |
| 162 | + | |
| 163 | +void Camera::keepLookingAt(const glm::vec3& point) { | |
| 164 | + lookAt(point); | |
| 165 | + _isKeepLookingAt = true; | |
| 166 | + _lookingAt = point; | |
| 167 | +} | |