History

Fixing sixense and restoring lookat

Bradley Austin Davis committed 11 years ago

Commit 098a9bd1 parent fb3e3096 files · +65 −8Browse files

Showing the changes to interface/src/Camera.cpp (1 of 6 files). Show all

Unified · Split

interface/src/Camera.cpp+37−1
@@ -53,24 +53,42 @@ Camera::Camera() : · 52 unmodified lines
5353 _nearClip(DEFAULT_NEAR_CLIP), // default
5454 _farClip(DEFAULT_FAR_CLIP), // default
5555 _hmdPosition(),
56− _hmdRotation()
56+ _hmdRotation(),
57+ _isKeepLookingAt(false),
58+ _lookingAt(0.0f, 0.0f, 0.0f)
5759 {
5860 }
5961
62+void Camera::update(float deltaTime) {
63+ if (_isKeepLookingAt) {
64+ lookAt(_lookingAt);
65+ }
66+ return;
67+}
68+
6069 void Camera::setPosition(const glm::vec3& position) {
6170 _position = position;
6271 }
6372
6473 void Camera::setRotation(const glm::quat& rotation) {
6574 _rotation = rotation;
75+ if (_isKeepLookingAt) {
76+ lookAt(_lookingAt);
77+ }
6678 }
6779
6880 void Camera::setHmdPosition(const glm::vec3& hmdPosition) {
6981 _hmdPosition = hmdPosition;
82+ if (_isKeepLookingAt) {
83+ lookAt(_lookingAt);
84+ }
7085 }
7186
7287 void Camera::setHmdRotation(const glm::quat& hmdRotation) {
7388 _hmdRotation = hmdRotation;
89+ if (_isKeepLookingAt) {
90+ lookAt(_lookingAt);
91+ }
7492 }
7593
7694 float Camera::getFarClip() const {
@@ -101,6 +119,10 @@ void Camera::setFarClip(float f) { · 24 unmodified lines
101119 _farClip = f;
102120 }
103121
122+PickRay Camera::computePickRay(float x, float y) {
123+ return qApp->computePickRay(x, y);
124+}
125+
104126 void Camera::setModeString(const QString& mode) {
105127 CameraMode targetMode = stringToMode(mode);
106128
@@ -129,3 +151,17 @@ void Camera::setModeString(const QString& mode) { · 22 unmodified lines
129151 QString Camera::getModeString() const {
130152 return modeToString(_mode);
131153 }
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+}