Apply the neck position.

This commit is contained in:
Andrzej Kapolka 2013-10-21 17:30:26 -07:00
parent b5f2dcfa55
commit 9d89baa506
3 changed files with 38 additions and 7 deletions

View file

@ -22,9 +22,18 @@ void FaceModel::simulate(float deltaTime) {
return;
}
const Skeleton& skeleton = static_cast<Avatar*>(_owningHead->_owningAvatar)->getSkeleton();
setTranslation(skeleton.joint[AVATAR_JOINT_NECK_BASE].position);
setRotation(skeleton.joint[AVATAR_JOINT_NECK_BASE].absoluteRotation);
Avatar* owningAvatar = static_cast<Avatar*>(_owningHead->_owningAvatar);
const Skeleton& skeleton = owningAvatar->getSkeleton();
glm::vec3 neckPosition;
if (!owningAvatar->getSkeletonModel().getNeckPosition(neckPosition)) {
neckPosition = owningAvatar->getSkeleton().joint[AVATAR_JOINT_NECK_BASE].position;
}
setTranslation(neckPosition);
glm::quat neckRotation;
if (true || !owningAvatar->getSkeletonModel().getNeckRotation(neckRotation)) {
neckRotation = owningAvatar->getSkeleton().joint[AVATAR_JOINT_NECK_BASE].absoluteRotation;
}
setRotation(neckRotation);
const float MODEL_SCALE = 0.0006f;
setScale(glm::vec3(-1.0f, 1.0f, -1.0f) * _owningHead->getScale() * MODEL_SCALE);
const glm::vec3 MODEL_TRANSLATION(0.0f, -60.0f, 40.0f); // temporary fudge factor

View file

@ -85,10 +85,6 @@ void Model::simulate(float deltaTime) {
_resetStates = true;
}
// create our root transform
glm::mat4 baseTransform = glm::translate(_translation) * glm::mat4_cast(_rotation) *
glm::scale(_scale) * glm::translate(_offset);
// update the world space transforms for all joints
for (int i = 0; i < _jointStates.size(); i++) {
updateJointState(i);
@ -351,6 +347,14 @@ bool Model::getHeadPosition(glm::vec3& headPosition) const {
return isActive() && getJointPosition(_geometry->getFBXGeometry().headJointIndex, headPosition);
}
bool Model::getNeckPosition(glm::vec3& neckPosition) const {
return isActive() && getJointPosition(_geometry->getFBXGeometry().neckJointIndex, neckPosition);
}
bool Model::getNeckRotation(glm::quat& neckRotation) const {
return isActive() && getJointRotation(_geometry->getFBXGeometry().neckJointIndex, neckRotation);
}
bool Model::getEyePositions(glm::vec3& firstEyePosition, glm::vec3& secondEyePosition) const {
if (!isActive()) {
return false;
@ -404,6 +408,15 @@ bool Model::getJointPosition(int jointIndex, glm::vec3& position) const {
return true;
}
bool Model::getJointRotation(int jointIndex, glm::quat& rotation) const {
if (jointIndex == -1 || _jointStates.isEmpty()) {
return false;
}
const glm::mat4& transform = _jointStates[jointIndex].transform;
rotation = glm::normalize(glm::quat_cast(transform));
return true;
}
void Model::deleteGeometry() {
foreach (GLuint id, _blendedVertexBufferIDs) {
glDeleteBuffers(1, &id);

View file

@ -58,6 +58,14 @@ public:
/// \return whether or not the head was found
bool getHeadPosition(glm::vec3& headPosition) const;
/// Returns the position of the neck joint.
/// \return whether or not the neck was found
bool getNeckPosition(glm::vec3& neckPosition) const;
/// Returns the rotation of the neck joint.
/// \return whether or not the neck was found
bool getNeckRotation(glm::quat& neckRotation) const;
/// Retrieve the positions of up to two eye meshes.
/// \return whether or not both eye meshes were found
bool getEyePositions(glm::vec3& firstEyePosition, glm::vec3& secondEyePosition) const;
@ -88,6 +96,7 @@ protected:
private:
bool getJointPosition(int jointIndex, glm::vec3& position) const;
bool getJointRotation(int jointIndex, glm::quat& rotation) const;
void deleteGeometry();