mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-08-10 03:53:22 +02:00
Split PhysicsSimulation::stepForward() into parts
This commit is contained in:
parent
716ae3e479
commit
f0c2417206
3 changed files with 29 additions and 25 deletions
|
@ -200,7 +200,7 @@ void MyAvatar::simulate(float deltaTime) {
|
||||||
PerformanceTimer perfTimer("MyAvatar::simulate/head Simulate");
|
PerformanceTimer perfTimer("MyAvatar::simulate/head Simulate");
|
||||||
const int minError = 0.005f;
|
const int minError = 0.005f;
|
||||||
const float maxIterations = 4;
|
const float maxIterations = 4;
|
||||||
const quint64 maxUsec = 500;
|
const quint64 maxUsec = 1000;
|
||||||
_physicsSimulation.stepForward(deltaTime, minError, maxIterations, maxUsec);
|
_physicsSimulation.stepForward(deltaTime, minError, maxIterations, maxUsec);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -128,30 +128,36 @@ void PhysicsSimulation::removeRagdoll(Ragdoll* doll) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Andrew need to implement:
|
// TODO: Andrew need to implement:
|
||||||
// DONE (1) joints pull points (SpecialCapsuleShape would help solve this)
|
// DONE (1) joints pull points (SpecialCapsuleShape would help solve this)
|
||||||
// DONE (2) points slam shapes (SpecialCapsuleShape would help solve this)
|
// DONE (2) points slam shapes (SpecialCapsuleShape would help solve this)
|
||||||
// DONE (3) detect collisions
|
// DONE (3) detect collisions
|
||||||
// DONE (4) collisions move points (SpecialCapsuleShape would help solve this)
|
// DONE (4) collisions move points (SpecialCapsuleShape would help solve this)
|
||||||
// DONE (5) enforce constraints
|
// DONE (5) enforce constraints
|
||||||
// (6) make sure MyAvatar creates shapes, adds to simulation with ragdoll support
|
// DONE (6) make sure MyAvatar creates shapes, adds to simulation with ragdoll support
|
||||||
// (7) support for pairwise collision bypass
|
// (7) support for pairwise collision bypass
|
||||||
// (8) process collisions
|
// (8) process collisions
|
||||||
// (9) add and enforce angular contraints for joints
|
// (9) add and enforce angular contraints for joints
|
||||||
void PhysicsSimulation::stepForward(float deltaTime, float minError, int maxIterations, quint64 maxUsec) {
|
void PhysicsSimulation::stepForward(float deltaTime, float minError, int maxIterations, quint64 maxUsec) {
|
||||||
int iterations = 0;
|
quint64 startTime = usecTimestampNow();
|
||||||
quint64 now = usecTimestampNow();
|
quint64 expiry = startTime + maxUsec;
|
||||||
quint64 startTime = now;
|
|
||||||
quint64 expiry = now + maxUsec;
|
|
||||||
|
|
||||||
// move dolls
|
moveRagdolls(deltaTime);
|
||||||
|
computeCollisions();
|
||||||
|
processCollisions();
|
||||||
|
enforceConstraints(minError, maxIterations, expiry - usecTimestampNow());
|
||||||
|
|
||||||
|
_stepTime = usecTimestampNow()- startTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
void PhysicsSimulation::moveRagdolls(float deltaTime) {
|
||||||
int numDolls = _dolls.size();
|
int numDolls = _dolls.size();
|
||||||
for (int i = 0; i < numDolls; ++i) {
|
for (int i = 0; i < numDolls; ++i) {
|
||||||
_dolls.at(i)->stepRagdollForward(deltaTime);
|
_dolls.at(i)->stepRagdollForward(deltaTime);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
// collide
|
|
||||||
|
void PhysicsSimulation::computeCollisions() {
|
||||||
_collisionList.clear();
|
_collisionList.clear();
|
||||||
// TODO: keep track of QSet<PhysicsEntity*> collidedEntities;
|
// TODO: keep track of QSet<PhysicsEntity*> collidedEntities;
|
||||||
int numEntities = _entities.size();
|
int numEntities = _entities.size();
|
||||||
|
@ -179,12 +185,19 @@ void PhysicsSimulation::stepForward(float deltaTime, float minError, int maxIter
|
||||||
ShapeCollider::collideShapesWithShapes(shapes, otherShapes, _collisionList);
|
ShapeCollider::collideShapesWithShapes(shapes, otherShapes, _collisionList);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: process collisions
|
|
||||||
_numCollisions = _collisionList.size();
|
_numCollisions = _collisionList.size();
|
||||||
|
}
|
||||||
|
|
||||||
// enforce constraints
|
void PhysicsSimulation::processCollisions() {
|
||||||
|
// TODO: Andrew to implement this
|
||||||
|
}
|
||||||
|
|
||||||
|
void PhysicsSimulation::enforceConstraints(float minError, int maxIterations, quint64 maxUsec) {
|
||||||
|
quint64 now = usecTimestampNow();
|
||||||
|
quint64 expiry = now + maxUsec;
|
||||||
|
int iterations = 0;
|
||||||
float error = 0.0f;
|
float error = 0.0f;
|
||||||
|
int numDolls = _dolls.size();
|
||||||
do {
|
do {
|
||||||
error = 0.0f;
|
error = 0.0f;
|
||||||
for (int i = 0; i < numDolls; ++i) {
|
for (int i = 0; i < numDolls; ++i) {
|
||||||
|
@ -193,16 +206,7 @@ void PhysicsSimulation::stepForward(float deltaTime, float minError, int maxIter
|
||||||
++iterations;
|
++iterations;
|
||||||
now = usecTimestampNow();
|
now = usecTimestampNow();
|
||||||
} while (iterations < maxIterations && error > minError && now < expiry);
|
} while (iterations < maxIterations && error > minError && now < expiry);
|
||||||
|
|
||||||
_numIterations = iterations;
|
_numIterations = iterations;
|
||||||
_constraintError = error;
|
_constraintError = error;
|
||||||
_stepTime = now - startTime;
|
|
||||||
}
|
|
||||||
|
|
||||||
int PhysicsSimulation::computeCollisions() {
|
|
||||||
return 0.0f;
|
|
||||||
}
|
|
||||||
|
|
||||||
void PhysicsSimulation::processCollisions() {
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -41,10 +41,10 @@ public:
|
||||||
/// \return distance of largest movement
|
/// \return distance of largest movement
|
||||||
void stepForward(float deltaTime, float minError, int maxIterations, quint64 maxUsec);
|
void stepForward(float deltaTime, float minError, int maxIterations, quint64 maxUsec);
|
||||||
|
|
||||||
/// \return number of collisions
|
void moveRagdolls(float deltaTime);
|
||||||
int computeCollisions();
|
void computeCollisions();
|
||||||
|
|
||||||
void processCollisions();
|
void processCollisions();
|
||||||
|
void enforceConstraints(float minError, int maxIterations, quint64 maxUsec);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
CollisionList _collisionList;
|
CollisionList _collisionList;
|
||||||
|
|
Loading…
Reference in a new issue