I see, you got it right for the most part, just a subtle clarification, a kinematic body is not a static body.
I think that to justify what seems like arbitrary and contrive system, some background might help
Remember when I said, kinematic bodies have the property of a rigid body but not the properties of a dynamics rigid body. This definition is based on Newton's laws of motion.
From Wikipedia:
1-A body remains at rest, or in motion at a constant speed in a straight line, unless it is acted upon by a force.
2-At any instant of time, the net force on a body is equal to the body's acceleration multiplied by its mass or, equivalently, the rate at which the body's momentum is changing with time.
In classical mechanic, a kinematic body is on that obey Newton first law of physics.
I particularly do not like the second definition.
I prefer. A body acceleration is the product of its mass and the net force acting on it.
But the Wikipedia definition is fine.
form those laws, we can say that the state of a rigid body is determine by its velocity and acceleration. (this is different than what impulse based engine define as state with is velocity and position)
In the newton library. A kinematic body is one that abides by newton's first law of motion and optionally, the third, but not the second. A dynamics body is one that obey first, second and third laws of motion.
This mean that a kinematic body can have a velocity and still considered in equilibrium.
note that we use the term "equilibrium" instead of at "rest".
Normally if a dynamics body comes in contact with a kinematic body, the third law of motion takes place and the bodies collide, not problem there.
Now if a dynamics body is at rest, them it is also in equilibrium, so, how do we make it interact with other bodies that are also in equilibrium?
first: let me correct what I said before about kinematic body integration.
if a kinematic body has mass, they are integrated by the engine.
it is only static body that does not get integrated.
(static body defined as one with inverse mass zero)
so, how to make moving kinematic bodies interact with bodies at rest?
for that we are still appealing to all CPP objective programing.
Yes, this is still and legacy form 3.14 when we had base classes and special sub classes.
Anyway, to fix this all you need to do is this.
1-Sub class the trigger and make you own base trigger class.
2-Implement the three function: onEnter, OnTrigger and OnExit
3-give the trigger object a mass and inertia.
4 implement method ::SpecialUpdate(ndFloat32 timestep)
with that, a moving trigger will interact with bodies at rest. If the trigger has mass.
I modified the buoyancy demo to show how to do it, these are the modifications.
- Code: Select all
ndArchimedesBuoyancyVolume::ndArchimedesBuoyancyVolume()
:ndBodyTriggerVolume()
,m_plane(ndVector::m_zero)
,m_density(1.0f)
,m_hasPlane(0)
{
// gives the trigger some mass to make it acc as a dynamics body
SetMassMatrix(1.0f, 1.0f, 1.0f, 1.0f);
}
void ndArchimedesBuoyancyVolume::SpecialUpdate(ndFloat32 timestep)
{
ndBodyTriggerVolume::SpecialUpdate(timestep);
// here the app can do manipulate the body ex: setting velocity
// in this examnple we do nothing
//SetVelocity(ndVector(1.0f, 0.0f, 0.0f, 0.0f));
}
if you do that, it saves you the iteration logic, and the problem reduces to calculate the trigger's velocity and angular velocity, in the SpecialUpdate method.
To calculate velocity there are functions like velocity at a point to help with that:
basically, you associate the trigger with some reference body, then, the angular velocity will the angular velocity of the reference body, and the linear velocity is the VelocityAtaPoint(trigger center of mass in global space)
tell me if this helps?