Box2D Prestep function

Please don't post Bullet support questions here, use the above forums instead.
chudo19
Posts: 4
Joined: Wed Jun 07, 2006 11:39 am

Box2D Prestep function

Post 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.
Erin Catto
Posts: 316
Joined: Fri Jul 01, 2005 5:29 am
Location: Irvine

Post 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.