mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 01:17:14 +02:00
more correct moving test for ballistic kinematics
This commit is contained in:
parent
7ea81f3937
commit
74058ac049
1 changed files with 9 additions and 5 deletions
|
@ -919,7 +919,8 @@ void EntityItem::simulateKinematicMotion(float timeElapsed, bool setFlags) {
|
||||||
}
|
}
|
||||||
|
|
||||||
glm::vec3 linearAcceleration = _acceleration;
|
glm::vec3 linearAcceleration = _acceleration;
|
||||||
if (glm::length2(_acceleration) > 0.0f) {
|
bool nonZeroAcceleration = (glm::length2(_acceleration) > 0.0f);
|
||||||
|
if (nonZeroAcceleration) {
|
||||||
// acceleration is in world-frame but we need it in local-frame
|
// acceleration is in world-frame but we need it in local-frame
|
||||||
bool success;
|
bool success;
|
||||||
Transform parentTransform = getParentTransform(success);
|
Transform parentTransform = getParentTransform(success);
|
||||||
|
@ -928,17 +929,20 @@ void EntityItem::simulateKinematicMotion(float timeElapsed, bool setFlags) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// integrate position forward
|
||||||
|
glm::vec3 position = transform.getTranslation() + (linearVelocity * timeElapsed) + 0.5f * linearAcceleration * timeElapsed * timeElapsed;
|
||||||
|
transform.setTranslation(position);
|
||||||
|
|
||||||
// integrate linearVelocity
|
// integrate linearVelocity
|
||||||
linearVelocity += linearAcceleration * timeElapsed;
|
linearVelocity += linearAcceleration * timeElapsed;
|
||||||
|
|
||||||
const float EPSILON_LINEAR_VELOCITY_LENGTH_SQUARED = 1.0e-6f; // 1mm/sec ^2
|
const float EPSILON_LINEAR_VELOCITY_LENGTH_SQUARED = 1.0e-6f; // 1mm/sec ^2
|
||||||
if (glm::length2(linearVelocity) < EPSILON_LINEAR_VELOCITY_LENGTH_SQUARED) {
|
if (glm::length2(linearVelocity) < EPSILON_LINEAR_VELOCITY_LENGTH_SQUARED) {
|
||||||
setVelocity(ENTITY_ITEM_ZERO_VEC3);
|
setVelocity(ENTITY_ITEM_ZERO_VEC3);
|
||||||
|
if (nonZeroAcceleration) {
|
||||||
|
isMoving = true;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// integrate position forward
|
|
||||||
// NOTE: we're using the NEW linear velocity, which is why we negate the acceleration term
|
|
||||||
glm::vec3 position = transform.getTranslation() + (linearVelocity * timeElapsed) - 0.5f * linearAcceleration * timeElapsed * timeElapsed;
|
|
||||||
transform.setTranslation(position);
|
|
||||||
isMoving = true;
|
isMoving = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue