# Physics engine

Hi,

I am trying to use impulse resolution in my small physics engine like Erin Catto says, but this have no effect.
Same problem with friction resolution.

PS : I use the SAT for collision detection, and I use Verlet integration ( easier to make joint)

``````rpA_ = contacts[c].tk_position - _positionA;
rpB_ = contacts[c].tk_position - _positionB;

Vector3 _relativeVelocity = (_velocityB + new Vector3(rpB_.Y * -_omegaB, rpB_.X * _omegaB, 0)) -
(_velocityA + new Vector3(rpA_.Y * -_omegaA, rpA_.X * _omegaA, 0));

float _relativeNormalVelocity = _relativeVelocity.X * _normal.X + _relativeVelocity.Y * _normal.Y;
J_normal = (1 + _elasticity) * _relativeNormalVelocity;
float crossNA = (rpA_.X * _normal.Y) - (rpA_.Y * _normal.X);
float crossNB = (rpB_.X * _normal.Y) - (rpB_.Y * _normal.X);
float _crossA = crossNA * crossNA * _iA;
float _crossB = crossNB * crossNB * _iB;

float _countInv = 1.0f / (_count);
float invSum = _miA + _miB + _crossA + _crossB;

//J_normal = (J_normal / invSum) * _countInv;
//impulse_X = J_normal * _normal.X;
//impulse_Y = J_normal * _normal.Y;
^==^
float contactNormalImpulse = contacts[c].normalImpulse;
contacts[c].normalImpulse = contacts[c].normalImpulse + J_normal;
if (contacts[c].normalImpulse < 0)
contacts[c].normalImpulse = 0;
J_normal = contacts[c].normalImpulse - contactNormalImpulse;

impulse_X = (J_normal / invSum) * _countInv * _normal.X ;
impulse_Y = (J_normal / invSum) * _countInv * _normal.Y ;
``````

`float contactNormalImpulse` is null only at the first itération, so I really don’t know why it doeasn’t work

Thnx in advance

By no effect you mean that there is no visible change of motion for colliding bodies? Do they just pass through each other?

You’re saying that the math you posted results in a non-zero impulse. If that’s so, doesn’t that only leave two options?

• The calculated values are too small to have a visible impact -> you can test this by multiplying them by 10000.

• The problem is not with the math you posted that calculates the impulse, but in how this resulting impulse is being applied.

By no effect I mean there is no smouth resolution, its always a huge impulse.
I have the same result with line in comment.
When I make a pile of boxes, if I move the box on the top all my boxes jitter.
For now I desactivated friction, at the beginning I thought it was probably that… but nope

In GDC2006 Erin Catto says “remember the past”, so I think it’s ok for this part, but I don’t have PreSolveVelocity method for now, maybe its the problem.

This point its ok

``````if (rv > 0)
{

if (!(_bodyA.is_Sleeping || _bodyA.Is_Static))
{
_bodyA.oldPosition_.X -= impulse_X  * _miA;
_bodyA.oldPosition_.Y -= impulse_Y * _miA;
_bodyA.oldTheta_ -= (rpA_.X * impulse_Y - rpA_.Y * impulse_X ) * _iA;
}
if (!(_bodyB.is_Sleeping || _bodyB.Is_Static))
{
_bodyB.oldPosition_.X += impulse_X  * _miB;
_bodyB.oldPosition_.Y += impulse_Y * _miB;
_bodyB.oldTheta_ += (rpB_.X * impulse_Y - rpB_.Y * impulse_X) * _iB;
}
}
``````

I think it’s good too

Thx for your reply

Something else is very strange
`// Impulse parameter`

j = −(1 + e) vab · n
1⁄ma + 1⁄mb + (rap × n)² ⁄ Ia + (rbp × n)² ⁄ Ib

With 2 contacts point I need to separate linear and angular velocity impulse resolution, else my bounce restitution doesn’t work
`// Need aabb restitution, else no bounce`

linearJ = −(1 + e) vab · n
1⁄ma + 1⁄mb

and

AngularJ = −(1 + e) vab · n
1⁄ma + 1⁄mb (rap × n)² ⁄ Ia + (rbp × n)² ⁄ Ib

So forget my pile of boxes for now.

I really don’t understand why in my case my restitution doesn’t work.
Box2D and all physics engine on github(box2D like) use the block solver for 2points, and use Euler integration, so ok.
But Matter.js use verlet integration, and use the impulse formula for 1contact point even if there are 2 contact point. I do the same thing,( I am not really good with the Jacobian matrix) but it doesn’t work for me.
I have my contacts point, normal collision, separation… everything I need to solve OBBvsOBB (its work perfectly on a static body) but my bounce do nothing.

And nowhere I see Matter.js do some trick for Invert inertia tend to absolute zero

Thx in advance for your advise