• Advertisement

Archived

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

how do i rotate

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

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 this post


Link to post
Share on other sites
Advertisement
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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.

Share this post


Link to post
Share on other sites

  • Advertisement