ZHaDoom Posted July 12, 2003 Posted July 12, 2003 I am rendering multiple X Meshes. Each requires me to move the world and rotate before I Render the object. I can rotate and move back to the center of the world for my point of referance, but eventualy i get a roundering error with a visual byproduct. They must be an easier way to recenter the object world. What am i missing?:confused: Thanks ZHaDoom void cXObject::Render(D3DXVECTOR3 m_dvPosition,D3DXVECTOR3 m_dvRotation) { D3DXMATRIXA16 matWorld; D3DXMATRIXA16 matWorldY; //Move to object location D3DXMatrixTranslation(&matWorld,m_dvPosition.x,m_dvPosition.y,m_dvPosition.z); l_pd3dDevice->MultiplyTransform(D3DTS_WORLD, &matWorld); //Rotate object D3DXMatrixRotationY( &matWorldY, m_dvRotation.y ); l_pd3dDevice->MultiplyTransform(D3DTS_WORLD, &matWorldY); //Render Object for( DWORD i=0; i<NumMaterials; i++ ) { // Set the material and texture for this subset l_pd3dDevice->SetMaterial( &Materials[i] ); l_pd3dDevice->SetTexture( 0, Textures[i] ); // Draw the mesh subset Mesh->DrawSubset( i ); } //Unrotate D3DXMatrixRotationY( &matWorldY, -m_dvRotation.y ); l_pd3dDevice->MultiplyTransform(D3DTS_WORLD, &matWorldY); //Move back to center of world space D3DXMatrixTranslation(&matWorld,-m_dvPosition.x,-m_dvPosition.y,-m_dvPosition.z); l_pd3dDevice->MultiplyTransform(D3DTS_WORLD, &matWorld); return; } Quote
*Experts* Nerseus Posted July 13, 2003 *Experts* Posted July 13, 2003 I usually start with an identity matrix and multiply by the rotation for each object (or have each object store it's current world matrix). Having to "unturn" the world matrix so the next mesh can use it is bound to cause problems. I've seen references where others use a counter and re-initialize the world matrix to an identity only after x number of iterations. Never tried it myself though. -Ner Quote "I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
ZHaDoom Posted July 13, 2003 Author Posted July 13, 2003 hmm. Sounds right. Now i just need to figure out how to have seperate "world_matrix" for each object. Ive try setting the world matrix to the identy matrix but it seems to be from the last rendered object. I'll play around and get back with you. Thanks ZHaDoom :-\Nerseus, Thanks for the quick repley. Quote
ZHaDoom Posted July 14, 2003 Author Posted July 14, 2003 Still Dazed and Confused Ok help me out. I setup what i think are sepearte world matrixs for each module. But when i render them it still moves based on the last render location. I only call CalcMatrix when I Create the object. Ack. ZHaDoom. //Call To Create an object cModuleptr m_ptrModule; D3DXVECTOR3 m_D3DXVECTOR3(0,0,0); D3DXVECTOR3 m_D3DXVRotation (0,0,0); m_ptrModule=new cModule(); m_ptrModule->Vector=m_D3DXVECTOR3; m_ptrModule->Rotation=m_D3DXVRotation; m_ptrModule->ptrMesh=&g_PowerStation; m_ptrModule->CalcMatrix(); g_StartModule=m_ptrModule; // Module Class cModule* ptrNext; cXObject* ptrMesh; D3DXMATRIXA16 matModule; void cModule::CalcMatrix(void) { //Create World matrix for this module D3DXMatrixIdentity(&matModule); D3DXMatrixTranslation(&matModule,Vector.x,Vector.y,Vector.z); } void cModule::Render(void) { D3DXMATRIXA16 matWorld; //Try to recenter world (dosen't appear to do anything ) D3DXMatrixIdentity(&matWorld); ptrMesh->l_pd3dDevice->MultiplyTransform(D3DTS_WORLD, &matWorld); //Move to Modual World space (still moving from last render =( ptrMesh->l_pd3dDevice->MultiplyTransform(D3DTS_WORLD, &matModule); //Render Module for( DWORD i=0; i<ptrMesh->NumMaterials; i++ ) { // Set the material and texture for this subset ptrMesh->l_pd3dDevice->SetMaterial( &ptrMesh->Materials[i] ); ptrMesh->l_pd3dDevice->SetTexture( 0, ptrMesh->Textures[i] ); // Draw the mesh subset ptrMesh->Mesh->DrawSubset( i ); } return ; } Quote
ZHaDoom Posted July 16, 2003 Author Posted July 16, 2003 Got it. Something simple =) I should have been using SetTransform instead of MultiplyTransform. void cModule::Render(void) { ptrMesh->l_pd3dDevice->SetTransform(D3DTS_WORLD, &matModule); for( DWORD i=0; i<ptrMesh->NumMaterials; i++ ) { // Set the material and texture for this subset ptrMesh->l_pd3dDevice->SetMaterial( &ptrMesh->Materials[i] ); ptrMesh->l_pd3dDevice->SetTexture( 0, ptrMesh->Textures[i] ); // Draw the mesh subset ptrMesh->Mesh->DrawSubset( i ); } return ; } Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.