#include "dxstdafx.h" #include ".\physxdebugrenderer.h" PhysXDebugRenderer::PhysXDebugRenderer(void) { } PhysXDebugRenderer::~PhysXDebugRenderer(void) { } void PhysXDebugRenderer::setDevice(IDirect3DDevice9 &_device) { this->device = &_device; } void PhysXDebugRenderer::render(const NxDebugRenderable &data) { if(this->device==NULL) this->device = DXUTGetD3DDevice(); this->device->BeginScene(); this->device->SetRenderState( D3DRS_LIGHTING, FALSE ); this->device->SetRenderState(D3DRS_FILLMODE, D3DFILL_WIREFRAME); // Render points { NxU32 NbPoints = data.getNbPoints(); if(NbPoints!=0) { const NxDebugPoint* Points = data.getPoints(); IDirect3DVertexBuffer9 *pBigSquareVB; this->device->CreateVertexBuffer( NbPoints*sizeof(CUSTOMVERTEX), D3DUSAGE_WRITEONLY, VertexFVF, D3DPOOL_DEFAULT, &pBigSquareVB, NULL ); //Set the values for each vertex. CUSTOMVERTEX * vList; pBigSquareVB->Lock( 0, 0, (VOID**)&vList, 0 ); for(UINT i=0;ip.x; vList[i].y = Points->p.y; vList[i].z = Points->p.z; vList[i].diffuse = Points->color; Points++; } pBigSquareVB->Unlock(); this->device->SetFVF(VertexFVF); this->device->SetStreamSource(0, pBigSquareVB, 0, sizeof(CUSTOMVERTEX)); this->device->DrawPrimitive(D3DPT_POINTLIST, 0 ,NbPoints); pBigSquareVB->Release(); } } // Render lines { NxU32 NbLines = data.getNbLines(); if(NbLines!=0) { const NxDebugLine* Lines = data.getLines(); IDirect3DVertexBuffer9 *pBigSquareVB; this->device->CreateVertexBuffer( 2*NbLines*sizeof(CUSTOMVERTEX), D3DUSAGE_WRITEONLY, VertexFVF, D3DPOOL_DEFAULT, &pBigSquareVB, NULL ); //Set the values for each vertex. CUSTOMVERTEX * vList; pBigSquareVB->Lock( 0, 0, (VOID**)&vList, 0 ); for(UINT i=0;i<2*NbLines;i+=2) { vList[i].x = Lines->p0.x; vList[i].y = Lines->p0.y; vList[i].z = Lines->p0.z; vList[i+1].x = Lines->p1.x; vList[i+1].y = Lines->p1.y; vList[i+1].z = Lines->p1.z; vList[i].diffuse = Lines->color; vList[i+1].diffuse = Lines->color; Lines++; } pBigSquareVB->Unlock(); this->device->SetFVF(VertexFVF); this->device->SetStreamSource(0, pBigSquareVB, 0, sizeof(CUSTOMVERTEX)); this->device->DrawPrimitive(D3DPT_LINELIST, 0 ,NbLines); pBigSquareVB->Release(); } } // Render triangles { NxU32 NbTris = data.getNbTriangles(); if(NbTris!=0) { const NxDebugTriangle* Triangles = data.getTriangles(); IDirect3DVertexBuffer9 *pBigSquareVB; this->device->CreateVertexBuffer( 3*NbTris*sizeof(CUSTOMVERTEX), D3DUSAGE_WRITEONLY, VertexFVF, D3DPOOL_DEFAULT, &pBigSquareVB, NULL ); //Set the values for each vertex. CUSTOMVERTEX * vList; pBigSquareVB->Lock( 0, 0, (VOID**)&vList, 0 ); for(UINT i=0;i<3*NbTris;i+=3) { vList[i].x = Triangles->p0.x; vList[i].y = Triangles->p0.y; vList[i].z = Triangles->p0.z; vList[i+1].x = Triangles->p1.x; vList[i+1].y = Triangles->p1.y; vList[i+1].z = Triangles->p1.z; vList[i+2].x = Triangles->p2.x; vList[i+2].y = Triangles->p2.y; vList[i+2].z = Triangles->p2.z; vList[i].diffuse = Triangles->color; vList[i+1].diffuse = Triangles->color; vList[i+2].diffuse = Triangles->color; Triangles++; } pBigSquareVB->Unlock(); this->device->SetFVF(VertexFVF); this->device->SetStreamSource(0, pBigSquareVB, 0, sizeof(CUSTOMVERTEX)); this->device->DrawPrimitive(D3DPT_LINELIST, 0 ,NbTris); pBigSquareVB->Release(); } } this->device->SetRenderState( D3DRS_LIGHTING, TRUE ); this->device->SetRenderState(D3DRS_FILLMODE, D3DFILL_SOLID); this->device->EndScene(); }