mirror of
https://thingvellir.net/git/overte
synced 2025-03-27 23:52:03 +01:00
attempt to make SpatiallyNestable data access thread-safe
This commit is contained in:
parent
e91a8684a4
commit
cf39cac7fc
19 changed files with 187 additions and 153 deletions
|
@ -3329,7 +3329,7 @@ MyAvatar* Application::getMyAvatar() const {
|
|||
return DependencyManager::get<AvatarManager>()->getMyAvatar();
|
||||
}
|
||||
|
||||
const glm::vec3& Application::getAvatarPosition() const {
|
||||
const glm::vec3 Application::getAvatarPosition() const {
|
||||
return getMyAvatar()->getPosition();
|
||||
}
|
||||
|
||||
|
|
|
@ -185,7 +185,7 @@ public:
|
|||
virtual float getSizeScale() const;
|
||||
virtual int getBoundaryLevelAdjust() const;
|
||||
virtual PickRay computePickRay(float x, float y) const;
|
||||
virtual const glm::vec3& getAvatarPosition() const;
|
||||
virtual const glm::vec3 getAvatarPosition() const;
|
||||
virtual void overrideEnvironmentData(const EnvironmentData& newData) { _environment.override(newData); }
|
||||
virtual void endOverrideEnvironmentData() { _environment.endOverride(); }
|
||||
virtual qreal getDevicePixelRatio();
|
||||
|
|
|
@ -1212,12 +1212,12 @@ glm::quat Avatar::getRightPalmRotation() {
|
|||
return rightRotation;
|
||||
}
|
||||
|
||||
void Avatar::setPosition(const glm::vec3& position) {
|
||||
void Avatar::setPosition(const glm::vec3 position) {
|
||||
AvatarData::setPosition(position);
|
||||
updateAttitude();
|
||||
}
|
||||
|
||||
void Avatar::setOrientation(const glm::quat& orientation) {
|
||||
void Avatar::setOrientation(const glm::quat orientation) {
|
||||
AvatarData::setOrientation(orientation);
|
||||
updateAttitude();
|
||||
}
|
||||
|
|
|
@ -161,8 +161,8 @@ public:
|
|||
void setMotionState(AvatarMotionState* motionState) { _motionState = motionState; }
|
||||
AvatarMotionState* getMotionState() { return _motionState; }
|
||||
|
||||
virtual void setPosition(const glm::vec3& position);
|
||||
virtual void setOrientation(const glm::quat& orientation);
|
||||
virtual void setPosition(const glm::vec3 position);
|
||||
virtual void setOrientation(const glm::quat orientation);
|
||||
|
||||
public slots:
|
||||
|
||||
|
|
|
@ -1609,10 +1609,10 @@ void AvatarData::setBodyRoll(float bodyRoll) {
|
|||
setOrientation(glm::quat(glm::radians(eulerAngles)));
|
||||
}
|
||||
|
||||
void AvatarData::setPosition(const glm::vec3& position) {
|
||||
void AvatarData::setPosition(const glm::vec3 position) {
|
||||
SpatiallyNestable::setPosition(position);
|
||||
}
|
||||
|
||||
void AvatarData::setOrientation(const glm::quat& orientation) {
|
||||
void AvatarData::setOrientation(const glm::quat orientation) {
|
||||
SpatiallyNestable::setOrientation(orientation);
|
||||
}
|
||||
|
|
|
@ -201,8 +201,8 @@ public:
|
|||
float getBodyRoll() const;
|
||||
void setBodyRoll(float bodyRoll);
|
||||
|
||||
virtual void setPosition(const glm::vec3& position);
|
||||
virtual void setOrientation(const glm::quat& orientation);
|
||||
virtual void setPosition(const glm::vec3 position);
|
||||
virtual void setOrientation(const glm::quat orientation);
|
||||
|
||||
void nextAttitude(glm::vec3 position, glm::quat orientation); // Can be safely called at any time.
|
||||
void startCapture(); // start/end of the period in which the latest values are about to be captured for camera, etc.
|
||||
|
|
|
@ -44,7 +44,7 @@ RenderableModelEntityItem::~RenderableModelEntityItem() {
|
|||
}
|
||||
}
|
||||
|
||||
void RenderableModelEntityItem::setDimensions(const glm::vec3& value) {
|
||||
void RenderableModelEntityItem::setDimensions(const glm::vec3 value) {
|
||||
_dimensionsInitialized = true;
|
||||
ModelEntityItem::setDimensions(value);
|
||||
}
|
||||
|
|
|
@ -28,7 +28,7 @@ public:
|
|||
|
||||
virtual ~RenderableModelEntityItem();
|
||||
|
||||
virtual void setDimensions(const glm::vec3& value) override;
|
||||
virtual void setDimensions(const glm::vec3 value) override;
|
||||
|
||||
virtual EntityItemProperties getProperties(EntityPropertyFlags desiredProperties = EntityPropertyFlags()) const;
|
||||
virtual bool setProperties(const EntityItemProperties& properties);
|
||||
|
|
|
@ -1188,7 +1188,7 @@ const Transform EntityItem::getTransformToCenter() const {
|
|||
return result;
|
||||
}
|
||||
|
||||
void EntityItem::setDimensions(const glm::vec3& value) {
|
||||
void EntityItem::setDimensions(const glm::vec3 value) {
|
||||
if (value.x <= 0.0f || value.y <= 0.0f || value.z <= 0.0f) {
|
||||
return;
|
||||
}
|
||||
|
@ -1860,44 +1860,44 @@ void EntityItem::parentChanged() {
|
|||
});
|
||||
}
|
||||
|
||||
void EntityItem::setTransform(const Transform& transform) {
|
||||
void EntityItem::setTransform(const Transform transform) {
|
||||
SpatiallyNestable::setTransform(transform);
|
||||
forSelfAndEachChildEntity([&](EntityItemPointer entity) {
|
||||
entity->requiresRecalcBoxes();
|
||||
});
|
||||
entity->requiresRecalcBoxes();
|
||||
});
|
||||
}
|
||||
|
||||
void EntityItem::setLocalTransform(const Transform& transform) {
|
||||
void EntityItem::setLocalTransform(const Transform transform) {
|
||||
SpatiallyNestable::setLocalTransform(transform);
|
||||
forSelfAndEachChildEntity([&](EntityItemPointer entity) {
|
||||
entity->requiresRecalcBoxes();
|
||||
});
|
||||
entity->requiresRecalcBoxes();
|
||||
});
|
||||
}
|
||||
|
||||
void EntityItem::setPosition(const glm::vec3& position) {
|
||||
void EntityItem::setPosition(const glm::vec3 position) {
|
||||
SpatiallyNestable::setPosition(position);
|
||||
forSelfAndEachChildEntity([&](EntityItemPointer entity) {
|
||||
entity->requiresRecalcBoxes();
|
||||
});
|
||||
entity->requiresRecalcBoxes();
|
||||
});
|
||||
}
|
||||
|
||||
void EntityItem::setLocalPosition(const glm::vec3& position) {
|
||||
void EntityItem::setLocalPosition(const glm::vec3 position) {
|
||||
SpatiallyNestable::setLocalPosition(position);
|
||||
forSelfAndEachChildEntity([&](EntityItemPointer entity) {
|
||||
entity->requiresRecalcBoxes();
|
||||
});
|
||||
entity->requiresRecalcBoxes();
|
||||
});
|
||||
}
|
||||
|
||||
void EntityItem::setRotation(const glm::quat& orientation) {
|
||||
void EntityItem::setRotation(const glm::quat orientation) {
|
||||
SpatiallyNestable::setOrientation(orientation);
|
||||
forSelfAndEachChildEntity([&](EntityItemPointer entity) {
|
||||
entity->requiresRecalcBoxes();
|
||||
});
|
||||
entity->requiresRecalcBoxes();
|
||||
});
|
||||
}
|
||||
|
||||
void EntityItem::setLocalRotation(const glm::quat& orientation) {
|
||||
void EntityItem::setLocalRotation(const glm::quat orientation) {
|
||||
SpatiallyNestable::setLocalOrientation(orientation);
|
||||
forSelfAndEachChildEntity([&](EntityItemPointer entity) {
|
||||
entity->requiresRecalcBoxes();
|
||||
});
|
||||
entity->requiresRecalcBoxes();
|
||||
});
|
||||
}
|
||||
|
|
|
@ -196,8 +196,8 @@ public:
|
|||
void setDescription(QString value) { _description = value; }
|
||||
|
||||
/// Dimensions in meters (0.0 - TREE_SCALE)
|
||||
inline const glm::vec3& getDimensions() const { return getScale(); }
|
||||
virtual void setDimensions(const glm::vec3& value);
|
||||
inline const glm::vec3 getDimensions() const { return getScale(); }
|
||||
virtual void setDimensions(const glm::vec3 value);
|
||||
|
||||
float getGlowLevel() const { return _glowLevel; }
|
||||
void setGlowLevel(float glowLevel) { _glowLevel = glowLevel; }
|
||||
|
@ -325,15 +325,15 @@ public:
|
|||
/// return preferred shape type (actual physical shape may differ)
|
||||
virtual ShapeType getShapeType() const { return SHAPE_TYPE_NONE; }
|
||||
|
||||
virtual void setTransform(const Transform& transform);
|
||||
virtual void setLocalTransform(const Transform& transform);
|
||||
// virtual const glm::vec3& getPosition() const { return SpatiallyNestable::getPosition(); }
|
||||
virtual const glm::quat& getRotation() const { return SpatiallyNestable::getOrientation(); }
|
||||
virtual void setTransform(const Transform transform);
|
||||
virtual void setLocalTransform(const Transform transform);
|
||||
// virtual const glm::vec3 getPosition() const { return SpatiallyNestable::getPosition(); }
|
||||
virtual const glm::quat getRotation() const { return SpatiallyNestable::getOrientation(); }
|
||||
|
||||
virtual void setPosition(const glm::vec3& position);
|
||||
virtual void setLocalPosition(const glm::vec3& position);
|
||||
virtual void setRotation(const glm::quat& orientation);
|
||||
virtual void setLocalRotation(const glm::quat& orientation);
|
||||
virtual void setPosition(const glm::vec3 position);
|
||||
virtual void setLocalPosition(const glm::vec3 position);
|
||||
virtual void setRotation(const glm::quat orientation);
|
||||
virtual void setLocalRotation(const glm::quat orientation);
|
||||
|
||||
// updateFoo() methods to be used when changes need to be accumulated in the _dirtyFlags
|
||||
void updatePosition(const glm::vec3& value);
|
||||
|
|
|
@ -40,7 +40,7 @@ LightEntityItem::LightEntityItem(const EntityItemID& entityItemID) : EntityItem(
|
|||
_cutoff = PI;
|
||||
}
|
||||
|
||||
void LightEntityItem::setDimensions(const glm::vec3& value) {
|
||||
void LightEntityItem::setDimensions(const glm::vec3 value) {
|
||||
if (_isSpotlight) {
|
||||
// If we are a spotlight, treat the z value as our radius or length, and
|
||||
// recalculate the x/y dimensions to properly encapsulate the spotlight.
|
||||
|
|
|
@ -23,7 +23,7 @@ public:
|
|||
ALLOW_INSTANTIATION // This class can be instantiated
|
||||
|
||||
/// set dimensions in domain scale units (0.0 - 1.0) this will also reset radius appropriately
|
||||
virtual void setDimensions(const glm::vec3& value);
|
||||
virtual void setDimensions(const glm::vec3 value);
|
||||
|
||||
// methods for getting/setting all properties of an entity
|
||||
virtual EntityItemProperties getProperties(EntityPropertyFlags desiredProperties = EntityPropertyFlags()) const;
|
||||
|
|
|
@ -41,7 +41,7 @@ TextEntityItem::TextEntityItem(const EntityItemID& entityItemID) : EntityItem(en
|
|||
|
||||
const float TEXT_ENTITY_ITEM_FIXED_DEPTH = 0.01f;
|
||||
|
||||
void TextEntityItem::setDimensions(const glm::vec3& value) {
|
||||
void TextEntityItem::setDimensions(const glm::vec3 value) {
|
||||
// NOTE: Text Entities always have a "depth" of 1cm.
|
||||
EntityItem::setDimensions(glm::vec3(value.x, value.y, TEXT_ENTITY_ITEM_FIXED_DEPTH));
|
||||
}
|
||||
|
|
|
@ -23,7 +23,7 @@ public:
|
|||
ALLOW_INSTANTIATION // This class can be instantiated
|
||||
|
||||
/// set dimensions in domain scale units (0.0 - 1.0) this will also reset radius appropriately
|
||||
virtual void setDimensions(const glm::vec3& value);
|
||||
virtual void setDimensions(const glm::vec3 value);
|
||||
virtual ShapeType getShapeType() const { return SHAPE_TYPE_BOX; }
|
||||
|
||||
// methods for getting/setting all properties of an entity
|
||||
|
|
|
@ -34,7 +34,7 @@ WebEntityItem::WebEntityItem(const EntityItemID& entityItemID) : EntityItem(enti
|
|||
|
||||
const float WEB_ENTITY_ITEM_FIXED_DEPTH = 0.01f;
|
||||
|
||||
void WebEntityItem::setDimensions(const glm::vec3& value) {
|
||||
void WebEntityItem::setDimensions(const glm::vec3 value) {
|
||||
// NOTE: Web Entities always have a "depth" of 1cm.
|
||||
EntityItem::setDimensions(glm::vec3(value.x, value.y, WEB_ENTITY_ITEM_FIXED_DEPTH));
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@ public:
|
|||
ALLOW_INSTANTIATION // This class can be instantiated
|
||||
|
||||
/// set dimensions in domain scale units (0.0 - 1.0) this will also reset radius appropriately
|
||||
virtual void setDimensions(const glm::vec3& value);
|
||||
virtual void setDimensions(const glm::vec3 value);
|
||||
virtual ShapeType getShapeType() const { return SHAPE_TYPE_BOX; }
|
||||
|
||||
// methods for getting/setting all properties of an entity
|
||||
|
|
|
@ -45,7 +45,7 @@ public:
|
|||
virtual int getBoundaryLevelAdjust() const = 0;
|
||||
virtual PickRay computePickRay(float x, float y) const = 0;
|
||||
|
||||
virtual const glm::vec3& getAvatarPosition() const = 0;
|
||||
virtual const glm::vec3 getAvatarPosition() const = 0;
|
||||
|
||||
virtual void postLambdaEvent(std::function<void()> f) = 0;
|
||||
virtual qreal getDevicePixelRatio() = 0;
|
||||
|
|
|
@ -87,34 +87,38 @@ void SpatiallyNestable::forgetChild(SpatiallyNestablePointer newChild) const {
|
|||
});
|
||||
}
|
||||
|
||||
void SpatiallyNestable::setParentID(const QUuid& parentID) {
|
||||
void SpatiallyNestable::setParentID(const QUuid parentID) {
|
||||
if (_parentID != parentID) {
|
||||
_parentID = parentID;
|
||||
_parentKnowsMe = false;
|
||||
}
|
||||
}
|
||||
|
||||
glm::vec3 SpatiallyNestable::worldToLocal(const glm::vec3& position) {
|
||||
glm::vec3 SpatiallyNestable::worldToLocal(const glm::vec3 position) {
|
||||
Transform parentTransform = getParentTransform();
|
||||
Transform myWorldTransform;
|
||||
Transform::mult(myWorldTransform, parentTransform, _transform);
|
||||
_transformLock.withReadLock([&] {
|
||||
Transform::mult(myWorldTransform, parentTransform, _transform);
|
||||
});
|
||||
myWorldTransform.setTranslation(position);
|
||||
Transform result;
|
||||
Transform::inverseMult(result, parentTransform, myWorldTransform);
|
||||
return result.getTranslation();
|
||||
}
|
||||
|
||||
glm::quat SpatiallyNestable::worldToLocal(const glm::quat& orientation) {
|
||||
glm::quat SpatiallyNestable::worldToLocal(const glm::quat orientation) {
|
||||
Transform parentTransform = getParentTransform();
|
||||
Transform myWorldTransform;
|
||||
Transform::mult(myWorldTransform, parentTransform, _transform);
|
||||
_transformLock.withReadLock([&] {
|
||||
Transform::mult(myWorldTransform, parentTransform, _transform);
|
||||
});
|
||||
myWorldTransform.setRotation(orientation);
|
||||
Transform result;
|
||||
Transform::inverseMult(result, parentTransform, myWorldTransform);
|
||||
return result.getRotation();
|
||||
}
|
||||
|
||||
glm::vec3 SpatiallyNestable::localToWorld(const glm::vec3& position, QUuid parentID, int parentJointIndex) {
|
||||
glm::vec3 SpatiallyNestable::localToWorld(const glm::vec3 position, QUuid parentID, int parentJointIndex) {
|
||||
QSharedPointer<SpatialParentFinder> parentFinder = DependencyManager::get<SpatialParentFinder>();
|
||||
auto parentWP = parentFinder->find(parentID);
|
||||
auto parent = parentWP.lock();
|
||||
|
@ -130,7 +134,7 @@ glm::vec3 SpatiallyNestable::localToWorld(const glm::vec3& position, QUuid paren
|
|||
return result.getTranslation();
|
||||
}
|
||||
|
||||
glm::quat SpatiallyNestable::localToWorld(const glm::quat& orientation, QUuid parentID, int parentJointIndex) {
|
||||
glm::quat SpatiallyNestable::localToWorld(const glm::quat orientation, QUuid parentID, int parentJointIndex) {
|
||||
QSharedPointer<SpatialParentFinder> parentFinder = DependencyManager::get<SpatialParentFinder>();
|
||||
auto parentWP = parentFinder->find(parentID);
|
||||
auto parent = parentWP.lock();
|
||||
|
@ -147,115 +151,152 @@ glm::quat SpatiallyNestable::localToWorld(const glm::quat& orientation, QUuid pa
|
|||
}
|
||||
|
||||
|
||||
const glm::vec3& SpatiallyNestable::getPosition() const {
|
||||
const glm::vec3 SpatiallyNestable::getPosition() const {
|
||||
Transform parentTransformDescaled = getParentTransform();
|
||||
glm::mat4 parentMat;
|
||||
parentTransformDescaled.getMatrix(parentMat);
|
||||
glm::vec4 absPos = parentMat * glm::vec4(getLocalPosition(), 1.0f);
|
||||
_absolutePositionCache = glm::vec3(absPos);
|
||||
return _absolutePositionCache;
|
||||
return glm::vec3(absPos);
|
||||
}
|
||||
|
||||
const glm::vec3& SpatiallyNestable::getPosition(int jointIndex) const {
|
||||
getTransform(); // update _worldTransformCache
|
||||
getJointTransformInObjectFrame(jointIndex); // update _jointInObjectFrameCache
|
||||
_jointInWorldFrameCache.resize(jointIndex);
|
||||
Transform::mult(_jointInWorldFrameCache[jointIndex], _worldTransformCache, _jointInObjectFrameCache[jointIndex]);
|
||||
return _jointInWorldFrameCache[jointIndex].getTranslation();
|
||||
const glm::vec3 SpatiallyNestable::getPosition(int jointIndex) const {
|
||||
Transform worldTransform = getTransform();
|
||||
Transform jointInObjectFrame = getJointTransformInObjectFrame(jointIndex);
|
||||
Transform jointInWorldFrame;
|
||||
Transform::mult(jointInWorldFrame, worldTransform, jointInObjectFrame);
|
||||
return jointInWorldFrame.getTranslation();
|
||||
}
|
||||
|
||||
void SpatiallyNestable::setPosition(const glm::vec3& position) {
|
||||
void SpatiallyNestable::setPosition(const glm::vec3 position) {
|
||||
Transform parentTransform = getParentTransform();
|
||||
Transform myWorldTransform;
|
||||
Transform::mult(myWorldTransform, parentTransform, _transform);
|
||||
myWorldTransform.setTranslation(position);
|
||||
Transform::inverseMult(_transform, parentTransform, myWorldTransform);
|
||||
_transformLock.withWriteLock([&] {
|
||||
Transform::mult(myWorldTransform, parentTransform, _transform);
|
||||
myWorldTransform.setTranslation(position);
|
||||
Transform::inverseMult(_transform, parentTransform, myWorldTransform);
|
||||
});
|
||||
}
|
||||
|
||||
const glm::quat& SpatiallyNestable::getOrientation() const {
|
||||
const glm::quat SpatiallyNestable::getOrientation() const {
|
||||
Transform parentTransformDescaled = getParentTransform();
|
||||
_absoluteRotationCache = parentTransformDescaled.getRotation() * getLocalOrientation();
|
||||
return _absoluteRotationCache;
|
||||
return parentTransformDescaled.getRotation() * getLocalOrientation();
|
||||
}
|
||||
|
||||
const glm::quat& SpatiallyNestable::getOrientation(int jointIndex) const {
|
||||
getTransform(); // update _worldTransformCache
|
||||
getJointTransformInObjectFrame(jointIndex); // update _jointInObjectFrameCache
|
||||
_jointInWorldFrameCache.resize(jointIndex + 1);
|
||||
Transform::mult(_jointInWorldFrameCache[jointIndex], _worldTransformCache, _jointInObjectFrameCache[jointIndex]);
|
||||
return _jointInWorldFrameCache[jointIndex].getRotation();
|
||||
const glm::quat SpatiallyNestable::getOrientation(int jointIndex) const {
|
||||
Transform worldTransform = getTransform();
|
||||
Transform jointInObjectFrame = getJointTransformInObjectFrame(jointIndex);
|
||||
Transform jointInWorldFrame;
|
||||
Transform::mult(jointInWorldFrame, worldTransform, jointInObjectFrame);
|
||||
return jointInWorldFrame.getRotation();
|
||||
}
|
||||
|
||||
void SpatiallyNestable::setOrientation(const glm::quat& orientation) {
|
||||
void SpatiallyNestable::setOrientation(const glm::quat orientation) {
|
||||
Transform parentTransform = getParentTransform();
|
||||
Transform myWorldTransform;
|
||||
Transform::mult(myWorldTransform, parentTransform, _transform);
|
||||
myWorldTransform.setRotation(orientation);
|
||||
Transform::inverseMult(_transform, parentTransform, myWorldTransform);
|
||||
_transformLock.withWriteLock([&] {
|
||||
Transform::mult(myWorldTransform, parentTransform, _transform);
|
||||
myWorldTransform.setRotation(orientation);
|
||||
Transform::inverseMult(_transform, parentTransform, myWorldTransform);
|
||||
});
|
||||
}
|
||||
|
||||
const Transform& SpatiallyNestable::getTransform() const {
|
||||
const Transform SpatiallyNestable::getTransform() const {
|
||||
Transform parentTransform = getParentTransform();
|
||||
Transform::mult(_worldTransformCache, parentTransform, _transform);
|
||||
return _worldTransformCache;
|
||||
Transform result;
|
||||
_transformLock.withReadLock([&] {
|
||||
Transform::mult(result, parentTransform, _transform);
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
const Transform& SpatiallyNestable::getTransform(int jointIndex) const {
|
||||
getTransform(); // update _worldTransformCache
|
||||
getJointTransformInObjectFrame(jointIndex); // update _jointInObjectFrameCache
|
||||
_jointInWorldFrameCache.resize(jointIndex + 1);
|
||||
Transform::mult(_jointInWorldFrameCache[jointIndex], _worldTransformCache, _jointInObjectFrameCache[jointIndex]);
|
||||
return _jointInWorldFrameCache[jointIndex];
|
||||
const Transform SpatiallyNestable::getTransform(int jointIndex) const {
|
||||
Transform worldTransform = getTransform();
|
||||
Transform jointInObjectFrame = getJointTransformInObjectFrame(jointIndex);
|
||||
Transform jointInWorldFrame;
|
||||
Transform::mult(jointInWorldFrame, worldTransform, jointInObjectFrame);
|
||||
return jointInWorldFrame;
|
||||
}
|
||||
|
||||
void SpatiallyNestable::setTransform(const Transform& transform) {
|
||||
void SpatiallyNestable::setTransform(const Transform transform) {
|
||||
Transform parentTransform = getParentTransform();
|
||||
Transform::inverseMult(_transform, parentTransform, transform);
|
||||
_transformLock.withWriteLock([&] {
|
||||
Transform::inverseMult(_transform, parentTransform, transform);
|
||||
});
|
||||
}
|
||||
|
||||
const glm::vec3& SpatiallyNestable::getScale() const {
|
||||
return _transform.getScale();
|
||||
const glm::vec3 SpatiallyNestable::getScale() const {
|
||||
glm::vec3 result;
|
||||
_transformLock.withReadLock([&] {
|
||||
result = _transform.getScale();
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
const glm::vec3& SpatiallyNestable::getScale(int jointIndex) const {
|
||||
const glm::vec3 SpatiallyNestable::getScale(int jointIndex) const {
|
||||
// XXX ... something with joints
|
||||
return getScale();
|
||||
}
|
||||
|
||||
void SpatiallyNestable::setScale(const glm::vec3& scale) {
|
||||
_transform.setScale(scale);
|
||||
void SpatiallyNestable::setScale(const glm::vec3 scale) {
|
||||
_transformLock.withWriteLock([&] {
|
||||
_transform.setScale(scale);
|
||||
});
|
||||
}
|
||||
|
||||
const Transform& SpatiallyNestable::getLocalTransform() const {
|
||||
return _transform;
|
||||
const Transform SpatiallyNestable::getLocalTransform() const {
|
||||
Transform result;
|
||||
_transformLock.withReadLock([&] {
|
||||
result =_transform;
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
void SpatiallyNestable::setLocalTransform(const Transform& transform) {
|
||||
_transform = transform;
|
||||
void SpatiallyNestable::setLocalTransform(const Transform transform) {
|
||||
_transformLock.withWriteLock([&] {
|
||||
_transform = transform;
|
||||
});
|
||||
}
|
||||
|
||||
const glm::vec3& SpatiallyNestable::getLocalPosition() const {
|
||||
return _transform.getTranslation();
|
||||
const glm::vec3 SpatiallyNestable::getLocalPosition() const {
|
||||
glm::vec3 result;
|
||||
_transformLock.withReadLock([&] {
|
||||
result = _transform.getTranslation();
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
void SpatiallyNestable::setLocalPosition(const glm::vec3& position) {
|
||||
_transform.setTranslation(position);
|
||||
void SpatiallyNestable::setLocalPosition(const glm::vec3 position) {
|
||||
_transformLock.withWriteLock([&] {
|
||||
_transform.setTranslation(position);
|
||||
});
|
||||
}
|
||||
|
||||
const glm::quat& SpatiallyNestable::getLocalOrientation() const {
|
||||
return _transform.getRotation();
|
||||
const glm::quat SpatiallyNestable::getLocalOrientation() const {
|
||||
glm::quat result;
|
||||
_transformLock.withReadLock([&] {
|
||||
result = _transform.getRotation();
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
void SpatiallyNestable::setLocalOrientation(const glm::quat& orientation) {
|
||||
_transform.setRotation(orientation);
|
||||
void SpatiallyNestable::setLocalOrientation(const glm::quat orientation) {
|
||||
_transformLock.withWriteLock([&] {
|
||||
_transform.setRotation(orientation);
|
||||
});
|
||||
}
|
||||
|
||||
const glm::vec3& SpatiallyNestable::getLocalScale() const {
|
||||
return _transform.getScale();
|
||||
const glm::vec3 SpatiallyNestable::getLocalScale() const {
|
||||
glm::vec3 result;
|
||||
_transformLock.withReadLock([&] {
|
||||
result = _transform.getScale();
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
void SpatiallyNestable::setLocalScale(const glm::vec3& scale) {
|
||||
_transform.setScale(scale);
|
||||
void SpatiallyNestable::setLocalScale(const glm::vec3 scale) {
|
||||
_transformLock.withWriteLock([&] {
|
||||
_transform.setScale(scale);
|
||||
});
|
||||
}
|
||||
|
||||
QList<SpatiallyNestablePointer> SpatiallyNestable::getChildren() const {
|
||||
|
@ -272,12 +313,11 @@ QList<SpatiallyNestablePointer> SpatiallyNestable::getChildren() const {
|
|||
}
|
||||
|
||||
|
||||
const Transform& SpatiallyNestable::getJointTransformInObjectFrame(int jointIndex) const {
|
||||
_jointInObjectFrameCache.resize(jointIndex + 1);
|
||||
_jointInObjectFrameCache[jointIndex] = Transform();
|
||||
const Transform SpatiallyNestable::getJointTransformInObjectFrame(int jointIndex) const {
|
||||
Transform jointInObjectFrame;
|
||||
glm::vec3 position = getJointTranslation(jointIndex);
|
||||
glm::quat orientation = getJointRotation(jointIndex);
|
||||
_jointInObjectFrameCache[jointIndex].setRotation(orientation);
|
||||
_jointInObjectFrameCache[jointIndex].setTranslation(position);
|
||||
return _jointInObjectFrameCache[jointIndex];
|
||||
jointInObjectFrame.setRotation(orientation);
|
||||
jointInObjectFrame.setTranslation(position);
|
||||
return jointInObjectFrame;
|
||||
}
|
||||
|
|
|
@ -41,57 +41,57 @@ public:
|
|||
virtual const QUuid& getID() const { return _id; }
|
||||
virtual void setID(const QUuid& id) { _id = id; }
|
||||
|
||||
virtual const QUuid& getParentID() const { return _parentID; }
|
||||
virtual void setParentID(const QUuid& parentID);
|
||||
virtual const QUuid getParentID() const { return _parentID; }
|
||||
virtual void setParentID(const QUuid parentID);
|
||||
|
||||
virtual quint16 getParentJointIndex() const { return _parentJointIndex; }
|
||||
virtual void setParentJointIndex(quint16 parentJointIndex) { _parentJointIndex = parentJointIndex; }
|
||||
|
||||
glm::vec3 worldToLocal(const glm::vec3& position);
|
||||
glm::quat worldToLocal(const glm::quat& orientation);
|
||||
glm::vec3 worldToLocal(const glm::vec3 position);
|
||||
glm::quat worldToLocal(const glm::quat orientation);
|
||||
|
||||
static glm::vec3 localToWorld(const glm::vec3& position, QUuid parentID, int parentJointIndex);
|
||||
static glm::quat localToWorld(const glm::quat& orientation, QUuid parentID, int parentJointIndex);
|
||||
static glm::vec3 localToWorld(const glm::vec3 position, QUuid parentID, int parentJointIndex);
|
||||
static glm::quat localToWorld(const glm::quat orientation, QUuid parentID, int parentJointIndex);
|
||||
|
||||
// world frame
|
||||
virtual const Transform& getTransform() const;
|
||||
virtual void setTransform(const Transform& transform);
|
||||
virtual const Transform getTransform() const;
|
||||
virtual void setTransform(const Transform transform);
|
||||
|
||||
virtual Transform getParentTransform() const;
|
||||
|
||||
virtual const glm::vec3& getPosition() const;
|
||||
virtual void setPosition(const glm::vec3& position);
|
||||
virtual const glm::vec3 getPosition() const;
|
||||
virtual void setPosition(const glm::vec3 position);
|
||||
|
||||
virtual const glm::quat& getOrientation() const;
|
||||
virtual const glm::quat& getOrientation(int jointIndex) const;
|
||||
virtual void setOrientation(const glm::quat& orientation);
|
||||
virtual const glm::quat getOrientation() const;
|
||||
virtual const glm::quat getOrientation(int jointIndex) const;
|
||||
virtual void setOrientation(const glm::quat orientation);
|
||||
|
||||
virtual const glm::vec3& getScale() const;
|
||||
virtual void setScale(const glm::vec3& scale);
|
||||
virtual const glm::vec3 getScale() const;
|
||||
virtual void setScale(const glm::vec3 scale);
|
||||
|
||||
// get world location of a specific joint
|
||||
virtual const Transform& getTransform(int jointIndex) const;
|
||||
virtual const glm::vec3& getPosition(int jointIndex) const;
|
||||
virtual const glm::vec3& getScale(int jointIndex) const;
|
||||
virtual const Transform getTransform(int jointIndex) const;
|
||||
virtual const glm::vec3 getPosition(int jointIndex) const;
|
||||
virtual const glm::vec3 getScale(int jointIndex) const;
|
||||
|
||||
// object's parent's frame
|
||||
virtual const Transform& getLocalTransform() const;
|
||||
virtual void setLocalTransform(const Transform& transform);
|
||||
virtual const Transform getLocalTransform() const;
|
||||
virtual void setLocalTransform(const Transform transform);
|
||||
|
||||
virtual const glm::vec3& getLocalPosition() const;
|
||||
virtual void setLocalPosition(const glm::vec3& position);
|
||||
virtual const glm::vec3 getLocalPosition() const;
|
||||
virtual void setLocalPosition(const glm::vec3 position);
|
||||
|
||||
virtual const glm::quat& getLocalOrientation() const;
|
||||
virtual void setLocalOrientation(const glm::quat& orientation);
|
||||
virtual const glm::quat getLocalOrientation() const;
|
||||
virtual void setLocalOrientation(const glm::quat orientation);
|
||||
|
||||
virtual const glm::vec3& getLocalScale() const;
|
||||
virtual void setLocalScale(const glm::vec3& scale);
|
||||
virtual const glm::vec3 getLocalScale() const;
|
||||
virtual void setLocalScale(const glm::vec3 scale);
|
||||
|
||||
QList<SpatiallyNestablePointer> getChildren() const;
|
||||
NestableTypes::NestableType getNestableType() const { return _nestableType; }
|
||||
|
||||
// this object's frame
|
||||
virtual const Transform& getJointTransformInObjectFrame(int jointIndex) const;
|
||||
virtual const Transform getJointTransformInObjectFrame(int jointIndex) const;
|
||||
virtual glm::quat getJointRotation(int index) const = 0;
|
||||
virtual glm::vec3 getJointTranslation(int index) const = 0;
|
||||
|
||||
|
@ -112,15 +112,9 @@ protected:
|
|||
virtual void parentChanged() {} // called when parent pointer is updated
|
||||
|
||||
private:
|
||||
mutable ReadWriteLockable _transformLock;
|
||||
Transform _transform; // this is to be combined with parent's world-transform to produce this' world-transform.
|
||||
|
||||
// these are so we can return by reference
|
||||
mutable glm::vec3 _absolutePositionCache;
|
||||
mutable glm::quat _absoluteRotationCache;
|
||||
mutable Transform _worldTransformCache;
|
||||
mutable bool _parentKnowsMe = false;
|
||||
mutable QVector<Transform> _jointInObjectFrameCache;
|
||||
mutable QVector<Transform> _jointInWorldFrameCache;
|
||||
};
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue