[1378] | 1 | #include "dxstdafx.h"
|
---|
| 2 | #include ".\physxdebugrenderer.h"
|
---|
| 3 |
|
---|
| 4 | PhysXDebugRenderer::PhysXDebugRenderer(void)
|
---|
| 5 | {
|
---|
| 6 | }
|
---|
| 7 |
|
---|
| 8 | PhysXDebugRenderer::~PhysXDebugRenderer(void)
|
---|
| 9 | {
|
---|
| 10 | }
|
---|
| 11 |
|
---|
| 12 | void PhysXDebugRenderer::setDevice(IDirect3DDevice9 &_device)
|
---|
| 13 | {
|
---|
| 14 | this->device = &_device;
|
---|
| 15 | }
|
---|
| 16 |
|
---|
| 17 | void PhysXDebugRenderer::render(const NxDebugRenderable &data)
|
---|
| 18 | {
|
---|
| 19 | if(this->device==NULL)
|
---|
| 20 | this->device = DXUTGetD3DDevice();
|
---|
| 21 |
|
---|
| 22 | this->device->BeginScene();
|
---|
| 23 | this->device->SetRenderState( D3DRS_LIGHTING, FALSE );
|
---|
| 24 | this->device->SetRenderState(D3DRS_FILLMODE, D3DFILL_WIREFRAME);
|
---|
| 25 | // Render points
|
---|
| 26 | {
|
---|
| 27 | NxU32 NbPoints = data.getNbPoints();
|
---|
| 28 | if(NbPoints!=0) {
|
---|
| 29 | const NxDebugPoint* Points = data.getPoints();
|
---|
| 30 | IDirect3DVertexBuffer9 *pBigSquareVB;
|
---|
| 31 | this->device->CreateVertexBuffer( NbPoints*sizeof(CUSTOMVERTEX), D3DUSAGE_WRITEONLY, VertexFVF, D3DPOOL_DEFAULT, &pBigSquareVB, NULL );
|
---|
| 32 |
|
---|
| 33 | //Set the values for each vertex.
|
---|
| 34 | CUSTOMVERTEX * vList;
|
---|
| 35 | pBigSquareVB->Lock( 0, 0, (VOID**)&vList, 0 );
|
---|
| 36 |
|
---|
| 37 | for(UINT i=0;i<NbPoints;i++) {
|
---|
| 38 | vList[i].x = Points->p.x;
|
---|
| 39 | vList[i].y = Points->p.y;
|
---|
| 40 | vList[i].z = Points->p.z;
|
---|
| 41 | vList[i].diffuse = Points->color;
|
---|
| 42 | Points++;
|
---|
| 43 | }
|
---|
| 44 |
|
---|
| 45 | pBigSquareVB->Unlock();
|
---|
| 46 |
|
---|
| 47 | this->device->SetFVF(VertexFVF);
|
---|
| 48 | this->device->SetStreamSource(0, pBigSquareVB, 0, sizeof(CUSTOMVERTEX));
|
---|
| 49 | this->device->DrawPrimitive(D3DPT_POINTLIST, 0 ,NbPoints);
|
---|
| 50 |
|
---|
| 51 | pBigSquareVB->Release();
|
---|
| 52 | }
|
---|
| 53 | }
|
---|
| 54 | // Render lines
|
---|
| 55 | {
|
---|
| 56 | NxU32 NbLines = data.getNbLines();
|
---|
| 57 | if(NbLines!=0) {
|
---|
| 58 | const NxDebugLine* Lines = data.getLines();
|
---|
| 59 |
|
---|
| 60 | IDirect3DVertexBuffer9 *pBigSquareVB;
|
---|
| 61 | this->device->CreateVertexBuffer( 2*NbLines*sizeof(CUSTOMVERTEX), D3DUSAGE_WRITEONLY, VertexFVF, D3DPOOL_DEFAULT, &pBigSquareVB, NULL );
|
---|
| 62 |
|
---|
| 63 | //Set the values for each vertex.
|
---|
| 64 | CUSTOMVERTEX * vList;
|
---|
| 65 | pBigSquareVB->Lock( 0, 0, (VOID**)&vList, 0 );
|
---|
| 66 |
|
---|
| 67 | for(UINT i=0;i<2*NbLines;i+=2) {
|
---|
| 68 | vList[i].x = Lines->p0.x;
|
---|
| 69 | vList[i].y = Lines->p0.y;
|
---|
| 70 | vList[i].z = Lines->p0.z;
|
---|
| 71 | vList[i+1].x = Lines->p1.x;
|
---|
| 72 | vList[i+1].y = Lines->p1.y;
|
---|
| 73 | vList[i+1].z = Lines->p1.z;
|
---|
| 74 | vList[i].diffuse = Lines->color;
|
---|
| 75 | vList[i+1].diffuse = Lines->color;
|
---|
| 76 | Lines++;
|
---|
| 77 | }
|
---|
| 78 |
|
---|
| 79 | pBigSquareVB->Unlock();
|
---|
| 80 |
|
---|
| 81 | this->device->SetFVF(VertexFVF);
|
---|
| 82 | this->device->SetStreamSource(0, pBigSquareVB, 0, sizeof(CUSTOMVERTEX));
|
---|
| 83 | this->device->DrawPrimitive(D3DPT_LINELIST, 0 ,NbLines);
|
---|
| 84 |
|
---|
| 85 | pBigSquareVB->Release();
|
---|
| 86 | }
|
---|
| 87 | }
|
---|
| 88 | // Render triangles
|
---|
| 89 | {
|
---|
| 90 | NxU32 NbTris = data.getNbTriangles();
|
---|
| 91 | if(NbTris!=0) {
|
---|
| 92 | const NxDebugTriangle* Triangles = data.getTriangles();
|
---|
| 93 |
|
---|
| 94 | IDirect3DVertexBuffer9 *pBigSquareVB;
|
---|
| 95 | this->device->CreateVertexBuffer( 3*NbTris*sizeof(CUSTOMVERTEX), D3DUSAGE_WRITEONLY, VertexFVF, D3DPOOL_DEFAULT, &pBigSquareVB, NULL );
|
---|
| 96 |
|
---|
| 97 | //Set the values for each vertex.
|
---|
| 98 | CUSTOMVERTEX * vList;
|
---|
| 99 | pBigSquareVB->Lock( 0, 0, (VOID**)&vList, 0 );
|
---|
| 100 |
|
---|
| 101 | for(UINT i=0;i<3*NbTris;i+=3) {
|
---|
| 102 | vList[i].x = Triangles->p0.x;
|
---|
| 103 | vList[i].y = Triangles->p0.y;
|
---|
| 104 | vList[i].z = Triangles->p0.z;
|
---|
| 105 | vList[i+1].x = Triangles->p1.x;
|
---|
| 106 | vList[i+1].y = Triangles->p1.y;
|
---|
| 107 | vList[i+1].z = Triangles->p1.z;
|
---|
| 108 | vList[i+2].x = Triangles->p2.x;
|
---|
| 109 | vList[i+2].y = Triangles->p2.y;
|
---|
| 110 | vList[i+2].z = Triangles->p2.z;
|
---|
| 111 | vList[i].diffuse = Triangles->color;
|
---|
| 112 | vList[i+1].diffuse = Triangles->color;
|
---|
| 113 | vList[i+2].diffuse = Triangles->color;
|
---|
| 114 | Triangles++;
|
---|
| 115 | }
|
---|
| 116 |
|
---|
| 117 | pBigSquareVB->Unlock();
|
---|
| 118 |
|
---|
| 119 | this->device->SetFVF(VertexFVF);
|
---|
| 120 | this->device->SetStreamSource(0, pBigSquareVB, 0, sizeof(CUSTOMVERTEX));
|
---|
| 121 | this->device->DrawPrimitive(D3DPT_LINELIST, 0 ,NbTris);
|
---|
| 122 |
|
---|
| 123 | pBigSquareVB->Release();
|
---|
| 124 | }
|
---|
| 125 | }
|
---|
| 126 | this->device->SetRenderState( D3DRS_LIGHTING, TRUE );
|
---|
| 127 | this->device->SetRenderState(D3DRS_FILLMODE, D3DFILL_SOLID);
|
---|
| 128 | this->device->EndScene();
|
---|
| 129 | } |
---|