From 402f65fc00fd198d367d023de1fe0cbb3664006a Mon Sep 17 00:00:00 2001 From: Andrzej Kapolka Date: Wed, 25 Sep 2013 14:12:50 -0700 Subject: [PATCH] Use the blend face eye locations for the eye vectors, when possible. --- interface/src/avatar/BlendFace.cpp | 30 +++++++++++++++++++++++++----- interface/src/avatar/BlendFace.h | 2 ++ interface/src/avatar/Head.cpp | 8 +++++++- 3 files changed, 34 insertions(+), 6 deletions(-) diff --git a/interface/src/avatar/BlendFace.cpp b/interface/src/avatar/BlendFace.cpp index 90051dd4fc..4b0be2c051 100644 --- a/interface/src/avatar/BlendFace.cpp +++ b/interface/src/avatar/BlendFace.cpp @@ -35,6 +35,9 @@ void BlendFace::init() { } } +const glm::vec3 MODEL_TRANSLATION(0.0f, -0.025f, -0.025f); // temporary fudge factor +const float MODEL_SCALE = 0.0006f; + bool BlendFace::render(float alpha) { if (_meshIDs.isEmpty()) { return false; @@ -44,11 +47,9 @@ bool BlendFace::render(float alpha) { glTranslatef(_owningHead->getPosition().x, _owningHead->getPosition().y, _owningHead->getPosition().z); glm::quat orientation = _owningHead->getOrientation(); glm::vec3 axis = glm::axis(orientation); - glRotatef(glm::angle(orientation), axis.x, axis.y, axis.z); - const glm::vec3 MODEL_TRANSLATION(0.0f, -0.025f, -0.025f); // temporary fudge factor + glRotatef(glm::angle(orientation), axis.x, axis.y, axis.z); glTranslatef(MODEL_TRANSLATION.x, MODEL_TRANSLATION.y, MODEL_TRANSLATION.z); - const float MODEL_SCALE = 0.0006f; - glm::vec3 scale(_owningHead->getScale() * MODEL_SCALE, _owningHead->getScale() * MODEL_SCALE, + glm::vec3 scale(-_owningHead->getScale() * MODEL_SCALE, _owningHead->getScale() * MODEL_SCALE, -_owningHead->getScale() * MODEL_SCALE); glScalef(scale.x, scale.y, scale.z); @@ -75,7 +76,7 @@ bool BlendFace::render(float alpha) { glm::quat rotation = glm::inverse(orientation) * _owningHead->getEyeRotation(orientation * (mesh.pivot * scale + MODEL_TRANSLATION) + _owningHead->getPosition()); glm::vec3 rotationAxis = glm::axis(rotation); - glRotatef(glm::angle(-rotation), rotationAxis.x, rotationAxis.y, rotationAxis.z); + glRotatef(glm::angle(rotation), -rotationAxis.x, rotationAxis.y, -rotationAxis.z); glTranslatef(-mesh.pivot.x, -mesh.pivot.y, -mesh.pivot.z); // use texture coordinates only for the eye, for now @@ -149,6 +150,25 @@ bool BlendFace::render(float alpha) { return true; } +void BlendFace::getEyePositions(glm::vec3& firstEyePosition, glm::vec3& secondEyePosition) const { + glm::quat orientation = _owningHead->getOrientation(); + glm::vec3 scale(-_owningHead->getScale() * MODEL_SCALE, _owningHead->getScale() * MODEL_SCALE, + -_owningHead->getScale() * MODEL_SCALE); + bool foundFirst = false; + + foreach (const FBXMesh& mesh, _geometry.meshes) { + if (mesh.isEye) { + glm::vec3 position = orientation * (mesh.pivot * scale + MODEL_TRANSLATION) + _owningHead->getPosition(); + if (foundFirst) { + secondEyePosition = position; + return; + } + firstEyePosition = position; + foundFirst = true; + } + } +} + void BlendFace::setModelURL(const QUrl& url) { // don't restart the download if it's the same URL if (_modelURL == url) { diff --git a/interface/src/avatar/BlendFace.h b/interface/src/avatar/BlendFace.h index b7335208e2..0f1f82bbe2 100644 --- a/interface/src/avatar/BlendFace.h +++ b/interface/src/avatar/BlendFace.h @@ -36,6 +36,8 @@ public: Q_INVOKABLE void setModelURL(const QUrl& url); const QUrl& getModelURL() const { return _modelURL; } + void getEyePositions(glm::vec3& firstEyePosition, glm::vec3& secondEyePosition) const; + private slots: void handleModelDownloadProgress(qint64 bytesReceived, qint64 bytesTotal); diff --git a/interface/src/avatar/Head.cpp b/interface/src/avatar/Head.cpp index 41d773be52..2e17ad3557 100644 --- a/interface/src/avatar/Head.cpp +++ b/interface/src/avatar/Head.cpp @@ -343,7 +343,13 @@ void Head::render(float alpha, bool isMine) { } if (_renderLookatVectors) { - renderLookatVectors(_leftEyePosition, _rightEyePosition, _lookAtPosition); + glm::vec3 firstEyePosition = _leftEyePosition; + glm::vec3 secondEyePosition = _rightEyePosition; + if (_blendFace.isActive()) { + // the blend face may have custom eye meshes + _blendFace.getEyePositions(firstEyePosition, secondEyePosition); + } + renderLookatVectors(firstEyePosition, secondEyePosition, _lookAtPosition); } }