3D object physics

Started by
11 comments, last by stefu 22 years, 8 months ago
This is part of my racing sim game. I''ve implemented the car physics by impulsing the car object in different positions (for example tyres in each axes) with forces. Here''s my impulse methods: (Sorry for my english but the english terms of physics are strangers for me)
  

// m_vLiikMaara is the amount of Movement

// m_vPyorMaar is the amount of Rotation

// m_matrix is objects transform matrix


void Impulse(float seconds,D3DXVECTOR3 *pF,D3DXVECTOR3 *pPos)
{
	D3DXVECTOR3 R,F,M;

	// Impulse the amount of movement

	m_vLiikMaara += *pF * seconds;
	
	// Transform the ForceDir to local space

	D3DXVec3TransformNormal( &F, pF, D3DXMatrixInverse(&D3DXMATRIX(),NULL,&m_matrix) );

	// Transform the ForcePos to local space

	D3DXVec3TransformCoord( &R, pPos, D3DXMatrixInverse(&D3DXMATRIX(),NULL,&m_matrix) );

	// calc momentum

	D3DXVec3Cross(&M, &R, &F);

	// Impulse the amount of rotation

	m_vPyorMaara += M * seconds;

}

D3DXVECTOR3 GetForce(float seconds,D3DXVECTOR3 *pPos,D3DXVECTOR3 *pDir)
{
	D3DXVECTOR3 R,F,M;

	// Transform the Pos to local space

	D3DXVec3TransformCoord( &R, pPos, D3DXMatrixInverse(&D3DXMATRIX(),NULL,&m_matrix) );

	// calc the moment

	M = m_vPyorMaara / seconds;

	// calc the Force by M and R

	D3DXVec3Cross(&F, &M, &R);

	// Transform Force to world space

	D3DXVec3TransformNormal(&F,&F,&m_matrix);
        // Now F is the Force by rotation


	// add the force by movement

	F += m_vLiikMaara / seconds;

	// Project the Force to pDir

	return *pDir * D3DXVec3Dot(pDir,&F) / D3DXVec3Dot(pDir,pDir);
}
  
This simply works well and I get my car running realistic. My problem comes here: Now I affect the amount of rotation and amount of movement with the impulse force. But in reality? How much does the impulse affect to the amount of rotation and how much it affects to the amount of movement? This is over my head! I know that if I impulse the object in line that goes throug the mass centre the the object doesn''t rotate at all. But if I impulse it to the edge of the object then it begins to rotate and move but it moves less. Aaargh. It''s hard to put this in words, but hope someone understand what I mean? I''ve thought to emulate this with kind of simple algorithm, but because this seems to be very complex problem, I couldn''t find any.
Advertisement
The simplest solution (I think) is to take your force vector and split it in two parts. One going straight through the centre of mass, and the other one perpendicular to the first one (ie. perpendicular to a vector from the point where the force vector is applied to the centre of mass. This can quite easily be done with cross and dot products etc...

Am I making any sense?
In reality, the force doesn''t modify neither rotation nor translation directly. The force affects the angular acceleration, which is integrated to get the angular velocity, and that is integrated to get the rotation angle.
Same thing for translation. If you want realistic physics, you have to implement all that. Not to forget about friction, wind resistance and so on. Look at Chris Heckers articles about dynamics, they are a bit dated, but still very good and cover all that.
www.d6.com/users/checker
> Now I affect the amount of rotation and amount of movement
> with the impulse force.

> But in reality? How much does the impulse affect to the amount
> of rotation and how much it affects to the amount of movement?
> This is over my head!

The answer is mathematically straightforward. Any applied force effects both the linear and rotational motion. The linear effect is the one you are familiar with, i.f. F = Ma. The rotational effect is a bit more complex but can be expressed similarly as

T = I(dw/dt)

T is the torque, which can be calculated from r ^ F, where r is the offset of the force from the centre of mass/rotation and F is the same applied force. dw/dt is the rate of change of angular velocity, just as ''a'' is the rate of change of linear velocity.

''I'' is the moment of inertia tensor. This is a symmetric 3 x 3 matrix which depends on the mass distribution of the shape. It''s possible to do these calculations in world space or object space. The latter is far easier as then the moement of inertia tensor is constant, and in general if the axes are aligned along the objects axes of symmetry it is a diagonal matrix.
John BlackburneProgrammer, The Pitbull Syndicate
Thanks for replies!

I don''t yet really understand all the physics needed but I''m very consentrated in it and I''ll clear from it soon!

I''m learning Chris Heckers articles about dynamics. It''s just what I need to know about physics and collisions. Very good. Also the Physics example is very good, I''v already made some test with it.
If you''re searching google or wherever for more information, the subject you need to learn about is rotational dynamics, or, more specifically, torque, angular momentum, and angular velocity.

When a force/impulse is applied to an object, it affects both the movement and the rotation.

How it affects motion: Whenever a force is applied to an object, it causes an acceleration in that direction, which in turn affects velocity and position. This is true regardless of where on the object the force is applied.

How it affects rotation: Any force will cause rotation if
a) it is not applied to the centre of the object
AND
b) the direction of the force does not point directly towards or away from the object''s centre

