Jump to content
  • Advertisement
Sign in to follow this  
Say

[DirectX 9] Rotate objects

This topic is 4858 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

I have t orotate objects of a scene, and all the scene. To accomplish to the first task what id the operation i've to do? so rotate the mesh of 100 pixel on X axis. Is the object rotate by its center? If i want to rotate by another point? Then how i could rotate all the scene by the center of the scene?

Share this post


Link to post
Share on other sites
Advertisement
You need to look into matrix mathematics for this - it's very possible to create some powerful transforms using the built in functions [smile]

The simple idea is that you create a D3DXMATRIX struct, which is a standard 4x4 matrix, and compose your transform. More in a second..

Once you've composed your D3DXMATRIX you set it to the current device: IDirect3DDevice::SetTransform( D3DTS_WORLD, &your_matrix_here ). All geometry rendered after that call will be transformed according to your matrix. You can change the matrix any number of times during a given frame - you're not tied to using the same matrix for everything..


To construct a matrix...

Have a look at the list of D3DX Functions beginning with D3DXMatrix...() on this page.

The topic of matrix mathematics is a bit too big to go into here, so I suggest you find a mathematics text book or have a look on Google for some information (if you're not already familiar with them...!)

D3DXMATRIX matWorld;
D3DXMATRIX matTemp;

D3DXMatrixIdentity( &matWorld );

//For each transform (scale, rotate, translate...) you
//want to first set the temporary matrix to the identity
//then perform the operation. Finally you multiply the temporary
//matrix with your "final" matrix.
D3DXMatrixIdentity( &matTemp );
//Perform an operation here
D3DXMatrixMultiply( &matWorld, &matWorld, &matTemp );

//Once you've performed all necessary operations, use the
//'matWorld' variable as the parameter to SetTransform()...



Quote:
Is the object rotate by its center?

It will be rotated about the origin [0,0,0] - which may, or may not, be the center of the object.

Quote:
If i want to rotate by another point?

You need to translate the object before rotating it, such that the point you want to rotate around becomes the same as the origin.

hth
Jack

Share this post


Link to post
Share on other sites
So to rotate by a point that is not thecenter of the object that information is included in d3dxmatrix?

Share this post


Link to post
Share on other sites
Quote:
Original post by Say
So to rotate by a point that is not thecenter of the object that information is included in d3dxmatrix?


An example:
Say you want to rotate the object around the point [x, y, z] by r radians on the y axis, then use this:

D3DXMATRIX matWorld;
D3DXMATRIX matTemp;
D3DXMatrixTranslation( &matWorld, -x, -y, -z );
D3DXMatrixRotationY( &matTemp, r );
D3DXMatrixMultiply( &matWorld, &matWorld, &matTemp );
D3DXMatrixTranslation( &matTemp, x, y, z );
D3DXMatrixMultiply( &matWorld, &matWorld, &matTemp );

pDevice->SetTransform( D3DTS_WORLD, &matWorld );

HTH,
Cambo_frog

Share this post


Link to post
Share on other sites
sorry what does it rappresent matWorld? Just the bounding box that contains all the object in the scene?
And matTemp is a copy of matWorld?

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Say, you will get a better understanding by studying some basic tutorials. Take a look at "Article/Tutorial/Sample sites" topic in DX FAQ. You will find a lot of information about geometric transformations (translating, rotations and scaling) there.

Share this post


Link to post
Share on other sites
Quote:
Original post by Say
sorry what does it rappresent matWorld? Just the bounding box that contains all the object in the scene?
And matTemp is a copy of matWorld?


Hi, Say
Like Anonymous Poster says, you will need to read some 3D graphics tutorials. Don't go for anything DirectX specific to start with, I would recommend getting a general book on 3D graphics to start with, and for your particular problem, read up on "transformations", "matrix", "matrices" and "matrix Concatenation" \ "matrix multiplication". But just start from the beginning of your book (coordinate systems etc) and work your way through, then get back to the DirectX SDK. Don't try to rush and just take your time. Don't move on to the next section until you understand the previous section.

***Edit***
Learning 3D graphics from English language texts is difficult enough for people who speak english as a first language. Try to get a book in French if that is your first language. If you speak Creole, I can imagine it is even more difficult to find a suitable book :)

Good Luck,
Cambo_frog

[Edited by - Cambo_frog on July 25, 2005 6:23:30 PM]

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • 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!