// Tom Plick // 24 Jul 2005 #include "mesh.h" #include "d3dUtility.h" D3DXMATRIX rotMatrix; Mesh::Mesh(IDirect3DDevice9* device, char * xfilename) { this->Device = device; HRESULT result = D3DXLoadMeshFromX( xfilename, D3DXMESH_MANAGED, device, &buf_adjacency, &buf_materials, NULL, // effect instances &num_materials, &dx_mesh); bright_material = d3d::InitMtrl(0x00ff00ff, 0x00ff00ff, 0x00ff00ff, 0x00ff00ff, 1.0f); } Mesh::~Mesh() { buf_materials->Release(); buf_adjacency->Release(); dx_mesh->Release(); } void Mesh::Draw(double x, double y, double z, bool rotate, double angle) { D3DXMATRIX W; D3DXMatrixTranslation(&W, (float) x, (float) y, (float) z); if (rotate){ D3DXMatrixRotationX(&::rotMatrix, angle); // W *= ::rotMatrix; W = rotMatrix * W; } Device->SetTransform(D3DTS_WORLD, &W); D3DXMATERIAL* mtrls = (D3DXMATERIAL*) buf_materials->GetBufferPointer(); Device->SetTexture(0, 0); for (DWORD mat = 0; mat < num_materials; mat++){ Device->SetMaterial(&mtrls[mat].MatD3D); dx_mesh->DrawSubset(mat); } } ID3DXMesh * Mesh::getMesh() { return dx_mesh; }