Public Group

# movement in 3D space issues

This topic is 4089 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

hi folks. i'm currently working on a 3D racing game for a university project, and right now i'm trying to get the motion down. basicly, i've got the model of my car moving forwards and back, however, when i come to turn the car, i can't figure it out. i can rotate teh mesh on the spot, but from what i can fogure, to get to to turn, and then move in the new "forwards" direction, is going to need some kind of matrix multiplication or something, right? my question is simply, where can i find info on how to do that? because frankly i'm rubbish at this kind of maths, and i really need to learn it for this. also, i'm currently using Visual studio 2005 (full, not express) and am working in C++ and Directx, so tutorials in those languages would be most useful. i got hold of the following set of matrix opperations from a tutorial: D3DXMatrixTranslation(&matTranslation, Racer.Position.x, Racer.Position.y, Racer.Position.z); D3DXMatrixRotationX(&matRotationX, Racer.RotX); D3DXMatrixRotationY(&matRotationY, Racer.RotY); D3DXMatrixRotationZ(&matRotationZ, Racer.RotZ); D3DXMatrixScaling(&matScale, 1, 1, 1); D3DXMatrixMultiply(&TempMatrix1, &matRotationZ, &matRotationX); D3DXMatrixMultiply(&TempMatrix2, &matRotationY, &TempMatrix1); D3DXMatrixMultiply(&matTransform, &TempMatrix2, &matTranslation); g_pd3dDevice->SetTransform(D3DTS_WORLD,&matTransform ); Racer.renderMesh(g_pd3dDevice); my problem is, i don't know how to use them propperly :( Thanks in advance, Mal'

##### Share on other sites
Movement in 3D is all about vectors and high school physics:

vel = at + v0
pos = vel*t + s0;

t = time
a = acceleration vector
vel = velocity vector this frame
v0 = velocity vector last frame
s0 = position vector last frame

add in whatever other physics you need for friction, drag, etc.

You can do similar equations for rotational velocity and such. Alternately you can just use a simple "speed" scalar for motion and rotate a heading vector (which you then transform by those physics equation to get the new position for this frame).

For tutorials you just want to google on: "Linear Algebra Tutorial". And I found it helps to buy a high school or college physics text for reference (or raid your basement for your old texts).

-me

##### Share on other sites
moving in a straight line isn't my problem, i've implimented acceleration based on applying a force, taking into account mass and friction. my problem is turning, and then having the object (car) move in the new "forward" direction. which doesn't happen, the object turns on the spot, and continues on it's merry way in the direction it was previously headed.

##### Share on other sites
Yeah, was just editing my post to account for that. Basically, you need to learn some basic linear algebra. Once you have a heading vector and know how to rotate it, everything else is easy. Just spend a few days learning the basics of vectors and matrices and it should become apparent.

More or less you just calculate the rotation this frame and then rotate the heading vector to account for that. If you manage your speed as a scalar then a naive algorithm could be:

1) calculate new heading vector
2) scale heading vector by speed to get the new position.

That'll be close enough for government work.

There's more physics oriented approaches that would involve rigid body rotation and the like (rotational equivalents of the d = 1/2at^2 _v0t + s0 equation). Best to look those up in a physics text; my memory of them is shoddy.

[EDIT: there's also a pretty thorough article on race car physics somewhere in the Article & Resources section of this site]

-me

1. 1
Rutin
23
2. 2
3. 3
JoeJ
20
4. 4
5. 5

• 29
• 40
• 23
• 13
• 13
• ### Forum Statistics

• Total Topics
631739
• Total Posts
3001957
×