Jump to content
  • Advertisement


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


Anyone can correct this?

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

I think this class may have a bug. Any one can help me find bug. Because when i create this object class .Use it to to render many screen but it slow fps(~=5fps) in some screen while another not slow(~=40fps). Note:i use Beginning Direct3D Game Programming Book //***** class CXObject { public: CXObject(); ~CXObject(); //variables public: Object m_MeshObject; LPDIRECT3DVERTEXBUFFER8 m_pVB; // Buffers to hold vertices DWORD m_dwNumVertices; DWORD m_dwNumFaces; LPDIRECT3DINDEXBUFFER8 m_pIB; D3DXMATRIX m_combinedMat; D3DXMATRIX m_matWorld ,m_matScaling ,m_matTranslation; //Picking float m_fPickT,m_fPickU,m_fPickV; DWORD m_dwNumPickedTriangles; //method public: HRESULT InitLocationRotationVector(D3DXVECTOR3 v3Loc,D3DXVECTOR3 v3Rot); HRESULT InitDeviceObjects(LPDIRECT3DDEVICE8 pd3dDevice,char * strXFileName); HRESULT RestoreDeviceObjects(LPDIRECT3DDEVICE8 pd3dDevice); HRESULT InvalidateDeviceObjects(); HRESULT DeleteDeviceObjects(); HRESULT FinalCleanup(); HRESULT Render(LPDIRECT3DDEVICE8 pd3dDevice); HRESULT SetLocation(D3DXVECTOR3 v3Loc); HRESULT SetScaling(D3DXVECTOR3 v3Scaling); }; CXObject::CXObject() { m_pVB = NULL; m_pIB = NULL; m_MeshObject.mesh=new CD3DMesh(); m_fPickT=0.0f; m_fPickU=0.0f; m_fPickV=0.0f; //SetScaling(D3DXVECTOR3(1.0f,1.0f,1.0f)); //SetLocation(D3DXVECTOR3(0.0f,0.0f,0.0f)); } CXObject::~CXObject() { if(m_pVB && m_pIB && m_MeshObject.mesh) { DeleteDeviceObjects(); FinalCleanup(); } } HRESULT CXObject::InitLocationRotationVector(D3DXVECTOR3 v3Loc,D3DXVECTOR3 v3Rot) { D3DXMATRIX matTemp; m_MeshObject.vLoc = v3Loc ; m_MeshObject.vR= v3Rot; //set initial translation D3DXMatrixTranslation(&matTemp, m_MeshObject.vLoc.x, m_MeshObject.vLoc.y, m_MeshObject.vLoc.z); m_matTranslation=matTemp; //assign to object member -> m_matTranslation return S_OK; } HRESULT CXObject::InitDeviceObjects(LPDIRECT3DDEVICE8 pd3dDevice,char * strXFileName) { //Load X file if( FAILED(m_MeshObject.mesh->Create( pd3dDevice, _T(strXFileName) ) ) ) return E_FAIL; //set FVF m_MeshObject.mesh->SetFVF( pd3dDevice, FVF_CUSTOMVERTEX); //Get num..... m_dwNumVertices = m_MeshObject.mesh->GetSysMemMesh()->GetNumVertices(); m_dwNumFaces = m_MeshObject.mesh->GetSysMemMesh()->GetNumFaces(); //set vertex buffer m_MeshObject.mesh->GetSysMemMesh()->GetVertexBuffer( &m_pVB); //set index buffer m_MeshObject.mesh->GetSysMemMesh()->GetIndexBuffer( &m_pIB); //initial object material D3DUtil_InitMaterial(m_MeshObject.mtrl, m_MeshObject.mesh->m_pMaterials[0].Diffuse.r, m_MeshObject.mesh->m_pMaterials[0].Diffuse.g, m_MeshObject.mesh->m_pMaterials[0].Diffuse.b, m_MeshObject.mesh->m_pMaterials[0].Diffuse.a); return S_OK; } HRESULT CXObject::RestoreDeviceObjects(LPDIRECT3DDEVICE8 pd3dDevice) { m_MeshObject.mesh->RestoreDeviceObjects( pd3dDevice ); return S_OK; } HRESULT CXObject::InvalidateDeviceObjects() { m_MeshObject.mesh->InvalidateDeviceObjects(); return S_OK; } HRESULT CXObject::DeleteDeviceObjects() { m_MeshObject.mesh->Destroy(); SAFE_RELEASE( m_pVB); SAFE_RELEASE( m_pIB); return S_OK; } HRESULT CXObject::FinalCleanup() { SAFE_DELETE( m_MeshObject.mesh); return S_OK; } HRESULT CXObject::Render(LPDIRECT3DDEVICE8 pd3dDevice) { D3DXMATRIX matTemp; //multiply scaling and trans together D3DXMatrixMultiply( &matTemp, &m_matScaling, &m_matTranslation ); m_MeshObject.matLocal = matTemp; //apply to object (matLocal) pd3dDevice->SetTransform(D3DTS_WORLD, &m_MeshObject.matLocal ); m_MeshObject.mesh->Render(pd3dDevice); return S_OK; } HRESULT CXObject::SetLocation(D3DXVECTOR3 v3Loc) { D3DXMATRIX matTemp; // m_MeshObject.vLoc.x=v3Loc.x; // m_MeshObject.vLoc.y=v3Loc.y; // m_MeshObject.vLoc.z=v3Loc.z; D3DXMatrixTranslation(&matTemp, v3Loc.x, v3Loc.y, v3Loc.z); m_matTranslation=matTemp; return S_OK; } HRESULT CXObject::SetScaling(D3DXVECTOR3 v3Scaling) { D3DXMATRIX matTemp; D3DXMatrixScaling(&matTemp,v3Scaling.x,v3Scaling.y,v3Scaling.z); //create scaling matrix m_matScaling=matTemp; return S_OK; } }

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!