diff --git a/libraries/shared/src/SpatiallyNestable.cpp b/libraries/shared/src/SpatiallyNestable.cpp index 9b2e809063..688ed831e3 100644 --- a/libraries/shared/src/SpatiallyNestable.cpp +++ b/libraries/shared/src/SpatiallyNestable.cpp @@ -40,18 +40,17 @@ SpatiallyNestablePointer SpatiallyNestable::getParentPointer() const { return nullptr; } - SpatiallyNestableConstPointer constThisPointer = shared_from_this(); - SpatiallyNestablePointer thisPointer = std::const_pointer_cast(constThisPointer); // ermahgerd !!! - if (parent && parent->getID() == _parentID) { // parent pointer is up-to-date if (!_parentKnowsMe) { - parent->beParentOfChild(thisPointer); + parent->beParentOfChild(getThisPointer()); _parentKnowsMe = true; } return parent; } + SpatiallyNestablePointer thisPointer = getThisPointer(); + if (parent) { // we have a parent pointer but our _parentID doesn't indicate this parent. parent->forgetChild(thisPointer); @@ -167,21 +166,12 @@ glm::quat SpatiallyNestable::localToWorld(glm::quat orientation, QUuid parentID, return result.getRotation(); } - glm::vec3 SpatiallyNestable::getPosition() const { - Transform parentTransformDescaled = getParentTransform(); - glm::mat4 parentMat; - parentTransformDescaled.getMatrix(parentMat); - glm::vec4 absPos = parentMat * glm::vec4(getLocalPosition(), 1.0f); - return glm::vec3(absPos); + return getTransform().getTranslation(); } glm::vec3 SpatiallyNestable::getPosition(int jointIndex) const { - Transform worldTransform = getTransform(); - Transform jointInObjectFrame = getJointTransformInObjectFrame(jointIndex); - Transform jointInWorldFrame; - Transform::mult(jointInWorldFrame, worldTransform, jointInObjectFrame); - return jointInWorldFrame.getTranslation(); + return getTransform(jointIndex).getTranslation(); } void SpatiallyNestable::setPosition(glm::vec3 position) { @@ -195,16 +185,11 @@ void SpatiallyNestable::setPosition(glm::vec3 position) { } glm::quat SpatiallyNestable::getOrientation() const { - Transform parentTransformDescaled = getParentTransform(); - return parentTransformDescaled.getRotation() * getLocalOrientation(); + return getTransform().getRotation(); } glm::quat SpatiallyNestable::getOrientation(int jointIndex) const { - Transform worldTransform = getTransform(); - Transform jointInObjectFrame = getJointTransformInObjectFrame(jointIndex); - Transform jointInWorldFrame; - Transform::mult(jointInWorldFrame, worldTransform, jointInObjectFrame); - return jointInWorldFrame.getRotation(); + return getTransform(jointIndex).getRotation(); } void SpatiallyNestable::setOrientation(glm::quat orientation) { @@ -228,7 +213,7 @@ const Transform SpatiallyNestable::getTransform() const { } const Transform SpatiallyNestable::getTransform(int jointIndex) const { - // this returns the world-space transform for this object. It find its parent's transform (which may + // this returns the world-space transform for this object. It finds its parent's transform (which may // cause this object's parent to query its parent, etc) and multiplies this object's local transform onto it. Transform worldTransform = getTransform(); Transform jointInObjectFrame = getJointTransformInObjectFrame(jointIndex); @@ -341,3 +326,9 @@ const Transform SpatiallyNestable::getJointTransformInObjectFrame(int jointIndex jointInObjectFrame.setTranslation(position); return jointInObjectFrame; } + +SpatiallyNestablePointer SpatiallyNestable::getThisPointer() const { + SpatiallyNestableConstPointer constThisPointer = shared_from_this(); + SpatiallyNestablePointer thisPointer = std::const_pointer_cast(constThisPointer); // ermahgerd !!! + return thisPointer; +} diff --git a/libraries/shared/src/SpatiallyNestable.h b/libraries/shared/src/SpatiallyNestable.h index 6e0afa24a5..b7c04e8563 100644 --- a/libraries/shared/src/SpatiallyNestable.h +++ b/libraries/shared/src/SpatiallyNestable.h @@ -95,6 +95,8 @@ public: virtual glm::quat getJointRotation(int index) const = 0; virtual glm::vec3 getJointTranslation(int index) const = 0; + SpatiallyNestablePointer getThisPointer() const; + protected: NestableTypes::NestableType _nestableType; // EntityItem or an AvatarData QUuid _id;