// 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); } 
3D object physics
Started by stefu, Aug 05 2001 08:03 AM
12 replies to this topic
#1 Members  Reputation: 120
Posted 05 August 2001  08:03 AM
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)
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.
Sponsor:
#2 Members  Reputation: 122
Posted 05 August 2001  08:23 AM
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?
Am I making any sense?
#3 Anonymous Poster_Anonymous Poster_* Guests  Reputation:
Posted 05 August 2001  09:25 AM
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
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
#4 Members  Reputation: 347
Posted 05 August 2001  09:43 PM
> 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.
> 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.
#5 Members  Reputation: 120
Posted 05 August 2001  10:30 PM
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.
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.
#6 Members  Reputation: 164
Posted 06 August 2001  10:22 AM
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.
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.
#7 Members  Reputation: 122
Posted 06 August 2001  10:39 AM
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.
#8 Moderators  Reputation: 1390
Posted 06 August 2001  06:49 PM
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
Magmai Kai Holmlor
 Not For Rent
#9 Members  Reputation: 120
Posted 06 August 2001  10:09 PM
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 Forceline 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.
#10 Members  Reputation: 347
Posted 06 August 2001  10:12 PM
> 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.
> 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.
#11 Members  Reputation: 164
Posted 07 August 2001  09:40 AM
Yeah, just wanted to reiterate what I said in plainer language. The point on a body where a force is applied is irrelevant to linear dynamics (well, I think this is true only if the body is rigid, but I''m assuming that''s the case here). Force (F=ma) is in no way dependent on position, but torue (T = r x F) obviously is, because the cross product depends on the length of the vectors r and F and the angle between them (r is a vector from the centre of mass to the point where the force is applied).
The only reason we break forces up into components is because it''s generally easiest for us humans to represent vectors in X, Y and Z components. There is no such thing as a linear or angular component of force.
The only reason we break forces up into components is because it''s generally easiest for us humans to represent vectors in X, Y and Z components. There is no such thing as a linear or angular component of force.
#12 Members  Reputation: 120
Posted 08 August 2001  12:21 AM
Thanks for all, I have now quite working rigid base class.
The interesting point is getting force that affects to a point.
Here''s my old GetForce funtion:
I looked at Chris Heckers rigid physics example. There was an interersting function to get the Impulse.
So I modified my GetForce function:
I don''t quite understand that great chunck of Dot/cross Products yet. I didn''t realize differences in my car''s running so what does this do that the first method doesn''t?
The interesting point is getting force that affects to a point.
Here''s my old GetForce funtion:

I looked at Chris Heckers rigid physics example. There was an interersting function to get the Impulse.
So I modified my GetForce function:

I don''t quite understand that great chunck of Dot/cross Products yet. I didn''t realize differences in my car''s running so what does this do that the first method doesn''t?
#13 Members  Reputation: 347
Posted 08 August 2001  01:01 AM
> I don''t quite understand that great chunck of Dot/cross
> Products yet. I didn''t realize differences in my car''s running
> so what does this do that the first method doesn''t?
What it is supposed to do is work out the impulse experienced by a moving object colliding instantaneously with a fixed object/plane. The inputs include a plane/collision point normal, the object''s initial angular and linear velocity, as well as the position of the impact point relative to the object centre and the moment of inertia tensor.
I don''t know whether that code will work: it looks like it includes everything but the code relies on a number of factors, such all the variables being measured the same way, which aren''t
obvious from the code.
As for its use, it''s the way to (e.g.) work out the impuluse on a car colliding with a wall, or with the floor when rolling over. It''s not as much use for collisions between two moving objects, which requires a similar but more complex calculation.
> Products yet. I didn''t realize differences in my car''s running
> so what does this do that the first method doesn''t?
What it is supposed to do is work out the impulse experienced by a moving object colliding instantaneously with a fixed object/plane. The inputs include a plane/collision point normal, the object''s initial angular and linear velocity, as well as the position of the impact point relative to the object centre and the moment of inertia tensor.
I don''t know whether that code will work: it looks like it includes everything but the code relies on a number of factors, such all the variables being measured the same way, which aren''t
obvious from the code.
As for its use, it''s the way to (e.g.) work out the impuluse on a car colliding with a wall, or with the floor when rolling over. It''s not as much use for collisions between two moving objects, which requires a similar but more complex calculation.