mirror of
https://github.com/lubosz/overte.git
synced 2025-08-07 19:41:20 +02:00
add EntityItem::set/getTransformAndVelocities()
This commit is contained in:
parent
771727890c
commit
905c5398c4
2 changed files with 47 additions and 10 deletions
|
@ -90,11 +90,9 @@ SpatiallyNestablePointer SpatiallyNestable::getParentPointer(bool& success) cons
|
||||||
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(getThisPointer());
|
||||||
_parentKnowsMe = false;
|
_parentKnowsMe = false;
|
||||||
_parent.reset();
|
_parent.reset();
|
||||||
}
|
}
|
||||||
|
@ -112,16 +110,11 @@ SpatiallyNestablePointer SpatiallyNestable::getParentPointer(bool& success) cons
|
||||||
|
|
||||||
parent = _parent.lock();
|
parent = _parent.lock();
|
||||||
if (parent) {
|
if (parent) {
|
||||||
parent->beParentOfChild(thisPointer);
|
parent->beParentOfChild(getThisPointer());
|
||||||
_parentKnowsMe = true;
|
_parentKnowsMe = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (parent || parentID.isNull()) {
|
success = (parent || parentID.isNull());
|
||||||
success = true;
|
|
||||||
} else {
|
|
||||||
success = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return parent;
|
return parent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -873,3 +866,40 @@ bool SpatiallyNestable::hasAncestorOfType(NestableType nestableType) {
|
||||||
|
|
||||||
return parent->hasAncestorOfType(nestableType);
|
return parent->hasAncestorOfType(nestableType);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SpatiallyNestable::getLocalTransformAndVelocities(
|
||||||
|
Transform& transform,
|
||||||
|
glm::vec3& velocity,
|
||||||
|
glm::vec3& angularVelocity) const {
|
||||||
|
// transform
|
||||||
|
_transformLock.withReadLock([&] {
|
||||||
|
transform = _transform;
|
||||||
|
});
|
||||||
|
// linear velocity
|
||||||
|
_velocityLock.withReadLock([&] {
|
||||||
|
velocity = _velocity;
|
||||||
|
});
|
||||||
|
// angular velocity
|
||||||
|
_angularVelocityLock.withReadLock([&] {
|
||||||
|
angularVelocity = _angularVelocity;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
void SpatiallyNestable::setLocalTransformAndVelocities(
|
||||||
|
const Transform& localTransform,
|
||||||
|
const glm::vec3& localVelocity,
|
||||||
|
const glm::vec3& localAngularVelocity) {
|
||||||
|
// transform
|
||||||
|
_transformLock.withWriteLock([&] {
|
||||||
|
_transform = localTransform;
|
||||||
|
});
|
||||||
|
// linear velocity
|
||||||
|
_velocityLock.withWriteLock([&] {
|
||||||
|
_velocity = localVelocity;
|
||||||
|
});
|
||||||
|
// angular velocity
|
||||||
|
_angularVelocityLock.withWriteLock([&] {
|
||||||
|
_angularVelocity = localAngularVelocity;
|
||||||
|
});
|
||||||
|
locationChanged();
|
||||||
|
}
|
||||||
|
|
|
@ -151,6 +151,13 @@ protected:
|
||||||
quint16 _parentJointIndex { 0 }; // which joint of the parent is this relative to?
|
quint16 _parentJointIndex { 0 }; // which joint of the parent is this relative to?
|
||||||
SpatiallyNestablePointer getParentPointer(bool& success) const;
|
SpatiallyNestablePointer getParentPointer(bool& success) const;
|
||||||
|
|
||||||
|
void getLocalTransformAndVelocities(Transform& localTransform, glm::vec3& localVelocity, glm::vec3& localAngularVelocity) const;
|
||||||
|
|
||||||
|
void setLocalTransformAndVelocities(
|
||||||
|
const Transform& localTransform,
|
||||||
|
const glm::vec3& localVelocity,
|
||||||
|
const glm::vec3& localAngularVelocity);
|
||||||
|
|
||||||
mutable SpatiallyNestableWeakPointer _parent;
|
mutable SpatiallyNestableWeakPointer _parent;
|
||||||
|
|
||||||
virtual void beParentOfChild(SpatiallyNestablePointer newChild) const;
|
virtual void beParentOfChild(SpatiallyNestablePointer newChild) const;
|
||||||
|
|
Loading…
Reference in a new issue