#include "dxstdafx.h" #include ".\box.h" #include "Scene.h" Box::Box(void) : Object3d() { this->halfWidth = 2; this->halfHeight = 2; this->halfDepth = 2; LPD3DXMESH * pMesh = this->getMesh(); HRESULT hr = 0; hr = D3DXCreateMeshFVF(12, 8, D3DXMESH_MANAGED, this->FVF_Flags, DXUTGetD3DDevice(), pMesh); this->nodeType |= Scene::NODE_BOX; } Box::~Box(void) { } void Box::setDimension(float _width, float _height, float _depth) { this->halfWidth = _width/2; this->halfHeight = _height/2; this->halfDepth = _depth/2; LPD3DXMESH * pMesh = this->getMesh(); Vertex* pVertices; //lock vertex buffer (*pMesh)->LockVertexBuffer( 0, (void**)&pVertices ); pVertices[0] = Vertex(-this->halfWidth, -this->halfHeight, this->halfDepth); pVertices[1] = Vertex(-this->halfWidth, -this->halfHeight, -this->halfDepth); pVertices[2] = Vertex(this->halfWidth, -this->halfHeight, -this->halfDepth); pVertices[3] = Vertex(this->halfWidth, -this->halfHeight, this->halfDepth); pVertices[4] = Vertex(-this->halfWidth, this->halfHeight, this->halfDepth); pVertices[5] = Vertex(-this->halfWidth, this->halfHeight, -this->halfDepth); pVertices[6] = Vertex(this->halfWidth, this->halfHeight, -this->halfDepth); pVertices[7] = Vertex(this->halfWidth, this->halfHeight, this->halfDepth); //unlock vertex buffer (*pMesh)->UnlockVertexBuffer(); // fill the indices: WORD* pIndices = NULL; (*pMesh)->LockIndexBuffer( 0, (void**)&pIndices ); pIndices[0] = (WORD) 0; pIndices[2] = (WORD) 2; pIndices[1] = (WORD) 1; pIndices[3] = (WORD) 0; pIndices[5] = (WORD) 3; pIndices[4] = (WORD) 2; pIndices[6] = (WORD) 4; pIndices[8] = (WORD) 5; pIndices[7] = (WORD) 6; pIndices[9] = (WORD) 4; pIndices[11] = (WORD) 6; pIndices[10] = (WORD) 7; pIndices[12] = (WORD) 1; pIndices[14] = (WORD) 6; pIndices[13] = (WORD) 5; pIndices[15] = (WORD) 1; pIndices[17] = (WORD) 2; pIndices[16] = (WORD) 6; pIndices[18] = (WORD) 0; pIndices[20] = (WORD) 4; pIndices[19] = (WORD) 7; pIndices[21] = (WORD) 0; pIndices[23] = (WORD) 7; pIndices[22] = (WORD) 3; pIndices[24] = (WORD) 0; pIndices[26] = (WORD) 1; pIndices[25] = (WORD) 4; pIndices[27] = (WORD) 5; pIndices[29] = (WORD) 4; pIndices[28] = (WORD) 1; pIndices[30] = (WORD) 7; pIndices[32] = (WORD) 2; pIndices[31] = (WORD) 3; pIndices[33] = (WORD) 7; pIndices[35] = (WORD) 6; pIndices[34] = (WORD) 2; (*pMesh)->UnlockIndexBuffer(); // model creation finished, set value to true this->setModelLoaded(true); } void Box::generatePhysicMesh(int type) { this->shapeType = type; boxDesc.dimensions.set(this->halfWidth,this->halfHeight, this->halfDepth); this->pActorDesc.shapes.pushBack(&boxDesc); }