So the same impulse will always produce the same change in motion regardless of where it is applied, but it can cause different changes in rotation depending on where it is applied.

You''ve probably learned the equations of motion like F=ma, v1 = v0 + a*dt, etc. that govern motion and have implemented them in your code. There are similar equations governing rotation that you''ll need to learn.
quote:
Dobbs wrote:
How it affects motion: Whenever a force is applied to an object, it causes an acceleration in that direction, which in turn affects velocity and position. This is true regardless of where on the object the force is applied.

[...]

So the same impulse will always produce the same change in motion regardless of where it is applied, [...]


This is not quite true. You must first divide the force into two composants (as I wrote above). One pointing towards the center of mass of the object. This is the part of the force that affects the objects acceleration (and hence velocity). The second composant should be perpendicular to the first. This is the part of the force that affects the torque. If the force is moved to another point on the object the direction towards the center of mass may change and if it does the composants will change, leading to a different amount of acceleration and torque.

If this is in any way unclear, don''t hesitate to ask and I''ll try to explain it a bit better.
The point as which you stop differentiating the motion involved is arbitrary. You can differentiate acceleration and produce jerk and differentiate jerk to produce jerk/s, ad infinitum... I think the minimum level you need to go to in order to produce plausibly realistic results, is acceleration; it''s probably adequate for the majority of simulations as well.

Magmai Kai Holmlor
- Not For Rent
- The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara
quote:Original post by Dactylos
This is not quite true. You must first divide the force into two composants (as I wrote above). One pointing towards the center of mass of the object. This is the part of the force that affects the objects acceleration (and hence velocity). The second composant should be perpendicular to the first. This is the part of the force that affects the torque. If the force is moved to another point on the object the direction towards the center of mass may change and if it does the composants will change, leading to a different amount of acceleration and torque.

If this is in any way unclear, don''t hesitate to ask and I''ll try to explain it a bit better.


I have to doubt what you said. Does what you say mean that if I hit object (that doesn''t move) with a Force (not going through the Center of Mass) then the object starts moving (not the direction of Force but) direction of the Force component that goes through the CM (+ rotation of course)?

If I divide the force in two components, the I need starting point for the force (+ CM). But The Force isn''t applied from any point, Force lies on a line. Position is needed to calculate how far the Force is perpendicular to CM (it''s always the nearest point of Force-line to CM point).

I think that the object wil alway move the direction of the force (+ rotating).

Correct me if I''m wrong. This is what I got from my head, I haven''t studied these things at all.

Is there any good math libraries in c++? I''m working with D3DXVECTOR and D3DXMATRIX, but they are not so nice to work with.
> This is not quite true. You must first divide the force into
> two composants (as I wrote above). One pointing towards the
> center of mass of the object. This is the part of the force
> that affects the objects acceleration (and hence velocity).
> The second composant should be perpendicular to the first.
> This is the part of the force that affects the torque. If the
> force is moved to another point on the object the direction
> towards the center of mass may change and if it does the
> composants will change, leading to a different amount of
> acceleration and torque.

You are wrong. The correct way is to apply the same force to the linear and angular veclocity/acceleration. The outcomes will be different because the effects and the way you calculate them are different, e.g. with rotation depending on the offset of the force from the centre of rotation. Again the equations are

F = ma

and

r ^ F = I(dw/dt)

with F in both equations being the applied force.

The confusion perhaps arises because often the input force depends on the relationship between linear and rotational effects. E.g. levers work by increasing the distance of the point a force is applied from the centre of rotation, increasing the rotational effect of it and so reducing the force required. But the force is still applied to rotational and linear dynamics.
John BlackburneProgrammer, The Pitbull Syndicate

This topic is closed to new replies.

Advertisement