mirror of
https://github.com/overte-org/overte.git
synced 2025-08-07 14:30:35 +02:00
fix non-physical kinematic motion
also can set objects collisionless again
This commit is contained in:
parent
47f978b86e
commit
f0618501dd
4 changed files with 51 additions and 44 deletions
|
@ -256,6 +256,8 @@ public:
|
|||
bool getCollisionsWillMove() const { return _collisionsWillMove; }
|
||||
void setCollisionsWillMove(bool value) { _collisionsWillMove = value; }
|
||||
|
||||
virtual bool shouldBePhysical() const { return !_ignoreForCollisions; }
|
||||
|
||||
bool getLocked() const { return _locked; }
|
||||
void setLocked(bool value) { _locked = value; }
|
||||
|
||||
|
|
|
@ -442,3 +442,8 @@ QString ModelEntityItem::getAnimationSettings() const {
|
|||
QString jsonByteString(jsonByteArray);
|
||||
return jsonByteString;
|
||||
}
|
||||
|
||||
// virtual
|
||||
bool ModelEntityItem::shouldBePhysical() const {
|
||||
return EntityItem::shouldBePhysical() && getShapeType() != SHAPE_TYPE_NONE;
|
||||
}
|
||||
|
|
|
@ -118,6 +118,8 @@ public:
|
|||
const QString& getTextures() const { return _textures; }
|
||||
void setTextures(const QString& textures) { _textures = textures; }
|
||||
|
||||
virtual bool shouldBePhysical() const;
|
||||
|
||||
static void cleanupLoadedAnimations();
|
||||
|
||||
protected:
|
||||
|
|
|
@ -47,18 +47,13 @@ void PhysicalEntitySimulation::updateEntitiesInternal(const quint64& now) {
|
|||
|
||||
void PhysicalEntitySimulation::addEntityInternal(EntityItem* entity) {
|
||||
assert(entity);
|
||||
if (entity->getIgnoreForCollisions() && entity->isMoving()) {
|
||||
_simpleKinematicEntities.insert(entity);
|
||||
} else {
|
||||
if (entity->shouldBePhysical()) {
|
||||
EntityMotionState* motionState = static_cast<EntityMotionState*>(entity->getPhysicsInfo());
|
||||
if (!motionState) {
|
||||
_pendingAdds.insert(entity);
|
||||
} else {
|
||||
// DEBUG -- Andrew to remove this after testing
|
||||
// Adding entity already in simulation? assert that this is case,
|
||||
// since otherwise we probably have an orphaned EntityMotionState.
|
||||
assert(_physicalObjects.find(motionState) != _physicalObjects.end());
|
||||
}
|
||||
} else if (entity->isMoving()) {
|
||||
_simpleKinematicEntities.insert(entity);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -83,7 +78,7 @@ void PhysicalEntitySimulation::changeEntityInternal(EntityItem* entity) {
|
|||
assert(entity);
|
||||
EntityMotionState* motionState = static_cast<EntityMotionState*>(entity->getPhysicsInfo());
|
||||
if (motionState) {
|
||||
if (entity->getIgnoreForCollisions()) {
|
||||
if (!entity->shouldBePhysical()) {
|
||||
// the entity should be removed from the physical simulation
|
||||
_pendingChanges.remove(motionState);
|
||||
_physicalObjects.remove(motionState);
|
||||
|
@ -95,8 +90,8 @@ void PhysicalEntitySimulation::changeEntityInternal(EntityItem* entity) {
|
|||
} else {
|
||||
_pendingChanges.insert(motionState);
|
||||
}
|
||||
} else if (!entity->getIgnoreForCollisions()) {
|
||||
// The intent is for this object to be in the PhysicsEngine.
|
||||
} else if (entity->shouldBePhysical()) {
|
||||
// The intent is for this object to be in the PhysicsEngine, but it has no MotionState yet.
|
||||
// Perhaps it's shape has changed and it can now be added?
|
||||
_pendingAdds.insert(entity);
|
||||
_simpleKinematicEntities.remove(entity); // just in case it's non-physical-kinematic
|
||||
|
@ -159,9 +154,12 @@ VectorOfMotionStates& PhysicalEntitySimulation::getObjectsToAdd() {
|
|||
while (entityItr != _pendingAdds.end()) {
|
||||
EntityItem* entity = *entityItr;
|
||||
assert(!entity->getPhysicsInfo());
|
||||
if (entity->getShapeType() == SHAPE_TYPE_NONE || entity->getIgnoreForCollisions()) {
|
||||
if (!entity->shouldBePhysical()) {
|
||||
// this entity should no longer be on the internal _pendingAdds
|
||||
entityItr = _pendingAdds.erase(entityItr);
|
||||
if (entity->isMoving()) {
|
||||
_simpleKinematicEntities.insert(entity);
|
||||
}
|
||||
} else if (entity->isReadyToComputeShape()) {
|
||||
ShapeInfo shapeInfo;
|
||||
entity->computeShapeInfo(shapeInfo);
|
||||
|
|
Loading…
Reference in a new issue