Skip to main content
gamedev.net
🔒 Locked

Transform Vertices

Started by ShadowCoder Oct 5, 2002 at 2:04 AM 0 replies 250+ views
Original Post
ShadowCoder
ShadowCoder
I don''t get why this doesn''t work. Wall is a simple 12 triangle mesh. I use similar code to scale my terain and it works flawlessly. What am I missing?
  
CD3DMesh       *m_pWall;             // Wall Object


// Code from InitDeviceObjects


D3DXMATRIXA16   matx;      
D3DXVECTOR3     vecx;

if( FAILED( m_pWall->Create( m_pd3dDevice, _T("wall2.x") ) ) )
   return D3DAPPERR_MEDIANOTFOUND;

D3DXMatrixTranslation( &matx, 300, 0, 0 ); 

LPDIRECT3DVERTEXBUFFER8 pVB;
if( SUCCEEDED( m_pWall->GetSysMemMesh()
                      ->GetVertexBuffer( &pVB ) ) )
  {
  struct VERTEX { FLOAT x,y,z,tu,tv; };
  VERTEX* pVertices;
  DWORD   dwNumVertices = m_pWall->GetSysMemMesh()
                                 ->GetNumVertices();
  pVB->Lock( 0, 0, (BYTE**)&pVertices, 0 );
  for( DWORD i=0; i<dwNumVertices; i++ )
    {
    vecx.x = pVertices[i].x;
    vecx.y = pVertices[i].y;
    vecx.z = pVertices[i].z;
    D3DXVec3TransformCoord(&vecx,&vecx,&matx); 
    pVertices[i].x = vecx.x;
    pVertices[i].y = vecx.y;
    pVertices[i].z = vecx.z;
    }
  pVB->Unlock();
  pVB->Release();
  }
  
What i get is a bunch of trangles shooting off in all sorts of oddball directions. What I''m trying to do is transform the mesh in the VB so I don''t have to transform it each time I go to render it. This is a static object so it doesn''t make sense to me to have to transform it each time I have to render it. pVertices.x += 300; Doesn''t work either. Shad
ShadowCoder
ShadowCoder
I figured it out.

struct VERTEX { FLOAT x,y,z,tu,tv; };

was the wrong size.

DWORD meshFVF;
UINT uiFVFSize;
meshFVF = m_pWall->GetSysMemMesh()->GetFVF();
uiFVFSize = D3DXGetFVFVertexSize(meshFVF );

gave me the correct size. Sorry this was a waste of perfectly good thread space.

Shad



[edited by - ShadowCoder on October 5, 2002 4:20:51 AM]

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.