Advanced Character Physics - Angular... ?

Please don't post Bullet support questions here, use the above forums instead.
Steinmetz
Posts: 26
Joined: Sat Dec 15, 2007 12:03 am

Advanced Character Physics - Angular... ?

Post by Steinmetz »

Hello,
I implemented a physics engine based on http://www.gamasutra.com/resource_guide ... n_01.shtml.
For those who haven't read the paper above I'll explain what my engine does:
For satisfying constraints the engine just simply sets them satisfied. So if the distance between the car and the other object is too big, it will just modify their positions to the right distance. The new speeds are then calculated by Verlet( I only use it for the constraints, in the rest of the engine i use a normal Euler ).
This is done over a few iterations, so that it approximates all constraints satisfied. The hinge constraint works in the same way.
I didn't just use particles, instead I have rigid bodies.
But now I have a problem, for example in such a situation:
Image

The red circle is a hinge constraint while the red line is a position constraint.

When I pull on the circle or whatever it is, the position constraint sets it a bit in the direction of the car and the car a bit in the direction of the circle. Now in real world the car should rotate to the circle. But it doesn't because the angular velocity/position is never affected by the constraint.
Is there any possibility to calculate the resulting angular properties of both the objects, for example in the same way as I do it with the normal velocities by setting these values into Verlet?

I'm sorry but my physics knowledge isn't very big, i have just got 3 years of physics in school, and with that you can't do much :(
I also apologise for my English, I'm German and I hope you understood it ...
Yours sincerely, thank you very much.
colinvella
Posts: 24
Joined: Sat Feb 09, 2008 2:38 pm
Location: Malta

Re: Advanced Character Physics - Angular... ?

Post by colinvella »

You're basically implementing a sequential constraint solver from what I can understand. Attempting to fix the positions, especially over a number of iterations is good enough. However, for the velocities, simply attempting to translate the bodies to satisfy the constraints will not induce any rotation. You probably haven't noticed anything wierd with the position constraint because you happen to be binding the bodies at their centres of mass.

You should instead solve the velocity discrepancy at the constraints in much the same way as you would resolve single-contact collisions. In a collision, you would typically determine the appropriate velocity restitution along the normal, and calculate an impulse, that when applied to the points on the respective bodies, induce a linear and angular velocity change such that the points at the contact move off according to the required restitution.

For a constriant, the penetration becomes the constraint or joint discrepancy (i.e the distance between the two body points that should be coincident), the coefficient of restitution would typically be zero (to ensure the bodies stick together at the contact), the normal would be a unit vector along the offset between the two points. As with contacts, the constraint discrepancy (i.e. the equivalent of penetration) may be easily solved by fixing the positions using translation depending on the mass rations. The offset impulses will however still generate the required angular motion and the body will appear to rotate at the hinge.

To implement a distance constraint (rod) that can be attached to an offset position on a body (not CM), you would need to solve two discrepancies: one at the attachment point of the first body and another at the second. This will cause the bodies to swivel around the rod accordingly when one or the other is moved.

I've managed to implement angle-limited joints and hinges (in 3D) using this technique.. you just need a way of identifying where and how many constraint discrepancies to pass to your solver.
Steinmetz
Posts: 26
Joined: Sat Dec 15, 2007 12:03 am

Re: Advanced Character Physics - Angular... ?

Post by Steinmetz »

So, I can just pass the offset of the constraint to the function I have in my collision routine which calculates the resulting angular impulse out of a collision, (clearly, it will not be that easy :D), and the result would fit?
Thank you very much, thats exactly what i searched for.

edit: thank you again, it works!
colinvella
Posts: 24
Joined: Sat Feb 09, 2008 2:38 pm
Location: Malta

Re: Advanced Character Physics - Angular... ?

Post by colinvella »

Glad to hear it worked :)

The trick is to realise that a collision may be formulated as a constraint - one that you apply when two bodies are trying to interpenetrate. This approach is particularly useful when using a simultaneous solver (such as LCP), but it also works fine with a sequential solver, as in your case.

I suggest you grab hold of Ian Millington's book "Game Physics Engine Development" - it covers some of these ideas, for example, how to implement an inelastic cable between two bodies by treating it as an "inverted" collision.