From 8bc92144453e486b614662daea5df829aa8cf416 Mon Sep 17 00:00:00 2001 From: barnold1953 Date: Thu, 10 Jul 2014 14:37:04 -0700 Subject: [PATCH] Added helper scaling function to Avatar. --- interface/src/avatar/Avatar.cpp | 5 +++++ interface/src/avatar/Avatar.h | 4 ++++ interface/src/avatar/Hand.cpp | 4 ++-- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/interface/src/avatar/Avatar.cpp b/interface/src/avatar/Avatar.cpp index 3221e75e56..2ebbd55c85 100644 --- a/interface/src/avatar/Avatar.cpp +++ b/interface/src/avatar/Avatar.cpp @@ -970,6 +970,11 @@ glm::quat Avatar::getJointCombinedRotation(const QString& name) const { return rotation; } +void Avatar::scaleVectorRelativeToPosition(glm::vec3 &positionToScale) const { + //Scale a world space vector as if it was relative to the position + positionToScale = _position + _scale * (positionToScale - _position); +} + void Avatar::setFaceModelURL(const QUrl& faceModelURL) { AvatarData::setFaceModelURL(faceModelURL); const QUrl DEFAULT_FACE_MODEL_URL = QUrl::fromLocalFile(Application::resourcesPath() + "meshes/defaultAvatar_head.fst"); diff --git a/interface/src/avatar/Avatar.h b/interface/src/avatar/Avatar.h index 8c14fc9ed0..6fb7991c3c 100755 --- a/interface/src/avatar/Avatar.h +++ b/interface/src/avatar/Avatar.h @@ -152,6 +152,10 @@ public: glm::vec3 getAcceleration() const { return _acceleration; } glm::vec3 getAngularVelocity() const { return _angularVelocity; } + + /// Scales a world space position vector relative to the avatar position and scale + /// \param vector position to be scaled. Will store the result + void scaleVectorRelativeToPosition(glm::vec3 &positionToScale) const; public slots: void updateCollisionGroups(); diff --git a/interface/src/avatar/Hand.cpp b/interface/src/avatar/Hand.cpp index aae9cb0a29..08e1cf83df 100644 --- a/interface/src/avatar/Hand.cpp +++ b/interface/src/avatar/Hand.cpp @@ -170,8 +170,8 @@ void Hand::renderHandTargets(bool isMine) { glm::vec3 root = palm.getPosition(); //Scale the positions based on avatar scale - tip = myAvatar->getPosition() + avatarScale * (tip - myAvatar->getPosition()); - root = myAvatar->getPosition() + avatarScale * (root - myAvatar->getPosition()); + myAvatar->scaleVectorRelativeToPosition(tip); + myAvatar->scaleVectorRelativeToPosition(root); Avatar::renderJointConnectingCone(root, tip, PALM_FINGER_ROD_RADIUS, PALM_FINGER_ROD_RADIUS); // Render sphere at palm/finger root