From ec0b1a99fb15b79d49208bf1ad4c4cffc933ba57 Mon Sep 17 00:00:00 2001 From: Andrzej Kapolka Date: Fri, 14 Jun 2013 11:23:08 -0700 Subject: [PATCH] Fix iris orientations: start with the head orientation, then rotate onto the lookat vector. This way, the irises don't rotate around as we yaw. --- interface/src/Head.cpp | 23 ++++++++++++----------- interface/src/Util.cpp | 2 +- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/interface/src/Head.cpp b/interface/src/Head.cpp index 63fc6d6c25..48282b1a5f 100644 --- a/interface/src/Head.cpp +++ b/interface/src/Head.cpp @@ -486,18 +486,19 @@ void Head::renderEyeBalls() { glBindTexture(GL_TEXTURE_2D, _irisTextureID); glEnable(GL_TEXTURE_2D); - glm::vec3 front = getFrontDirection(); + glm::quat orientation = getOrientation(); + glm::vec3 front = orientation * IDENTITY_FRONT; // render left iris glPushMatrix(); { glTranslatef(_leftEyePosition.x, _leftEyePosition.y, _leftEyePosition.z); //translate to eyeball position glPushMatrix(); //rotate the eyeball to aim towards the lookat position - glm::vec3 targetLookatAxis = glm::normalize(_lookAtPosition + _saccade - _leftEyePosition); - glm::vec3 rotationAxis = glm::cross(targetLookatAxis, IDENTITY_UP); - float angle = 180.0f - angleBetween(targetLookatAxis, IDENTITY_UP); - glRotatef(angle, rotationAxis.x, rotationAxis.y, rotationAxis.z); - glRotatef(180.0, 0.0f, 1.0f, 0.0f); //adjust roll to correct after previous rotations + glm::vec3 targetLookatVector = _lookAtPosition + _saccade - _leftEyePosition; + glm::quat rotation = rotationBetween(front, targetLookatVector) * orientation; + glm::vec3 rotationAxis = glm::axis(rotation); + glRotatef(glm::angle(rotation), rotationAxis.x, rotationAxis.y, rotationAxis.z); + glRotatef(90.0, 1.0f, 0.0f, 0.0f); // rotate to face Z- glTranslatef( 0.0f, -IRIS_PROTRUSION, 0.0f); glScalef( 1.0f, 0.5f, 1.0f); // flatten the iris gluSphere(irisQuadric, IRIS_RADIUS, 15, 15); @@ -511,11 +512,11 @@ void Head::renderEyeBalls() { glPushMatrix(); //rotate the eyeball to aim towards the lookat position - glm::vec3 targetLookatAxis = glm::normalize(_lookAtPosition + _saccade - _rightEyePosition); - glm::vec3 rotationAxis = glm::cross(targetLookatAxis, IDENTITY_UP); - float angle = 180.0f - angleBetween(targetLookatAxis, IDENTITY_UP); - glRotatef(angle, rotationAxis.x, rotationAxis.y, rotationAxis.z); - glRotatef(180.0f, 0.0f, 1.0f, 0.0f); //adjust roll to correct after previous rotations + glm::vec3 targetLookatVector = _lookAtPosition + _saccade - _rightEyePosition; + glm::quat rotation = rotationBetween(front, targetLookatVector) * orientation; + glm::vec3 rotationAxis = glm::axis(rotation); + glRotatef(glm::angle(rotation), rotationAxis.x, rotationAxis.y, rotationAxis.z); + glRotatef(90.0f, 1.0f, 0.0f, 0.0f); // rotate to face Z- glTranslatef( 0.0f, -IRIS_PROTRUSION, 0.0f); glScalef( 1.0f, 0.5f, 1.0f); // flatten the iris gluSphere(irisQuadric, IRIS_RADIUS, 15, 15); diff --git a/interface/src/Util.cpp b/interface/src/Util.cpp index 93596e1c1d..4bfdb1f587 100644 --- a/interface/src/Util.cpp +++ b/interface/src/Util.cpp @@ -85,7 +85,7 @@ glm::quat rotationBetween(const glm::vec3& v1, const glm::vec3& v2) { if (isnan(angle) || angle < EPSILON) { return glm::quat(); } - glm::vec3 axis = glm::cross(v1, v2); + glm::vec3 axis; if (angle > 179.99f) { // 180 degree rotation; must use another axis axis = glm::cross(v1, glm::vec3(1.0f, 0.0f, 0.0f)); float axisLength = glm::length(axis);