History

Fix default eye model calculation to be reliable

David Rowe committed 12 years ago

Commit dbf6daf1 parent c0419c62 files · +26 −16Browse files

Showing the changes to interface/src/avatar/SkeletonModel.cpp (1 of 2 files). Show all

Unified · Split

interface/src/avatar/SkeletonModel.cpp+25−15
@@ -36,9 +36,30 @@ SkeletonModel::~SkeletonModel() { · 35 unmodified lines
3636 _ragdoll = NULL;
3737 }
3838
39+const float MODEL_SCALE = 0.0006f;
40+
3941 void SkeletonModel::setJointStates(QVector<JointState> states) {
4042 Model::setJointStates(states);
4143
44+ // Determine the default eye position for avatar scale = 1.0
45+ int headJointIndex = _geometry->getFBXGeometry().headJointIndex;
46+ if (0 <= headJointIndex && headJointIndex < _jointStates.size()) {
47+
48+ glm::vec3 leftEyePosition, rightEyePosition;
49+ getEyeModelPositions(leftEyePosition, rightEyePosition);
50+ glm::vec3 midEyePosition = (leftEyePosition + rightEyePosition) / 2.f;
51+
52+ int rootJointIndex = _geometry->getFBXGeometry().rootJointIndex;
53+ glm::vec3 rootModelPosition;
54+ getJointPosition(rootJointIndex, rootModelPosition);
55+
56+ _defaultEyeModelPosition = midEyePosition - rootModelPosition;
57+ _defaultEyeModelPosition.z = -_defaultEyeModelPosition.z;
58+
59+ // Skeleton may have already been scaled so unscale it
60+ _defaultEyeModelPosition = MODEL_SCALE * _defaultEyeModelPosition / _scale;
61+ }
62+
4263 // the SkeletonModel override of updateJointState() will clear the translation part
4364 // of its root joint and we need that done before we try to build shapes hence we
4465 // recompute all joint transforms at this time.
@@ -59,7 +80,6 @@ void SkeletonModel::simulate(float deltaTime, bool fullUpdate) { · 14 unmodified lines
5980 setTranslation(_owningAvatar->getPosition());
6081 static const glm::quat refOrientation = glm::angleAxis(PI, glm::vec3(0.0f, 1.0f, 0.0f));
6182 setRotation(_owningAvatar->getOrientation() * refOrientation);
62− const float MODEL_SCALE = 0.0006f;
6383 setScale(glm::vec3(1.0f, 1.0f, 1.0f) * _owningAvatar->getScale() * MODEL_SCALE);
6484 setBlendshapeCoefficients(_owningAvatar->getHead()->getBlendshapeCoefficients());
6585
@@ -507,6 +527,10 @@ bool SkeletonModel::getEyePositions(glm::vec3& firstEyePosition, glm::vec3& seco · 441 unmodified lines
507527 return false;
508528 }
509529
530+glm::vec3 SkeletonModel::getDefaultEyeModelPosition() const {
531+ return _owningAvatar->getScale() * _defaultEyeModelPosition;
532+}
533+
510534 void SkeletonModel::renderRagdoll() {
511535 if (!_ragdoll) {
512536 return;
@@ -666,20 +690,6 @@ void SkeletonModel::buildShapes() { · 153 unmodified lines
666690 // This method moves the shapes to their default positions in Model frame.
667691 computeBoundingShape(geometry);
668692
669− int headJointIndex = _geometry->getFBXGeometry().headJointIndex;
670− if (0 <= headJointIndex && headJointIndex < _jointStates.size()) {
671− glm::vec3 leftEyePosition, rightEyePosition;
672− getEyeModelPositions(leftEyePosition, rightEyePosition);
673− glm::vec3 midEyePosition = (leftEyePosition + rightEyePosition) / 2.f;
674−
675− int rootJointIndex = _geometry->getFBXGeometry().rootJointIndex;
676− glm::vec3 rootModelPosition;
677− getJointPosition(rootJointIndex, rootModelPosition);
678−
679− _defaultEyeModelPosition = midEyePosition - rootModelPosition;
680− _defaultEyeModelPosition.z = -_defaultEyeModelPosition.z;
681− }
682−
683693 // While the shapes are in their default position we disable collisions between
684694 // joints that are currently colliding.
685695 disableCurrentSelfCollisions();

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t