mirror of
https://github.com/Armored-Dragon/overte.git
synced 2025-03-11 16:13:16 +01:00
working toward making children of avatar joints work
This commit is contained in:
parent
2d804555de
commit
6f79b381f9
4 changed files with 59 additions and 83 deletions
|
@ -1319,9 +1319,6 @@ void EntityItem::updatePosition(const glm::vec3& value) {
|
|||
}
|
||||
if (getLocalPosition() != value) {
|
||||
setLocalPosition(value);
|
||||
forSelfAndEachChildEntity([&](EntityItemPointer entity) {
|
||||
entity->_dirtyFlags |= Simulation::DIRTY_POSITION;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1337,10 +1334,12 @@ void EntityItem::updateRotation(const glm::quat& rotation) {
|
|||
return;
|
||||
}
|
||||
if (getLocalOrientation() != rotation) {
|
||||
setLocalRotation(rotation);
|
||||
forSelfAndEachChildEntity([&](EntityItemPointer entity) {
|
||||
entity->_dirtyFlags |= Simulation::DIRTY_ROTATION;
|
||||
if (this->getID() != entity->getID()) {
|
||||
setLocalOrientation(rotation);
|
||||
_dirtyFlags |= Simulation::DIRTY_ROTATION;
|
||||
forEachDescendant([&](SpatiallyNestablePointer object) {
|
||||
if (object->getNestableType() == NestableTypes::Entity) {
|
||||
EntityItemPointer entity = std::static_pointer_cast<EntityItem>(object);
|
||||
entity->_dirtyFlags |= Simulation::DIRTY_ROTATION;
|
||||
entity->_dirtyFlags |= Simulation::DIRTY_POSITION;
|
||||
}
|
||||
});
|
||||
|
@ -1838,65 +1837,7 @@ QList<EntityActionPointer> EntityItem::getActionsOfType(EntityActionType typeToG
|
|||
return result;
|
||||
}
|
||||
|
||||
void EntityItem::forSelfAndEachChildEntity(std::function<void(EntityItemPointer)> actor) {
|
||||
QQueue<SpatiallyNestablePointer> toProcess;
|
||||
toProcess.enqueue(shared_from_this());
|
||||
|
||||
while (!toProcess.empty()) {
|
||||
EntityItemPointer entity = std::static_pointer_cast<EntityItem>(toProcess.dequeue());
|
||||
actor(entity);
|
||||
foreach (SpatiallyNestablePointer child, entity->getChildren()) {
|
||||
if (child && child->getNestableType() == NestableTypes::Entity) {
|
||||
toProcess.enqueue(child);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void EntityItem::parentChanged() {
|
||||
forSelfAndEachChildEntity([&](EntityItemPointer entity) {
|
||||
entity->requiresRecalcBoxes();
|
||||
});
|
||||
}
|
||||
|
||||
void EntityItem::setTransform(const Transform transform) {
|
||||
SpatiallyNestable::setTransform(transform);
|
||||
forSelfAndEachChildEntity([&](EntityItemPointer entity) {
|
||||
entity->requiresRecalcBoxes();
|
||||
});
|
||||
}
|
||||
|
||||
void EntityItem::setLocalTransform(const Transform transform) {
|
||||
SpatiallyNestable::setLocalTransform(transform);
|
||||
forSelfAndEachChildEntity([&](EntityItemPointer entity) {
|
||||
entity->requiresRecalcBoxes();
|
||||
});
|
||||
}
|
||||
|
||||
void EntityItem::setPosition(const glm::vec3 position) {
|
||||
SpatiallyNestable::setPosition(position);
|
||||
forSelfAndEachChildEntity([&](EntityItemPointer entity) {
|
||||
entity->requiresRecalcBoxes();
|
||||
});
|
||||
}
|
||||
|
||||
void EntityItem::setLocalPosition(const glm::vec3 position) {
|
||||
SpatiallyNestable::setLocalPosition(position);
|
||||
forSelfAndEachChildEntity([&](EntityItemPointer entity) {
|
||||
entity->requiresRecalcBoxes();
|
||||
});
|
||||
}
|
||||
|
||||
void EntityItem::setRotation(const glm::quat orientation) {
|
||||
SpatiallyNestable::setOrientation(orientation);
|
||||
forSelfAndEachChildEntity([&](EntityItemPointer entity) {
|
||||
entity->requiresRecalcBoxes();
|
||||
});
|
||||
}
|
||||
|
||||
void EntityItem::setLocalRotation(const glm::quat orientation) {
|
||||
SpatiallyNestable::setLocalOrientation(orientation);
|
||||
forSelfAndEachChildEntity([&](EntityItemPointer entity) {
|
||||
entity->requiresRecalcBoxes();
|
||||
});
|
||||
void EntityItem::locationChanged() {
|
||||
requiresRecalcBoxes();
|
||||
SpatiallyNestable::locationChanged(); // tell all the children, also
|
||||
}
|
||||
|
|
|
@ -306,15 +306,9 @@ 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 setPosition(glm::vec3 position);
|
||||
virtual void setLocalPosition(glm::vec3 position);
|
||||
virtual void setRotation(glm::quat orientation);
|
||||
virtual void setLocalRotation(glm::quat orientation);
|
||||
// these are only needed because the names don't match
|
||||
virtual const glm::quat getRotation() const { return getOrientation(); }
|
||||
virtual void setRotation(glm::quat orientation) { setOrientation(orientation); }
|
||||
|
||||
// updateFoo() methods to be used when changes need to be accumulated in the _dirtyFlags
|
||||
void updatePosition(const glm::vec3& value);
|
||||
|
@ -393,8 +387,7 @@ protected:
|
|||
const QByteArray getActionDataInternal() const;
|
||||
void setActionDataInternal(QByteArray actionData);
|
||||
|
||||
void forSelfAndEachChildEntity(std::function<void(EntityItemPointer)> actor);
|
||||
virtual void parentChanged();
|
||||
virtual void locationChanged();
|
||||
EntityTypes::EntityType _type;
|
||||
quint64 _lastSimulated; // last time this entity called simulate(), this includes velocity, angular velocity,
|
||||
// and physics changes
|
||||
|
|
|
@ -9,6 +9,8 @@
|
|||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
#include <QQueue>
|
||||
|
||||
#include "DependencyManager.h"
|
||||
#include "SpatiallyNestable.h"
|
||||
|
||||
|
@ -91,6 +93,7 @@ void SpatiallyNestable::setParentID(const QUuid parentID) {
|
|||
_parentID = parentID;
|
||||
_parentKnowsMe = false;
|
||||
}
|
||||
parentChanged();
|
||||
}
|
||||
|
||||
glm::vec3 SpatiallyNestable::worldToLocal(glm::vec3 position, QUuid parentID, int parentJointIndex) {
|
||||
|
@ -182,6 +185,7 @@ void SpatiallyNestable::setPosition(glm::vec3 position) {
|
|||
myWorldTransform.setTranslation(position);
|
||||
Transform::inverseMult(_transform, parentTransform, myWorldTransform);
|
||||
});
|
||||
locationChanged();
|
||||
}
|
||||
|
||||
glm::quat SpatiallyNestable::getOrientation() const {
|
||||
|
@ -200,6 +204,7 @@ void SpatiallyNestable::setOrientation(glm::quat orientation) {
|
|||
myWorldTransform.setRotation(orientation);
|
||||
Transform::inverseMult(_transform, parentTransform, myWorldTransform);
|
||||
});
|
||||
locationChanged();
|
||||
}
|
||||
|
||||
const Transform SpatiallyNestable::getTransform() const {
|
||||
|
@ -227,6 +232,7 @@ void SpatiallyNestable::setTransform(const Transform transform) {
|
|||
_transformLock.withWriteLock([&] {
|
||||
Transform::inverseMult(_transform, parentTransform, transform);
|
||||
});
|
||||
locationChanged();
|
||||
}
|
||||
|
||||
glm::vec3 SpatiallyNestable::getScale() const {
|
||||
|
@ -246,6 +252,7 @@ void SpatiallyNestable::setScale(glm::vec3 scale) {
|
|||
_transformLock.withWriteLock([&] {
|
||||
_transform.setScale(scale);
|
||||
});
|
||||
dimensionsChanged();
|
||||
}
|
||||
|
||||
const Transform SpatiallyNestable::getLocalTransform() const {
|
||||
|
@ -260,6 +267,7 @@ void SpatiallyNestable::setLocalTransform(const Transform transform) {
|
|||
_transformLock.withWriteLock([&] {
|
||||
_transform = transform;
|
||||
});
|
||||
locationChanged();
|
||||
}
|
||||
|
||||
glm::vec3 SpatiallyNestable::getLocalPosition() const {
|
||||
|
@ -274,6 +282,7 @@ void SpatiallyNestable::setLocalPosition(glm::vec3 position) {
|
|||
_transformLock.withWriteLock([&] {
|
||||
_transform.setTranslation(position);
|
||||
});
|
||||
locationChanged();
|
||||
}
|
||||
|
||||
glm::quat SpatiallyNestable::getLocalOrientation() const {
|
||||
|
@ -288,6 +297,7 @@ void SpatiallyNestable::setLocalOrientation(glm::quat orientation) {
|
|||
_transformLock.withWriteLock([&] {
|
||||
_transform.setRotation(orientation);
|
||||
});
|
||||
locationChanged();
|
||||
}
|
||||
|
||||
glm::vec3 SpatiallyNestable::getLocalScale() const {
|
||||
|
@ -302,12 +312,13 @@ void SpatiallyNestable::setLocalScale(glm::vec3 scale) {
|
|||
_transformLock.withWriteLock([&] {
|
||||
_transform.setScale(scale);
|
||||
});
|
||||
dimensionsChanged();
|
||||
}
|
||||
|
||||
QList<SpatiallyNestablePointer> SpatiallyNestable::getChildren() const {
|
||||
QList<SpatiallyNestablePointer> children;
|
||||
_childrenLock.withReadLock([&] {
|
||||
foreach (SpatiallyNestableWeakPointer childWP, _children.values()) {
|
||||
foreach(SpatiallyNestableWeakPointer childWP, _children.values()) {
|
||||
SpatiallyNestablePointer child = childWP.lock();
|
||||
if (child) {
|
||||
children << child;
|
||||
|
@ -317,7 +328,6 @@ QList<SpatiallyNestablePointer> SpatiallyNestable::getChildren() const {
|
|||
return children;
|
||||
}
|
||||
|
||||
|
||||
const Transform SpatiallyNestable::getJointTransformInObjectFrame(int jointIndex) const {
|
||||
Transform jointInObjectFrame;
|
||||
glm::vec3 position = getJointTranslation(jointIndex);
|
||||
|
@ -332,3 +342,30 @@ SpatiallyNestablePointer SpatiallyNestable::getThisPointer() const {
|
|||
SpatiallyNestablePointer thisPointer = std::const_pointer_cast<SpatiallyNestable>(constThisPointer); // ermahgerd !!!
|
||||
return thisPointer;
|
||||
}
|
||||
|
||||
void SpatiallyNestable::forEachChild(std::function<void(SpatiallyNestablePointer)> actor) {
|
||||
foreach(SpatiallyNestablePointer child, getChildren()) {
|
||||
actor(child);
|
||||
}
|
||||
}
|
||||
|
||||
void SpatiallyNestable::forEachDescendant(std::function<void(SpatiallyNestablePointer)> actor) {
|
||||
QQueue<SpatiallyNestablePointer> toProcess;
|
||||
foreach(SpatiallyNestablePointer child, getChildren()) {
|
||||
toProcess.enqueue(child);
|
||||
}
|
||||
|
||||
while (!toProcess.empty()) {
|
||||
SpatiallyNestablePointer object = toProcess.dequeue();
|
||||
actor(object);
|
||||
foreach (SpatiallyNestablePointer child, object->getChildren()) {
|
||||
toProcess.enqueue(child);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void SpatiallyNestable::locationChanged() {
|
||||
forEachChild([&](SpatiallyNestablePointer object) {
|
||||
object->locationChanged();
|
||||
});
|
||||
}
|
||||
|
|
|
@ -92,8 +92,8 @@ public:
|
|||
|
||||
// this object's frame
|
||||
virtual const Transform getJointTransformInObjectFrame(int jointIndex) const;
|
||||
virtual glm::quat getJointRotation(int index) const = 0;
|
||||
virtual glm::vec3 getJointTranslation(int index) const = 0;
|
||||
virtual glm::quat getJointRotation(int index) const { assert(false); }
|
||||
virtual glm::vec3 getJointTranslation(int index) const { assert(false); }
|
||||
|
||||
SpatiallyNestablePointer getThisPointer() const;
|
||||
|
||||
|
@ -112,6 +112,11 @@ protected:
|
|||
mutable QHash<QUuid, SpatiallyNestableWeakPointer> _children;
|
||||
|
||||
virtual void parentChanged() {} // called when parent pointer is updated
|
||||
virtual void locationChanged(); // called when a this object's location has changed
|
||||
virtual void dimensionsChanged() {} // called when a this object's dimensions have changed
|
||||
|
||||
void forEachChild(std::function<void(SpatiallyNestablePointer)> actor);
|
||||
void forEachDescendant(std::function<void(SpatiallyNestablePointer)> actor);
|
||||
|
||||
private:
|
||||
mutable ReadWriteLockable _transformLock;
|
||||
|
|
Loading…
Reference in a new issue