#### Archived

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

# how do i rotate

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

## Recommended Posts

hi. how do i do to rotate an object and translate it without changing and distort the y,x,z axis?. i want the object to rotate on the zero y and x axis and still be translated. Edited by - Funkodysse on November 19, 2001 4:03:57 AM Edited by - funkodysse on November 19, 2001 4:05:05 AM

##### Share on other sites
Have a look at the SDK helpfile - it''s all in there...you might wanna read up a bit on matrices aswell if you haven''t..

##### Share on other sites
Push your matrix on the stack, rotate, translate, draw your object, then pop the matrix.

The translation will happen in the rotated coordinate system.

Edited by - Fruny on November 19, 2001 4:42:11 AM

##### Share on other sites
well im new to 3D.

ok i took a look at the sdk, it said something about the order of matrixmultiply, but ít didnt help. where should i look?

##### Share on other sites
if(raknare>100)raknare=0;
raknare=raknare+(float)0.004;

CUSTOMVERTEX g_Vertices[] =
{
{ 0.0f,0.0f, 0.0f,D3DCOLOR_XRGB(0,255,0) }, // x,y,z,color
{ 1.0f,0.0f, 0.0f,D3DCOLOR_XRGB(0,0,255) },
{ 1.0f,1.0f, 0.0f,0xffffffff },
{ 0.0f,1.0f, 0.0f,D3DCOLOR_XRGB(0,255,0) },
{ 0.0f,0.0f, 0.0f,D3DCOLOR_XRGB(255,0,0) },

{ 0.0f,0.0f, -1.0f,D3DCOLOR_XRGB(0,0,255) }, // x,y,z,color
{ 1.0f,0.0f, -1.0f,D3DCOLOR_XRGB(255,255,0) },
{ 1.0f,1.0f, -1.0f,D3DCOLOR_XRGB(0,255,255) },
{ 0.0f,1.0f, -1.0f,D3DCOLOR_XRGB(255,0,0) },
{ 0.0f,0.0f, -1.0f,D3DCOLOR_XRGB(255,255,0) },

};

g_pVB->Lock( 0, sizeof(g_Vertices), (BYTE**)&pVertices, 0 );
memcpy( pVertices, g_Vertices, sizeof(g_Vertices));
g_pVB->Unlock();

g_pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0,0,0), 1.0f, 0 );
g_pd3dDevice->BeginScene();
D3DXMATRIX Worldrotate;
D3DXMATRIX Worldtranslate;
D3DXMATRIX matWorld;

D3DXMatrixTranslation(&Worldtranslate, raknare, 0, 0);
D3DXMatrixRotationYawPitchRoll(&Worldrotate, raknare, 0, 0);
D3DXMatrixMultiply(&matWorld, &Worldtranslate, &Worldrotate);

g_pd3dDevice->SetTransform( D3DTS_WORLD, &matWorld );

what this code does is rotate the object around its own x axis, and translating it around its "own" x axis, this is no good, i want to translate it around the "world" x axis and rotate itself around its "own" x axis. how do i do that?

Edited by - Funkodysse on November 19, 2001 4:53:34 AM

##### Share on other sites
Ah.

Translate, then rotate.

##### Share on other sites
But i do that, look at the matrixmultiply. but it aint working, what shall i do?

##### Share on other sites
You have 3 choices

- rotate then translate : rotate then translate along the new X axis.
- translate then rotate : translate along the original X axis, then rotate in place.

- work out the math of the actual transformation you want on a sheet of paper. Then use the above to do it.

##### Share on other sites
ok. choosed
- translate then rotate
as i did in the code. but it trabslate itself around the new axis.
could you please tell med whats wrong with the code?

##### Share on other sites
AAAAAAH forgive me.
now i understand... i thought
D3DXMatrixMultiply(&matWorld, &Worldrotate, &Worldtranslate)

that number 2 parameter was to be processed first and then the third but it was the other way around... hehe..ok now its working good..
thanks.

1. 1
Rutin
29
2. 2
3. 3
4. 4
5. 5

• 13
• 13
• 11
• 10
• 14
• ### Forum Statistics

• Total Topics
632961
• Total Posts
3009494
• ### Who's Online (See full list)

There are no registered users currently online

×