mirror of
https://github.com/lubosz/overte.git
synced 2025-08-08 02:48:12 +02:00
Merge pull request #13525 from AndrewMeadows/slow-kinematics
fix for erroneous deactivation of slow-spinning kinematic objects
This commit is contained in:
commit
8f838397a4
6 changed files with 27 additions and 4 deletions
|
@ -100,7 +100,7 @@ void SimpleEntitySimulation::changeEntityInternal(EntityItemPointer entity) {
|
||||||
}
|
}
|
||||||
} else if (entity->isMovingRelativeToParent()) {
|
} else if (entity->isMovingRelativeToParent()) {
|
||||||
SetOfEntities::iterator itr = _simpleKinematicEntities.find(entity);
|
SetOfEntities::iterator itr = _simpleKinematicEntities.find(entity);
|
||||||
if (itr != _simpleKinematicEntities.end()) {
|
if (itr == _simpleKinematicEntities.end()) {
|
||||||
_simpleKinematicEntities.insert(entity);
|
_simpleKinematicEntities.insert(entity);
|
||||||
entity->setLastSimulated(usecTimestampNow());
|
entity->setLastSimulated(usecTimestampNow());
|
||||||
}
|
}
|
||||||
|
@ -118,7 +118,7 @@ void SimpleEntitySimulation::changeEntityInternal(EntityItemPointer entity) {
|
||||||
|
|
||||||
if (entity->isMovingRelativeToParent()) {
|
if (entity->isMovingRelativeToParent()) {
|
||||||
SetOfEntities::iterator itr = _simpleKinematicEntities.find(entity);
|
SetOfEntities::iterator itr = _simpleKinematicEntities.find(entity);
|
||||||
if (itr != _simpleKinematicEntities.end()) {
|
if (itr == _simpleKinematicEntities.end()) {
|
||||||
_simpleKinematicEntities.insert(entity);
|
_simpleKinematicEntities.insert(entity);
|
||||||
entity->setLastSimulated(usecTimestampNow());
|
entity->setLastSimulated(usecTimestampNow());
|
||||||
}
|
}
|
||||||
|
|
|
@ -834,3 +834,14 @@ void EntityMotionState::clearObjectVelocities() const {
|
||||||
}
|
}
|
||||||
_entity->setAcceleration(glm::vec3(0.0f));
|
_entity->setAcceleration(glm::vec3(0.0f));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void EntityMotionState::saveKinematicState(btScalar timeStep) {
|
||||||
|
_body->saveKinematicState(timeStep);
|
||||||
|
|
||||||
|
// This is a WORKAROUND for a quirk in Bullet: due to floating point error slow spinning kinematic objects will
|
||||||
|
// have a measured angular velocity of zero. This probably isn't a bug that the Bullet team is interested in
|
||||||
|
// fixing since there is one very simple workaround: use double-precision math for the physics simulation.
|
||||||
|
// We're not ready migrate to double-precision yet so we explicitly work around it by slamming the RigidBody's
|
||||||
|
// angular velocity with the value in the entity.
|
||||||
|
_body->setAngularVelocity(glmToBullet(_entity->getWorldAngularVelocity()));
|
||||||
|
}
|
||||||
|
|
|
@ -97,6 +97,7 @@ public:
|
||||||
OwnershipState getOwnershipState() const { return _ownershipState; }
|
OwnershipState getOwnershipState() const { return _ownershipState; }
|
||||||
|
|
||||||
void setRegion(uint8_t region);
|
void setRegion(uint8_t region);
|
||||||
|
void saveKinematicState(btScalar timeStep) override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void updateSendVelocities();
|
void updateSendVelocities();
|
||||||
|
|
|
@ -347,7 +347,7 @@ void ObjectMotionState::updateLastKinematicStep() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void ObjectMotionState::updateBodyMassProperties() {
|
void ObjectMotionState::updateBodyMassProperties() {
|
||||||
float mass = getMass();
|
btScalar mass = getMass();
|
||||||
btVector3 inertia(1.0f, 1.0f, 1.0f);
|
btVector3 inertia(1.0f, 1.0f, 1.0f);
|
||||||
if (mass > 0.0f) {
|
if (mass > 0.0f) {
|
||||||
_body->getCollisionShape()->calculateLocalInertia(mass, inertia);
|
_body->getCollisionShape()->calculateLocalInertia(mass, inertia);
|
||||||
|
@ -356,3 +356,7 @@ void ObjectMotionState::updateBodyMassProperties() {
|
||||||
_body->updateInertiaTensor();
|
_body->updateInertiaTensor();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ObjectMotionState::saveKinematicState(btScalar timeStep) {
|
||||||
|
_body->saveKinematicState(timeStep);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -165,6 +165,7 @@ public:
|
||||||
|
|
||||||
virtual bool isLocallyOwned() const { return false; }
|
virtual bool isLocallyOwned() const { return false; }
|
||||||
virtual bool isLocallyOwnedOrShouldBe() const { return false; } // aka shouldEmitCollisionEvents()
|
virtual bool isLocallyOwnedOrShouldBe() const { return false; } // aka shouldEmitCollisionEvents()
|
||||||
|
virtual void saveKinematicState(btScalar timeStep);
|
||||||
|
|
||||||
friend class PhysicsEngine;
|
friend class PhysicsEngine;
|
||||||
|
|
||||||
|
|
|
@ -162,7 +162,13 @@ void ThreadSafeDynamicsWorld::saveKinematicState(btScalar timeStep) {
|
||||||
for (int i=0;i<m_nonStaticRigidBodies.size();i++) {
|
for (int i=0;i<m_nonStaticRigidBodies.size();i++) {
|
||||||
btRigidBody* body = m_nonStaticRigidBodies[i];
|
btRigidBody* body = m_nonStaticRigidBodies[i];
|
||||||
if (body && body->isKinematicObject() && body->getActivationState() != ISLAND_SLEEPING) {
|
if (body && body->isKinematicObject() && body->getActivationState() != ISLAND_SLEEPING) {
|
||||||
body->saveKinematicState(timeStep);
|
if (body->getMotionState()) {
|
||||||
|
btMotionState* motionState = body->getMotionState();
|
||||||
|
ObjectMotionState* objectMotionState = static_cast<ObjectMotionState*>(motionState);
|
||||||
|
objectMotionState->saveKinematicState(timeStep);
|
||||||
|
} else {
|
||||||
|
body->saveKinematicState(timeStep);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue