Page 1 of 1

Box2D Prestep function

Posted: Tue Feb 13, 2007 8:22 am
by chudo19
Hi , Erin. While studing your Box2D example , i noticed you apply combined impulse in prestep function:

Code: Select all

	// Apply normal + friction impulse
	/*	*/Vec2 P = c->Pn * c->normal + c->Pt * tangent;

		body1->velocity -= body1->invMass * P;
		body1->angularVelocity -= body1->invI * Cross(r1, P);

		body2->velocity += body2->invMass * P;
		body2->angularVelocity += body2->invI * Cross(r2, P);
When commented stacking goes unstable.

Why this code is matter?
As i understand impulses already applied and body velocities modified while performing Impulse iteration.

Posted: Tue Feb 13, 2007 5:59 pm
by Erin Catto
The pre-step function applies the accumulated impulse from the previous time step. This is an example of warm-starting: using an old solution as an initial guess.

By commenting out those lines, you have only partially turned off warm-starting. To turn it off completely, you need to set c->Pn = c->Pt = 0 in the pre-step. With your modification the solver is in bad shape.