proper corner case check for Quat::lookAtSimple()

This commit is contained in:
Andrew Meadows 2016-11-03 09:17:22 -07:00
parent cd5826e2ce
commit b7c6922545

View file

@ -37,7 +37,8 @@ glm::quat Quat::lookAt(const glm::vec3& eye, const glm::vec3& center, const glm:
glm::quat Quat::lookAtSimple(const glm::vec3& eye, const glm::vec3& center) { glm::quat Quat::lookAtSimple(const glm::vec3& eye, const glm::vec3& center) {
auto dir = glm::normalize(center - eye); auto dir = glm::normalize(center - eye);
// if the direction is nearly aligned with the Y axis, then use the X axis for 'up' // if the direction is nearly aligned with the Y axis, then use the X axis for 'up'
if (dir.x < 0.001f && dir.z < 0.001f) { const float MAX_ABS_Y_COMPONENT = 0.9999991f;
if (fabsf(dir.y) > MAX_ABS_Y_COMPONENT) {
return lookAt(eye, center, Vectors::UNIT_X); return lookAt(eye, center, Vectors::UNIT_X);
} }
return lookAt(eye, center, Vectors::UNIT_Y); return lookAt(eye, center, Vectors::UNIT_Y);