#include "BoxDrawArray.h" #include using namespace std; namespace X3DTK { namespace GL { int BoxDrawArray::_count = 0; BoxDrawArray *BoxDrawArray::_ref = 0; BoxDrawArray *BoxDrawArray::getInstance() { if (_count == 0) _ref = new BoxDrawArray(); ++_count; return _ref; } void BoxDrawArray::removeInstance() { if (_count > 0) { --_count; if (_count == 0) delete _ref; } } BoxDrawArray::BoxDrawArray() { //size the array _boxVertexArray = vector(24); _boxIndexArray = vector(36); //computing the vertex array //front face _boxVertexArray[0].normal = SFVec3f(0.0f, 0.0f, 1.0f); _boxVertexArray[0].vertex = SFVec3f(-0.5f, -0.5f, 0.5f); _boxVertexArray[1].normal = SFVec3f(0.0f, 0.0f, 1.0f); _boxVertexArray[1].vertex = SFVec3f(-0.5f, 0.5f, 0.5f); _boxVertexArray[2].normal = SFVec3f(0.0f, 0.0f, 1.0f); _boxVertexArray[2].vertex = SFVec3f(0.5f, 0.5f, 0.5f); _boxVertexArray[3].normal = SFVec3f(0.0f, 0.0f, 1.0f); _boxVertexArray[3].vertex = SFVec3f(0.5f, -0.5f, 0.5f); //back face _boxVertexArray[4].normal = SFVec3f(0.0f, 0.0f, -1.0f); _boxVertexArray[4].vertex = SFVec3f(0.5f, -0.5f, -0.5f); _boxVertexArray[5].normal = SFVec3f(0.0f, 0.0f, -1.0f); _boxVertexArray[5].vertex = SFVec3f(0.5f, 0.5f, -0.5f); _boxVertexArray[6].normal = SFVec3f(0.0f, 0.0f, -1.0f); _boxVertexArray[6].vertex = SFVec3f(-0.5f, 0.5f, -0.5f); _boxVertexArray[7].normal = SFVec3f(0.0f, 0.0f, -1.0f); _boxVertexArray[7].vertex = SFVec3f(-0.5f, -0.5f, -0.5f); //left face _boxVertexArray[8].normal = SFVec3f(-1.0f, 0.0f, 0.0f); _boxVertexArray[8].vertex = SFVec3f(-0.5f, -0.5f, -0.5f); _boxVertexArray[9].normal = SFVec3f(-1.0f, 0.0f, 0.0f); _boxVertexArray[9].vertex = SFVec3f(-0.5f, 0.5f, -0.5f); _boxVertexArray[10].normal = SFVec3f(-1.0f, 0.0f, 0.0f); _boxVertexArray[10].vertex = SFVec3f(-0.5f, 0.5f, 0.5f); _boxVertexArray[11].normal = SFVec3f(-1.0f, 0.0f, 0.0f); _boxVertexArray[11].vertex = SFVec3f(-0.5f, -0.5f, 0.5f); //right face _boxVertexArray[12].normal = SFVec3f(1.0f, 0.0f, 0.0f); _boxVertexArray[12].vertex = SFVec3f(0.5f, -0.5f, 0.5f); _boxVertexArray[13].normal = SFVec3f(1.0f, 0.0f, 0.0f); _boxVertexArray[13].vertex = SFVec3f(0.5f, 0.5f, 0.5f); _boxVertexArray[14].normal = SFVec3f(1.0f, 0.0f, 0.0f); _boxVertexArray[14].vertex = SFVec3f(0.5f, 0.5f, -0.5f); _boxVertexArray[15].normal = SFVec3f(1.0f, 0.0f, 0.0f); _boxVertexArray[15].vertex = SFVec3f(0.5f, -0.5f, -0.5f); //bottom face _boxVertexArray[16].normal = SFVec3f(0.0f, -1.0f, 0.0f); _boxVertexArray[16].vertex = SFVec3f(-0.5f, -0.5f, -0.5f); _boxVertexArray[17].normal = SFVec3f(0.0f, -1.0f, 0.0f); _boxVertexArray[17].vertex = SFVec3f(-0.5f, -0.5f, 0.5f); _boxVertexArray[18].normal = SFVec3f(0.0f, -1.0f, 0.0f); _boxVertexArray[18].vertex = SFVec3f(0.5f, -0.5f, 0.5f); _boxVertexArray[19].normal = SFVec3f(0.0f, -1.0f, 0.0f); _boxVertexArray[19].vertex = SFVec3f(0.5f, -0.5f, -0.5f); //top face _boxVertexArray[20].normal = SFVec3f(0.0f, 1.0f, 0.0f); _boxVertexArray[20].vertex = SFVec3f(-0.5f, 0.5f, 0.5f); _boxVertexArray[21].normal = SFVec3f(0.0f, 1.0f, 0.0f); _boxVertexArray[21].vertex = SFVec3f(-0.5f, 0.5f, -0.5f); _boxVertexArray[22].normal = SFVec3f(0.0f, 1.0f, 0.0f); _boxVertexArray[22].vertex = SFVec3f(0.5f, 0.5f, -0.5f); _boxVertexArray[23].normal = SFVec3f(0.0f, 1.0f, 0.0f); _boxVertexArray[23].vertex = SFVec3f(0.5f, 0.5f, 0.5f); //computing the index array for (unsigned short face = 0; face < 6; ++face) { _boxIndexArray[6*face + 0] = 4*face + 0; _boxIndexArray[6*face + 1] = 4*face + 1; _boxIndexArray[6*face + 2] = 4*face + 3; _boxIndexArray[6*face + 3] = 4*face + 3; _boxIndexArray[6*face + 4] = 4*face + 1; _boxIndexArray[6*face + 5] = 4*face + 2; } } unsigned int BoxDrawArray::getBoxSize() const { return _boxIndexArray.size(); } const void *BoxDrawArray::getBoxVertexArrayAddress() const { return &_boxVertexArray.front(); } const unsigned int *BoxDrawArray::getBoxIndexArrayAddress() const { return &_boxIndexArray.front(); } } }