Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.



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

If you intended to correct an error in the post then please contact us.

Recommended Posts

This is accomplished through matrix multiplication. Every object in the scene will have its own transformation matrix. To move or rotate an object relative to its current position you have to create a second matrix that contains the relative movement/rotation. Then they are combined by multiplying the two matrices. The resulting matrix is the objects new transformation matrix this is what will be used to render the object.

For instance to move an object using the keyboard by a set vector distance:

//Get Keyboard Input

object_matrix = MatrixMult(CreateTranslationMatrix(D3DVECTOR(-STEP,0.0,0.0)),object_matrix);

object_matrix = MatrixMult(CreateTranslationMatrix(D3DVECTOR(STEP,0.0,0.0)),object_matrix);

object_matrix = MatrixMult(CreateTranslationMatrix(D3DVECTOR(0.0,0.0,-STEP)),object_matrix);

object_matrix = MatrixMult(CreateTranslationMatrix(D3DVECTOR(0.0,0.0,STEP)),object_matrix);

The above code uses two functions:
MatrixMult - multiplys the two matrices together and returns the result.
CreateTranslationMatrix - creates a translation (position) matrix based on the given vector.

The above code would be a hell of a lot faster if flags were set if keys are pressed and then only call the matrixmult/createtranslationmatrix functions once with the final vector.

Also keep in mind that matrix multiplication is not commutative(sp?). It means that the order in which the multiplication takes place matters.

M1*M2 != M2*M1

This makes sense because if you turn right and take ten steps you will be in a different place than if you had taken 10 steps then turned right.

So basically you need to understand a little linear algebra. Also, Depending on if you are in a left or right hand coordinate system the construction of the matrix is a little different.

There is some matrix information in the Direct3D documentation or if you are using OpenGL take a look at chapter three in the Red Book [http://fly.cc.fer.hr/~unreal/theredbook/]

Good Luck

Oh yeah, If you have the DirectX SDK then do a search for 'D3DMath' it has all the functions you would need.

Share this post

Link to post
Share on other sites
Ok, I must have been smoking something wierd when I posted the message.

I want to know how to move something "forward" in 3d space? If it has a direction vector and a position vector how do I accomplish this?


Share this post

Link to post
Share on other sites


That is what I needed to know. Now I understand fully. So, I just need to multiply the new matrix by the current one to get the result I need!

Much Thanks!!!!!!!

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!