how do i rotate

Started by
8 comments, last by Funkodysse 22 years, 5 months ago
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
Advertisement
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..
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
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
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?
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
Ah.

Translate, then rotate.
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
But i do that, look at the matrixmultiply. but it aint working, what shall i do?
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.
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
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?
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.

This topic is closed to new replies.

Advertisement