mirror of
https://github.com/overte-org/overte.git
synced 2025-08-10 21:03:27 +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() {
|
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 pointA = _shapeA->getTranslation() + _offsetA;
|
||||||
glm::vec3 pointB = _shapeB->getTranslation() + _offsetB;
|
glm::vec3 pointB = _shapeB->getTranslation() + _offsetB;
|
||||||
glm::vec3 penetration = pointA - pointB;
|
glm::vec3 penetration = pointA - pointB;
|
||||||
|
@ -153,6 +135,27 @@ void ContactPoint::buildConstraints() {
|
||||||
_distances[i] = glm::length(glm::length(_offsets[i]));
|
_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) {
|
void ContactPoint::updateContact(const CollisionInfo& collision, quint32 frame) {
|
||||||
|
|
|
@ -26,8 +26,8 @@ public:
|
||||||
ContactPoint(const CollisionInfo& collision, quint32 frame);
|
ContactPoint(const CollisionInfo& collision, quint32 frame);
|
||||||
|
|
||||||
virtual float enforce();
|
virtual float enforce();
|
||||||
|
|
||||||
void buildConstraints();
|
void applyFriction();
|
||||||
void updateContact(const CollisionInfo& collision, quint32 frame);
|
void updateContact(const CollisionInfo& collision, quint32 frame);
|
||||||
quint32 getLastFrame() const { return _lastFrame; }
|
quint32 getLastFrame() const { return _lastFrame; }
|
||||||
|
|
||||||
|
|
|
@ -195,7 +195,7 @@ void PhysicsSimulation::stepForward(float deltaTime, float minError, int maxIter
|
||||||
quint64 expiry = startTime + maxUsec;
|
quint64 expiry = startTime + maxUsec;
|
||||||
|
|
||||||
moveRagdolls(deltaTime);
|
moveRagdolls(deltaTime);
|
||||||
buildContactConstraints();
|
enforceContacts();
|
||||||
int numDolls = _otherRagdolls.size();
|
int numDolls = _otherRagdolls.size();
|
||||||
{
|
{
|
||||||
PerformanceTimer perfTimer("enforce");
|
PerformanceTimer perfTimer("enforce");
|
||||||
|
@ -219,7 +219,7 @@ void PhysicsSimulation::stepForward(float deltaTime, float minError, int maxIter
|
||||||
error = glm::max(error, _otherRagdolls[i]->enforceConstraints());
|
error = glm::max(error, _otherRagdolls[i]->enforceConstraints());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
enforceContactConstraints();
|
applyContactFriction();
|
||||||
++iterations;
|
++iterations;
|
||||||
|
|
||||||
now = usecTimestampNow();
|
now = usecTimestampNow();
|
||||||
|
@ -288,16 +288,7 @@ void PhysicsSimulation::resolveCollisions() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void PhysicsSimulation::buildContactConstraints() {
|
void PhysicsSimulation::enforceContacts() {
|
||||||
PerformanceTimer perfTimer("contacts");
|
|
||||||
QMap<quint64, ContactPoint>::iterator itr = _contacts.begin();
|
|
||||||
while (itr != _contacts.end()) {
|
|
||||||
itr.value().buildConstraints();
|
|
||||||
++itr;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void PhysicsSimulation::enforceContactConstraints() {
|
|
||||||
PerformanceTimer perfTimer("contacts");
|
PerformanceTimer perfTimer("contacts");
|
||||||
QMap<quint64, ContactPoint>::iterator itr = _contacts.begin();
|
QMap<quint64, ContactPoint>::iterator itr = _contacts.begin();
|
||||||
while (itr != _contacts.end()) {
|
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() {
|
void PhysicsSimulation::updateContacts() {
|
||||||
PerformanceTimer perfTimer("contacts");
|
PerformanceTimer perfTimer("contacts");
|
||||||
int numCollisions = _collisions.size();
|
int numCollisions = _collisions.size();
|
||||||
|
|
|
@ -56,8 +56,8 @@ protected:
|
||||||
void computeCollisions();
|
void computeCollisions();
|
||||||
void resolveCollisions();
|
void resolveCollisions();
|
||||||
|
|
||||||
void buildContactConstraints();
|
void enforceContacts();
|
||||||
void enforceContactConstraints();
|
void applyContactFriction();
|
||||||
void updateContacts();
|
void updateContacts();
|
||||||
void pruneContacts();
|
void pruneContacts();
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue