mirror of
https://github.com/overte-org/overte.git
synced 2025-04-22 03:04:33 +02:00
more correct names for ContactPoint API
renamed (and disabled) the useless enforce() to applyFriction() changed the buildConstraints() method to more correct name: enforce() will eventually change how ContactPoint actually works, but later
This commit is contained in:
parent
60d411ead5
commit
98d27ad2b5
4 changed files with 37 additions and 34 deletions
|
@ -88,25 +88,7 @@ ContactPoint::ContactPoint(const CollisionInfo& collision, quint32 frame) :
|
|||
}
|
||||
}
|
||||
|
||||
// virtual
|
||||
float ContactPoint::enforce() {
|
||||
for (int i = 0; i < _numPoints; ++i) {
|
||||
glm::vec3& position = _points[i]->_position;
|
||||
// TODO: use a fast distance approximation
|
||||
float newDistance = glm::distance(_contactPoint, position);
|
||||
float constrainedDistance = _distances[i];
|
||||
// NOTE: these "distance" constraints only push OUT, don't pull IN.
|
||||
if (newDistance > EPSILON && newDistance < constrainedDistance) {
|
||||
glm::vec3 direction = (_contactPoint - position) / newDistance;
|
||||
glm::vec3 center = 0.5f * (_contactPoint + position);
|
||||
_contactPoint = center + (0.5f * constrainedDistance) * direction;
|
||||
position = center - (0.5f * constrainedDistance) * direction;
|
||||
}
|
||||
}
|
||||
return 0.0f;
|
||||
}
|
||||
|
||||
void ContactPoint::buildConstraints() {
|
||||
glm::vec3 pointA = _shapeA->getTranslation() + _offsetA;
|
||||
glm::vec3 pointB = _shapeB->getTranslation() + _offsetB;
|
||||
glm::vec3 penetration = pointA - pointB;
|
||||
|
@ -153,6 +135,27 @@ void ContactPoint::buildConstraints() {
|
|||
_distances[i] = glm::length(glm::length(_offsets[i]));
|
||||
}
|
||||
}
|
||||
return 0.0f;
|
||||
}
|
||||
|
||||
// virtual
|
||||
void ContactPoint::applyFriction() {
|
||||
// TODO: Andrew to re-implement this
|
||||
/*
|
||||
for (int i = 0; i < _numPoints; ++i) {
|
||||
glm::vec3& position = _points[i]->_position;
|
||||
// TODO: use a fast distance approximation
|
||||
float newDistance = glm::distance(_contactPoint, position);
|
||||
float constrainedDistance = _distances[i];
|
||||
// NOTE: these "distance" constraints only push OUT, don't pull IN.
|
||||
if (newDistance > EPSILON && newDistance < constrainedDistance) {
|
||||
glm::vec3 direction = (_contactPoint - position) / newDistance;
|
||||
glm::vec3 center = 0.5f * (_contactPoint + position);
|
||||
_contactPoint = center + (0.5f * constrainedDistance) * direction;
|
||||
position = center - (0.5f * constrainedDistance) * direction;
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
void ContactPoint::updateContact(const CollisionInfo& collision, quint32 frame) {
|
||||
|
|
|
@ -26,8 +26,8 @@ public:
|
|||
ContactPoint(const CollisionInfo& collision, quint32 frame);
|
||||
|
||||
virtual float enforce();
|
||||
|
||||
void buildConstraints();
|
||||
|
||||
void applyFriction();
|
||||
void updateContact(const CollisionInfo& collision, quint32 frame);
|
||||
quint32 getLastFrame() const { return _lastFrame; }
|
||||
|
||||
|
|
|
@ -195,7 +195,7 @@ void PhysicsSimulation::stepForward(float deltaTime, float minError, int maxIter
|
|||
quint64 expiry = startTime + maxUsec;
|
||||
|
||||
moveRagdolls(deltaTime);
|
||||
buildContactConstraints();
|
||||
enforceContacts();
|
||||
int numDolls = _otherRagdolls.size();
|
||||
{
|
||||
PerformanceTimer perfTimer("enforce");
|
||||
|
@ -219,7 +219,7 @@ void PhysicsSimulation::stepForward(float deltaTime, float minError, int maxIter
|
|||
error = glm::max(error, _otherRagdolls[i]->enforceConstraints());
|
||||
}
|
||||
}
|
||||
enforceContactConstraints();
|
||||
applyContactFriction();
|
||||
++iterations;
|
||||
|
||||
now = usecTimestampNow();
|
||||
|
@ -288,16 +288,7 @@ void PhysicsSimulation::resolveCollisions() {
|
|||
}
|
||||
}
|
||||
|
||||
void PhysicsSimulation::buildContactConstraints() {
|
||||
PerformanceTimer perfTimer("contacts");
|
||||
QMap<quint64, ContactPoint>::iterator itr = _contacts.begin();
|
||||
while (itr != _contacts.end()) {
|
||||
itr.value().buildConstraints();
|
||||
++itr;
|
||||
}
|
||||
}
|
||||
|
||||
void PhysicsSimulation::enforceContactConstraints() {
|
||||
void PhysicsSimulation::enforceContacts() {
|
||||
PerformanceTimer perfTimer("contacts");
|
||||
QMap<quint64, ContactPoint>::iterator itr = _contacts.begin();
|
||||
while (itr != _contacts.end()) {
|
||||
|
@ -306,6 +297,15 @@ void PhysicsSimulation::enforceContactConstraints() {
|
|||
}
|
||||
}
|
||||
|
||||
void PhysicsSimulation::applyContactFriction() {
|
||||
PerformanceTimer perfTimer("contacts");
|
||||
QMap<quint64, ContactPoint>::iterator itr = _contacts.begin();
|
||||
while (itr != _contacts.end()) {
|
||||
itr.value().applyFriction();
|
||||
++itr;
|
||||
}
|
||||
}
|
||||
|
||||
void PhysicsSimulation::updateContacts() {
|
||||
PerformanceTimer perfTimer("contacts");
|
||||
int numCollisions = _collisions.size();
|
||||
|
|
|
@ -56,8 +56,8 @@ protected:
|
|||
void computeCollisions();
|
||||
void resolveCollisions();
|
||||
|
||||
void buildContactConstraints();
|
||||
void enforceContactConstraints();
|
||||
void enforceContacts();
|
||||
void applyContactFriction();
|
||||
void updateContacts();
|
||||
void pruneContacts();
|
||||
|
||||
|
|
Loading…
Reference in a new issue