mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 23:40:11 +02:00
SimulationEngine::enforceConstraints() takes args
...for limiting simulation costs
This commit is contained in:
parent
718b98f70a
commit
417a7def07
2 changed files with 34 additions and 8 deletions
|
@ -11,6 +11,7 @@
|
||||||
|
|
||||||
#include <glm/glm.hpp>
|
#include <glm/glm.hpp>
|
||||||
|
|
||||||
|
#include "SharedUtil.h"
|
||||||
#include "SimulationEngine.h"
|
#include "SimulationEngine.h"
|
||||||
|
|
||||||
int MAX_DOLLS_PER_ENGINE = 32;
|
int MAX_DOLLS_PER_ENGINE = 32;
|
||||||
|
@ -59,13 +60,26 @@ void SimulationEngine::removeRagDoll(RagDoll* doll) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
float SimulationEngine::enforceConstraints() {
|
void SimulationEngine::enforceConstraints(float minError, int maxIterations, quint64 maxUsec) {
|
||||||
float maxMovement = 0.0f;
|
// enforce the constraints
|
||||||
int numDolls = _dolls.size();
|
int iterations = 0;
|
||||||
for (int i = 0; i < numDolls; ++i) {
|
float delta = 0.0f;
|
||||||
maxMovement = glm::max(maxMovement, _dolls[i]->enforceConstraints());
|
quint64 now = usecTimestampNow();
|
||||||
}
|
quint64 startTime = now;
|
||||||
return maxMovement;
|
quint64 expiry = now + maxUsec;
|
||||||
|
float error = 0.0f;
|
||||||
|
do {
|
||||||
|
error = 0.0f;
|
||||||
|
int numDolls = _dolls.size();
|
||||||
|
for (int i = 0; i < numDolls; ++i) {
|
||||||
|
error = glm::max(error, _dolls[i]->enforceConstraints());
|
||||||
|
}
|
||||||
|
++iterations;
|
||||||
|
now = usecTimestampNow();
|
||||||
|
} while (iterations < maxIterations && delta > minError && now < expiry);
|
||||||
|
_enforcementIterations = iterations;
|
||||||
|
_enforcementError = delta;
|
||||||
|
_enforcementTime = now - startTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
int SimulationEngine::computeCollisions() {
|
int SimulationEngine::computeCollisions() {
|
||||||
|
|
|
@ -28,8 +28,15 @@ public:
|
||||||
|
|
||||||
void removeRagDoll(RagDoll* doll);
|
void removeRagDoll(RagDoll* doll);
|
||||||
|
|
||||||
|
/// \param minError constraint motion below this value is considered "close enough"
|
||||||
|
/// \param maxIterations max number of iterations before giving up
|
||||||
|
/// \param maxUsec max number of usec to spend enforcing constraints
|
||||||
/// \return distance of largest movement
|
/// \return distance of largest movement
|
||||||
float enforceConstraints();
|
void enforceConstraints(float minError, int maxIterations, quint64 maxUsec);
|
||||||
|
|
||||||
|
int getEnforementIterations() const { return _enforcementIterations; }
|
||||||
|
float getEnforcementError() const { return _enforcementError; }
|
||||||
|
quint64 getEnforcementTime() const { return _enforcementTime; }
|
||||||
|
|
||||||
/// \return number of collisions
|
/// \return number of collisions
|
||||||
int computeCollisions();
|
int computeCollisions();
|
||||||
|
@ -39,6 +46,11 @@ public:
|
||||||
private:
|
private:
|
||||||
CollisionList _collisionList;
|
CollisionList _collisionList;
|
||||||
QVector<RagDoll*> _dolls;
|
QVector<RagDoll*> _dolls;
|
||||||
|
|
||||||
|
// some stats for performance queries
|
||||||
|
int _enforcementIterations;
|
||||||
|
float _enforcementError;
|
||||||
|
quint64 _enforcementTime;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // hifi_SimulationEngine_h
|
#endif // hifi_SimulationEngine_h
|
||||||
|
|
Loading…
Reference in a new issue