How kinematic bodies work under the hood

Post Reply
johnsmith
Posts: 4
Joined: Mon Mar 28, 2022 12:29 am

How kinematic bodies work under the hood

Post by johnsmith »

I'm trying to understand how "kinematic" or "passive" rigid bodies generally work under the hood. And how they fit into Lagrangian mechanics. They have zero inverse mass so they are not going to be affected by constraints. But I'm curious about how the force, velocity and position is calculated for these kinematic bodies as opposed to "dynamic" ones. With dynamic bodies we calculate the forces and integrate the velocity and position. Do we basically do the reverse with kinematic bodies? From animation get the change in position between frames, store this change as velocity, then calculate the change in velocity between frames and store it as acceleration? And finally use the calculated acceleration/force for the kinematic body to satisfy the constraints of dynamic rigid bodies connected to it?

Deeply appreciate any help as I'm not able to find any relevant information on the subject of kinematic bodies on the web.
User avatar
drleviathan
Posts: 849
Joined: Tue Sep 30, 2014 6:03 pm
Location: San Francisco

Re: How kinematic bodies work under the hood

Post by drleviathan »

Bullet does not integrate kinematic objects forward. Instead it relies on custom external logic (e.g. stuff the game dev wrote) to supply their world transforms every substep. Typically this is done by supplying a MotionState that does the Right Thing inside its getWorldTransform() override.

Usually kinematic objects follow a scripted non-physical motion. Think: moving platforms or other gamey mechanics that don't need to be reactive to collisions from other objects. It would be challenging (and questionable) to try to make a kinematic object that tries to move dynamically.
johnsmith
Posts: 4
Joined: Mon Mar 28, 2022 12:29 am

Re: How kinematic bodies work under the hood

Post by johnsmith »

Thanks for the reply. I think I need to rephrase the question. Say we have a hinge joint between a kinematic and dynamic rigid body. To implement this we need to define a position constraint. If you have two dynamic rigid bodies you can use their velocities and forces acting on them, to calculate the needed constraint forces or constraint impulses. But how would you constrain a dynamic rigid body to a kinematic one? My knowledge of Lagrangian mechanics is limited at the moment and I'm banging my head not being able to figure this one out.
User avatar
drleviathan
Posts: 849
Joined: Tue Sep 30, 2014 6:03 pm
Location: San Francisco

Re: How kinematic bodies work under the hood

Post by drleviathan »

The pivot on the kinematic object is effectively a constraint of the Lagrangian dynamics. It is determined by the transform/velocities of the kinematic object, which effectively has infinite mass and inertia, and are therefore known as soon as the kinematic object's transform/velocities have been revealed by whatever logic is supplying them. All of the unknown resulting transforms/velocities relate only to the dynamic object.

As I recall: with Lagrangian dynamics you don't normally compute the forces/torques. Instead you solve for the new transform/velocities which must obey the constraints and the forces/torques are whatever they had to be to produce the constrained motion. You can "measure" forces/torques after the fact, but they are not known or used when solving for the new transform/velocities.
johnsmith
Posts: 4
Joined: Mon Mar 28, 2022 12:29 am

Re: How kinematic bodies work under the hood

Post by johnsmith »

The pivot on the kinematic object is effectively a constraint of the Lagrangian dynamics
I'm sorry but I don't think this terminology make sense, what does it mean that a pivot is a constraint? Wouldn't example of a constraint be that pivot position vector has to equal something.
with Lagrangian dynamics you don't normally compute the forces/torques. Instead you solve for the new transform/velocities which must obey the constraints and the forces/torques
I'm not sure why correct me on this. You do in fact have to collect all forces/torques applied to each body. You use these to calculate the lagrange multiplier, which is then used to calculate the constraint forces (or impulses). The constraint forces are applied to the bodies and the velocity, position etc is integrated from these forces.
User avatar
drleviathan
Posts: 849
Joined: Tue Sep 30, 2014 6:03 pm
Location: San Francisco

Re: How kinematic bodies work under the hood

Post by drleviathan »

Sorry, I was getting Lagrangian dynamics confused with the Jacobi method which is what Bullet uses to solve constraints. When solving the Jacobi matrices of the various constraints the iterative method converges on the new final values of the transform and velocities without explicit knowledge of the forces involved.

When I scan the Bullet code I don't see much mention of Lagrangian dynamics except for the soft-body stuff, so AFAICT it isn't used when solving constraints.

Yes, if there is a Hinge joint between a kinematic and a dynamic object then the kinematic end of the hinge is fixed to be at a very specific point: some local offset from the kinematic object's world-frame transform. Meanwhile the kinematic object is immune to influences by the constraint because Bullet asks external logic for the Kinematic object's transform, applies it, and then leaves it there. As such, I describe its situation as being "effectively a constraint": for the duration of the constraint solver phase it is set a priori; it is immutable.
johnsmith
Posts: 4
Joined: Mon Mar 28, 2022 12:29 am

Re: How kinematic bodies work under the hood

Post by johnsmith »

the Jacobi method which is what Bullet uses to solve constraints.
Oh I see, I'll look into this method thanks!
Post Reply