source: GTP/trunk/App/Games/Jungle_Rumble/src/Box.cpp @ 1378

Revision 1378, 2.7 KB checked in by giegl, 18 years ago (diff)

GTPD - Jungle Rumble - integrate into GTP SVN structure

Line 
1#include "dxstdafx.h"
2#include ".\box.h"
3#include "Scene.h"
4
5Box::Box(void) : Object3d()
6{
7        this->halfWidth = 2;
8        this->halfHeight = 2;
9        this->halfDepth = 2;
10
11        LPD3DXMESH * pMesh = this->getMesh();
12        HRESULT hr = 0;
13
14        hr = D3DXCreateMeshFVF(12, 8, D3DXMESH_MANAGED, this->FVF_Flags, DXUTGetD3DDevice(), pMesh);
15        this->nodeType |= Scene::NODE_BOX;
16}
17
18Box::~Box(void)
19{
20}
21
22void Box::setDimension(float _width, float _height, float _depth)
23{
24        this->halfWidth = _width/2;
25        this->halfHeight = _height/2;
26        this->halfDepth = _depth/2;
27
28        LPD3DXMESH * pMesh = this->getMesh();
29
30        Vertex* pVertices;
31       
32        //lock vertex buffer
33        (*pMesh)->LockVertexBuffer( 0, (void**)&pVertices );
34
35        pVertices[0] = Vertex(-this->halfWidth, -this->halfHeight, this->halfDepth);
36        pVertices[1] = Vertex(-this->halfWidth, -this->halfHeight, -this->halfDepth);
37        pVertices[2] = Vertex(this->halfWidth, -this->halfHeight, -this->halfDepth);
38        pVertices[3] = Vertex(this->halfWidth, -this->halfHeight, this->halfDepth);
39        pVertices[4] = Vertex(-this->halfWidth, this->halfHeight, this->halfDepth);
40        pVertices[5] = Vertex(-this->halfWidth, this->halfHeight, -this->halfDepth);
41        pVertices[6] = Vertex(this->halfWidth, this->halfHeight, -this->halfDepth);
42        pVertices[7] = Vertex(this->halfWidth, this->halfHeight, this->halfDepth);
43
44        //unlock vertex buffer
45        (*pMesh)->UnlockVertexBuffer();
46
47        // fill the indices:
48        WORD* pIndices = NULL;
49        (*pMesh)->LockIndexBuffer( 0, (void**)&pIndices );
50
51        pIndices[0] = (WORD) 0; pIndices[2] = (WORD) 2; pIndices[1] = (WORD) 1;
52        pIndices[3] = (WORD) 0; pIndices[5] = (WORD) 3; pIndices[4] = (WORD) 2;
53        pIndices[6] = (WORD) 4; pIndices[8] = (WORD) 5; pIndices[7] = (WORD) 6;
54        pIndices[9] = (WORD) 4; pIndices[11] = (WORD) 6; pIndices[10] = (WORD) 7;
55        pIndices[12] = (WORD) 1; pIndices[14] = (WORD) 6; pIndices[13] = (WORD) 5;
56        pIndices[15] = (WORD) 1; pIndices[17] = (WORD) 2; pIndices[16] = (WORD) 6;
57        pIndices[18] = (WORD) 0; pIndices[20] = (WORD) 4; pIndices[19] = (WORD) 7;
58        pIndices[21] = (WORD) 0; pIndices[23] = (WORD) 7; pIndices[22] = (WORD) 3;
59        pIndices[24] = (WORD) 0; pIndices[26] = (WORD) 1; pIndices[25] = (WORD) 4;
60        pIndices[27] = (WORD) 5; pIndices[29] = (WORD) 4; pIndices[28] = (WORD) 1;
61        pIndices[30] = (WORD) 7; pIndices[32] = (WORD) 2; pIndices[31] = (WORD) 3;
62        pIndices[33] = (WORD) 7; pIndices[35] = (WORD) 6; pIndices[34] = (WORD) 2;
63
64        (*pMesh)->UnlockIndexBuffer();
65
66        // model creation finished, set value to true
67        this->setModelLoaded(true);
68
69       
70}
71
72void Box::generatePhysicMesh(int type)
73{
74        this->shapeType = type;
75        boxDesc.dimensions.set(this->halfWidth,this->halfHeight, this->halfDepth);
76        this->pActorDesc.shapes.pushBack(&boxDesc);
77}
Note: See TracBrowser for help on using the repository browser.