Sign in to follow this  
tont

newbie problem with DirectX

Recommended Posts

Hello, Im trying to create a small game with a top/down view and im having problems with the controls and rotating it. There are two things, Im having problems turning it around, left and right. and if its at the 'origin', it will turn properly. but if i move it 'forward' and attempt to 'turn it', its not spinning on the origin, but more like its spinning the whole z-axis. Here is the matrix mulitplication im trying to use: device.Transform.World = Matrix.Translation(pos) * Matrix.RotationAxis(new Vector3(0,0,1),tank.getAngle()); pos = a vector3 variable where the tank should be. and then i was under the impression that doing the rotationAxis matrix would spin it on the Z Vector (0,0,1) against the angle. It seems that when im doing the device.transform.world, its actually spinning the whole world, and ive tried spinning it on world1, but it does the same thing. Ive worked with openGL before and before it had to do with pushing and popping matrices to deal with this, but unfortunately, i cant seem to find something like that in directX. If anyone has any insights or tutorials they can point me towards, that would be much appreciated. Thank you in advance.

Share this post


Link to post
Share on other sites
You will have to move your object to the origin then rotate it and then move it back to its current position. You will most probably need D3DXMatrixMultiply to multiply all your matrices together.

Ill try post some code up later.

Share this post


Link to post
Share on other sites
You don't have to move it back, then rotate, then move it again. Just reverse the order of your existing multiplication.

Matrix multiplications kind of read like sentences.


device.Transform.World = Matrix.Translation(pos) * Matrix.RotationAxis(new Vector3(0,0,1),tank.getAngle());



Means "Move the object away from the origin, then rotate it around the Z axis", but the Z axis is now far away from the object, since it exists at the origin.

If you reverse the order you get "Rotate the object around the Z axis, then move it away from the origin".

In short, Move-then-rotate is a revolution, like the Earth around the Sun. Rotate-then-Move is a rotation, like the Earth rotating on its axis at some position in space.

Share this post


Link to post
Share on other sites
That worked! Thank you. But Ive run into another problem and im not sure how this should work out. I have an 'accelerate' function that will increase/decrease the X value that it is on. I was under the impression though that when i do the matrix multiplication, that it actually rotates the graph so the X axis is along whatever line the angle is set at, but its still going down the standard x axis? Any thoughts on how to stop that from happening?

Also, looking further into the future, Ive thought of something. Right now I just have a tank on the screen and it moves around, spinning and what not. But eventually there will be a map on there for it to move around, but with these matrix multiplications, will it spin everything, including the map , around? If so, how would i keep the map stationary and move the tank around? would i first draw the map, then do the matrix mulitplications, then draw the tank? and also, if i do that,would i have to reset the matrix back to the identity matrix? Please give me whateve insight you would be able to. Thank you again for you help!


Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this