Fix camera in render perf test

This commit is contained in:
Brad Davis 2016-11-23 10:30:52 -08:00
parent 8b9c6a45e1
commit f2118614da
2 changed files with 17 additions and 15 deletions

View file

@ -13,11 +13,11 @@ protected:
}
public:
glm::quat getOrientation() const {
return glm::angleAxis(yawPitch.x, Vectors::UP) * glm::angleAxis(yawPitch.y, Vectors::RIGHT);
const glm::quat& getOrientation() const {
return orientation;
}
vec2 yawPitch { 0 };
glm::quat orientation;
glm::vec3 position;
float rotationSpeed { 1.0f };
float movementSpeed { 1.0f };
@ -77,24 +77,25 @@ public:
};
void rotate(const float delta) {
yawPitch.x += delta;
orientation = glm::angleAxis(delta, Vectors::UP) * orientation;
updateViewMatrix();
}
void rotate(const glm::vec2& delta) {
yawPitch += delta;
// create orientation vectors
auto lookat = orientation * Vectors::UNIT_NEG_Z;
auto forward = glm::normalize(vec3(lookat.x, 0, lookat.z));
auto side = glm::cross(Vectors::UP, forward);
// rotate camera with quaternions created from axis and angle
orientation = glm::angleAxis(delta.x, Vectors::UP) * orientation;
orientation = glm::angleAxis(-delta.y, side) * orientation;
updateViewMatrix();
}
void setRotation(const glm::quat& rotation) {
glm::vec3 f = rotation * Vectors::UNIT_NEG_Z;
f.y = 0;
f = glm::normalize(f);
yawPitch.x = angleBetween(Vectors::UNIT_NEG_Z, f);
f = rotation * Vectors::UNIT_NEG_Z;
f.x = 0;
f = glm::normalize(f);
yawPitch.y = angleBetween(Vectors::UNIT_NEG_Z, f);
orientation = rotation;
updateViewMatrix();
}

View file

@ -946,7 +946,7 @@ private:
orientationRegex.cap(3).toFloat(),
orientationRegex.cap(4).toFloat());
if (!glm::any(glm::isnan(v))) {
_camera.setRotation(glm::normalize(glm::quat(v.w, v.x, v.y, v.z)));
_camera.setRotation(glm::quat(v.w, v.x, v.y, v.z));
}
}
}
@ -1008,6 +1008,7 @@ private:
arg(v.x).arg(v.y).arg(v.z).
arg(q.x).arg(q.y).arg(q.z).arg(q.w);
_settings.setValue(LAST_LOCATION_KEY, viewpoint);
_camera.setRotation(q);
}
void restorePosition() {
@ -1019,7 +1020,7 @@ private:
}
void resetPosition() {
_camera.yawPitch = vec3(0);
_camera.setRotation(quat());
_camera.setPosition(vec3());
}