Archived

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

CruxMihiAncora

Transforming a single object in the world

Recommended Posts

I was wondering how I would go about translating a single object in the world without effecting the rest of the world. For instance, let''s say I have two triangles (not connected) that I draw to the screen usign DrawPrimitive. How would I make Triangle1 move -5 x units but leave Triangle2 alone? I am using DirectX 8, MSVC++ and Win2k. Any help would be much appreciated. Thanks!

Share this post


Link to post
Share on other sites
Okay, I think I am beginning to understand. When you do a SetTransform to D3DTS_WORLD than that won''t affect anything currently in the world, it will just affect the next draw you do into the world. Does that sound right? Geez, maybe I am actually starting to understand this stuff.

So, I could have a triangle object that contains its own World Matrix and as I move it in the world I just change the object''s World Matrix and then SetTransform and Draw. Right?

Thanks a lot!!!

Share this post


Link to post
Share on other sites
It funny but I have the exact same question. Can someone please give a short code example. A little more specific than what ECKILLER said. Its hard trying to learn from the SDK and NeXe alone...can''t wait till I get my books!

"Ogun''s Laughter Is No Joke!!!" - Ogun Kills On The Right, A Nigerian Poem.

Share this post


Link to post
Share on other sites
Ok, here is come code quickly cobbled together as an example
Here we are rendering an island centered at 0,0,0 (basically untranslated) and the surrounding water, which we translate along y by sine (time) to model water lapping the shores.
        
//Render Island

D3DXMatrixTranslation(&islandMatrix, 0, 0 , 0);
m_pd3dDevice->SetTransform(D3DTS_WORLD, &islandMatrix );
m_pd3dDevice->SetStreamSource( 0, islandVB, sizeof(CUSTOMVERTEX) );
m_pd3dDevice->SetVertexShader( D3DFVF_CUSTOMVERTEX );
m_pd3dDevice->SetIndices( islandIB, 0 );
m_pd3dDevice->DrawIndexedPrimitive( D3DPT_TRIANGLELIST, 0, islandVertices, 0, islandIndices / 3 );

//Render Water Animating in Y direction of sine (time) to crudely simulate waves


D3DXMatrixTranslation(&waterMatrix, 0, sin (time) , 0);
m_pd3dDevice->SetTransform(D3DTS_WORLD, &waterMatrix );
m_pd3dDevice->SetStreamSource( 0, waterVB, sizeof(CUSTOMVERTEX) );
m_pd3dDevice->SetVertexShader( D3DFVF_CUSTOMVERTEX );
m_pd3dDevice->SetIndices( waterIB, 0 );
m_pd3dDevice->DrawIndexedPrimitive( D3DPT_TRIANGLELIST, 0, waterVertices, 0, waterIndices / 3 );


Note this code is meant to be instructional, not effiecient or elegant. Usually I put the world matrix as a member of a Mesh class, and have the mesh update and set its own world matrix before it renders itself. This gives you much nicer to look at and manage code (especially when the number of objects starts to get large).
        
//On Initialize

island->loadHieghtMap ("island.map");
island->MoveTo (0, 0, 0);
...
//On update

water->MoveTo (0, sin(time), 0);
....
//On render

island->render(); //Will set world matrix to its own matrix

water->render(); //Will set world matrix to its own matrix





Edited by - invective on November 4, 2001 10:28:50 AM

Share this post


Link to post
Share on other sites