mirror of
https://github.com/overte-org/overte.git
synced 2025-07-14 21:36:37 +02:00
minor cleanups
This commit is contained in:
parent
6eae98fb28
commit
2d804555de
2 changed files with 16 additions and 23 deletions
|
@ -40,18 +40,17 @@ SpatiallyNestablePointer SpatiallyNestable::getParentPointer() const {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
SpatiallyNestableConstPointer constThisPointer = shared_from_this();
|
|
||||||
SpatiallyNestablePointer thisPointer = std::const_pointer_cast<SpatiallyNestable>(constThisPointer); // ermahgerd !!!
|
|
||||||
|
|
||||||
if (parent && parent->getID() == _parentID) {
|
if (parent && parent->getID() == _parentID) {
|
||||||
// parent pointer is up-to-date
|
// parent pointer is up-to-date
|
||||||
if (!_parentKnowsMe) {
|
if (!_parentKnowsMe) {
|
||||||
parent->beParentOfChild(thisPointer);
|
parent->beParentOfChild(getThisPointer());
|
||||||
_parentKnowsMe = true;
|
_parentKnowsMe = true;
|
||||||
}
|
}
|
||||||
return parent;
|
return parent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SpatiallyNestablePointer thisPointer = getThisPointer();
|
||||||
|
|
||||||
if (parent) {
|
if (parent) {
|
||||||
// we have a parent pointer but our _parentID doesn't indicate this parent.
|
// we have a parent pointer but our _parentID doesn't indicate this parent.
|
||||||
parent->forgetChild(thisPointer);
|
parent->forgetChild(thisPointer);
|
||||||
|
@ -167,21 +166,12 @@ glm::quat SpatiallyNestable::localToWorld(glm::quat orientation, QUuid parentID,
|
||||||
return result.getRotation();
|
return result.getRotation();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
glm::vec3 SpatiallyNestable::getPosition() const {
|
glm::vec3 SpatiallyNestable::getPosition() const {
|
||||||
Transform parentTransformDescaled = getParentTransform();
|
return getTransform().getTranslation();
|
||||||
glm::mat4 parentMat;
|
|
||||||
parentTransformDescaled.getMatrix(parentMat);
|
|
||||||
glm::vec4 absPos = parentMat * glm::vec4(getLocalPosition(), 1.0f);
|
|
||||||
return glm::vec3(absPos);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
glm::vec3 SpatiallyNestable::getPosition(int jointIndex) const {
|
glm::vec3 SpatiallyNestable::getPosition(int jointIndex) const {
|
||||||
Transform worldTransform = getTransform();
|
return getTransform(jointIndex).getTranslation();
|
||||||
Transform jointInObjectFrame = getJointTransformInObjectFrame(jointIndex);
|
|
||||||
Transform jointInWorldFrame;
|
|
||||||
Transform::mult(jointInWorldFrame, worldTransform, jointInObjectFrame);
|
|
||||||
return jointInWorldFrame.getTranslation();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SpatiallyNestable::setPosition(glm::vec3 position) {
|
void SpatiallyNestable::setPosition(glm::vec3 position) {
|
||||||
|
@ -195,16 +185,11 @@ void SpatiallyNestable::setPosition(glm::vec3 position) {
|
||||||
}
|
}
|
||||||
|
|
||||||
glm::quat SpatiallyNestable::getOrientation() const {
|
glm::quat SpatiallyNestable::getOrientation() const {
|
||||||
Transform parentTransformDescaled = getParentTransform();
|
return getTransform().getRotation();
|
||||||
return parentTransformDescaled.getRotation() * getLocalOrientation();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
glm::quat SpatiallyNestable::getOrientation(int jointIndex) const {
|
glm::quat SpatiallyNestable::getOrientation(int jointIndex) const {
|
||||||
Transform worldTransform = getTransform();
|
return getTransform(jointIndex).getRotation();
|
||||||
Transform jointInObjectFrame = getJointTransformInObjectFrame(jointIndex);
|
|
||||||
Transform jointInWorldFrame;
|
|
||||||
Transform::mult(jointInWorldFrame, worldTransform, jointInObjectFrame);
|
|
||||||
return jointInWorldFrame.getRotation();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SpatiallyNestable::setOrientation(glm::quat orientation) {
|
void SpatiallyNestable::setOrientation(glm::quat orientation) {
|
||||||
|
@ -228,7 +213,7 @@ const Transform SpatiallyNestable::getTransform() const {
|
||||||
}
|
}
|
||||||
|
|
||||||
const Transform SpatiallyNestable::getTransform(int jointIndex) 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.
|
// cause this object's parent to query its parent, etc) and multiplies this object's local transform onto it.
|
||||||
Transform worldTransform = getTransform();
|
Transform worldTransform = getTransform();
|
||||||
Transform jointInObjectFrame = getJointTransformInObjectFrame(jointIndex);
|
Transform jointInObjectFrame = getJointTransformInObjectFrame(jointIndex);
|
||||||
|
@ -341,3 +326,9 @@ const Transform SpatiallyNestable::getJointTransformInObjectFrame(int jointIndex
|
||||||
jointInObjectFrame.setTranslation(position);
|
jointInObjectFrame.setTranslation(position);
|
||||||
return jointInObjectFrame;
|
return jointInObjectFrame;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SpatiallyNestablePointer SpatiallyNestable::getThisPointer() const {
|
||||||
|
SpatiallyNestableConstPointer constThisPointer = shared_from_this();
|
||||||
|
SpatiallyNestablePointer thisPointer = std::const_pointer_cast<SpatiallyNestable>(constThisPointer); // ermahgerd !!!
|
||||||
|
return thisPointer;
|
||||||
|
}
|
||||||
|
|
|
@ -95,6 +95,8 @@ public:
|
||||||
virtual glm::quat getJointRotation(int index) const = 0;
|
virtual glm::quat getJointRotation(int index) const = 0;
|
||||||
virtual glm::vec3 getJointTranslation(int index) const = 0;
|
virtual glm::vec3 getJointTranslation(int index) const = 0;
|
||||||
|
|
||||||
|
SpatiallyNestablePointer getThisPointer() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
NestableTypes::NestableType _nestableType; // EntityItem or an AvatarData
|
NestableTypes::NestableType _nestableType; // EntityItem or an AvatarData
|
||||||
QUuid _id;
|
QUuid _id;
|
||||||
|
|
Loading…
Reference in a new issue