Skip to content
This repository has been archived by the owner on Dec 29, 2022. It is now read-only.

Commit

Permalink
Pull in changes from jbox2d
Browse files Browse the repository at this point in the history
* Make velocityThreshold mutable - See jbox2d/jbox2d#1
* TimeOfImpact loop fixes - See jbox2d/jbox2d#36
* fix ropejoint pool leak bug - See jbox2d/jbox2d#59
  • Loading branch information
filiph committed Dec 7, 2017
2 parents 76a37c9 + 6aac893 commit a480df1
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 19 deletions.
25 changes: 8 additions & 17 deletions lib/src/collision/time_of_impact.dart
Expand Up @@ -59,7 +59,8 @@ class TOIOutput {
* @author daniel
*/
class TimeOfImpact {
static const int MAX_ITERATIONS = 1000;
static const int MAX_ITERATIONS = 20;
static const int MAX_ROOT_ITERATIONS = 50;

static int toiCalls = 0;
static int toiIters = 0;
Expand Down Expand Up @@ -227,6 +228,9 @@ class TimeOfImpact {
t = 0.5 * (a1 + a2);
}

++rootIterCount;
++toiRootIters;

double s = _fcn.evaluate(_indexes[0], _indexes[1], t);

if ((s - target).abs() < tolerance) {
Expand All @@ -244,11 +248,7 @@ class TimeOfImpact {
s2 = s;
}

++rootIterCount;
++toiRootIters;

// djm: whats with this? put in settings?
if (rootIterCount == 50) {
if (rootIterCount == MAX_ROOT_ITERATIONS) {
break;
}
}
Expand All @@ -257,7 +257,8 @@ class TimeOfImpact {

++pushBackIter;

if (pushBackIter == Settings.maxPolygonVertices) {
if (pushBackIter == Settings.maxPolygonVertices ||
rootIterCount == MAX_ROOT_ITERATIONS) {
break;
}
}
Expand Down Expand Up @@ -490,10 +491,6 @@ class SeparationFunction {

switch (type) {
case SeparationFunctionType.POINTS:
Rot.mulTransUnsafeVec2(_xfa.q, axis, _axisA);
Rot.mulTransUnsafeVec2(_xfb.q, axis..negate(), _axisB);
axis.negate();

_localPointA.setFrom(proxyA.getVertex(indexA));
_localPointB.setFrom(proxyB.getVertex(indexB));

Expand All @@ -507,9 +504,6 @@ class SeparationFunction {
Rot.mulToOutUnsafe(_xfa.q, axis, _normal);
Transform.mulToOutUnsafeVec2(_xfa, localPoint, _pointA);

Rot.mulTransUnsafeVec2(_xfb.q, _normal..negate(), _axisB);
_normal.negate();

_localPointB.setFrom(proxyB.getVertex(indexB));
Transform.mulToOutUnsafeVec2(_xfb, _localPointB, _pointB);
double separation = (_pointB..sub(_pointA)).dot(_normal);
Expand All @@ -519,9 +513,6 @@ class SeparationFunction {
Rot.mulToOutUnsafe(_xfb.q, axis, _normal);
Transform.mulToOutUnsafeVec2(_xfb, localPoint, _pointB);

Rot.mulTransUnsafeVec2(_xfa.q, _normal..negate(), _axisA);
_normal.negate();

_localPointA.setFrom(proxyA.getVertex(indexA));
Transform.mulToOutUnsafeVec2(_xfa, _localPointA, _pointA);

Expand Down
2 changes: 1 addition & 1 deletion lib/src/common/sweep.dart
Expand Up @@ -26,7 +26,7 @@ part of box2d.common;

/**
* This describes the motion of a body/shape for TOI computation. Shapes are defined with respect to
* the body origin, which may no coincide with the center of mass. However, to support dynamics we
* the body origin, which may not coincide with the center of mass. However, to support dynamics we
* must interpolate the center of mass position.
*/
class Sweep {
Expand Down
2 changes: 2 additions & 0 deletions lib/src/dynamics/joints/rope_joint.dart
Expand Up @@ -125,6 +125,8 @@ class RopeJoint extends Joint {
_u.setZero();
_mass = 0.0;
_impulse = 0.0;
pool.pushRot(2);
pool.pushVec2(1);
return;
}

Expand Down
2 changes: 1 addition & 1 deletion lib/src/settings.dart
Expand Up @@ -88,7 +88,7 @@ const int maxTOIContacts = 32;
* A velocity threshold for elastic collisions. Any collision with a relative linear velocity
* below this threshold will be treated as inelastic.
*/
const double velocityThreshold = 1.0;
double velocityThreshold = 1.0;

/**
* The maximum linear position correction used when solving constraints. This helps to prevent
Expand Down

0 comments on commit a480df1

Please sign in to comment.