Problem identified:Code:struct Mesh { public: // a pointer to a series of frames LPD3DXFRAME m_Root; }; struct Shape { // Get the best mesh suited for the camera's viewpoint, allows LOD. virtual const Mesh* getMesh( const CCamera& camera ) const = 0; virtual void setMesh(Mesh *mesh) = 0; }; struct WarehouseShape : public Shape { const Mesh* getMesh( const CCamera& camera ) const { return m_pMesh; } void setMesh(Mesh *mesh) { m_pMesh = mesh; } Mesh *m_pMesh; }; struct Object { Shape* shape; bool Load(TCHAR* pFilename); D3DXMATRIX transform; LPD3DXANIMATIONCONTROLLER m_pAnimCtrl; }; bool Object::Load(TCHAR* pFilename) { LPD3DXFRAME frames; CAllocMeshHierarchy Alloc; HRESULT hr = E_FAIL; D3DXLoadMeshHierarchyFromX( pFilename, D3DXMESH_MANAGED, g_pDevice, &Alloc, NULL, &frames, &m_pAnimCtrl ); Mesh mesh; // Set the whole bunch of frames // have tried to copy it using memcpy (&mesh.m_Root, &frames, sizeof(frames)); mesh.m_Root = frames; shape = new WarehouseShape(); shape->setMesh(&mesh); //shape->setMesh(frames); return true; } extern CD3DRenderer g_D3DRenderer; extern LPDIRECT3DDEVICE9 g_pDevice; class Scene { public: Scene() { SetCurCam(0); } ~Scene() { } void Load() { m_Cam[0].Load(g_pDevice, _T("Data\\Others\\Demo1.cam")); m_Cam[1].Load(g_pDevice, _T("Data\\Others\\Demo2.cam")); m_Cam[2].Load(g_pDevice, _T("Data\\Others\\Demo3.cam")); m_WarehouseObject.Load(_T("Data\\DemoWarehouse.x")); m_pRenderObjects.push_back(&m_WarehouseObject); } void SetCurCam(int i) { m_iCurCam = i; } void render() { for (int i = 0; i < m_pRenderObjects.size(); i++) { const Mesh& mesh = *m_pRenderObjects[i]->shape->getMesh(m_Cam[m_iCurCam]); Matrix4 mat = m_pRenderObjects[i]->transform; g_D3DRenderer.render(mesh, mat, m_Cam[m_iCurCam]); } } Object m_WarehouseObject; Object m_CBObject; Object m_OperatorObject; CCamera m_Cam[3]; int m_iCurCam; std::vector<Object *> m_pRenderObjects; };
for (int i = 0; i < m_pRenderObjects.size(); i++)
{
const Mesh& mesh = *m_pRenderObjects[i]->shape->getMesh(m_Cam[m_iCurCam]);
Matrix4 mat = m_pRenderObjects[i]->transform;
g_D3DRenderer.render(mesh, mat, m_Cam[m_iCurCam]);
}
shape has a value of 0xcccccccc
Does anyone know where the problem is?
Thanks
Jack


Reply With Quote
Bookmarks