Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File Members  

BoxDrawArray.cpp

Go to the documentation of this file.
00001 #include "BoxDrawArray.h"
00002 
00003 #include <math.h>
00004 
00005 using namespace X3DTK;
00006 using namespace std;
00007 
00008 int BoxDrawArray::_count = 0;
00009 BoxDrawArray *BoxDrawArray::_ref = 0;
00010 
00011 BoxDrawArray *BoxDrawArray::getInstance()
00012 {
00013   if (_count == 0)
00014     _ref = new BoxDrawArray();
00015   ++_count;
00016     
00017   return _ref;  
00018 }
00019 
00020 void BoxDrawArray::removeInstance()
00021 {
00022   if (_count > 0)
00023   {
00024     --_count;
00025     if (_count == 0)
00026       delete _ref;
00027   }    
00028 }
00029 
00030 
00031 BoxDrawArray::BoxDrawArray()
00032 {
00033   //size the array
00034   _boxVertexArray = vector<N3F_V3F>(24);
00035   _boxIndexArray = vector<unsigned int>(36);
00036     
00037   //computing the vertex array
00038   //front face 
00039   _boxVertexArray[0].normal = SFVec3f(0.0f, 0.0f, 1.0f);
00040   _boxVertexArray[0].vertex = SFVec3f(-0.5f, -0.5f, 0.5f);
00041   _boxVertexArray[1].normal = SFVec3f(0.0f, 0.0f, 1.0f);
00042   _boxVertexArray[1].vertex = SFVec3f(-0.5f, 0.5f, 0.5f);
00043   _boxVertexArray[2].normal = SFVec3f(0.0f, 0.0f, 1.0f);
00044   _boxVertexArray[2].vertex = SFVec3f(0.5f, 0.5f, 0.5f);
00045   _boxVertexArray[3].normal = SFVec3f(0.0f, 0.0f, 1.0f);
00046   _boxVertexArray[3].vertex = SFVec3f(0.5f, -0.5f, 0.5f);  
00047   
00048   //back face 
00049   _boxVertexArray[4].normal = SFVec3f(0.0f, 0.0f, -1.0f);
00050   _boxVertexArray[4].vertex = SFVec3f(0.5f, -0.5f, -0.5f);
00051   _boxVertexArray[5].normal = SFVec3f(0.0f, 0.0f, -1.0f);
00052   _boxVertexArray[5].vertex = SFVec3f(0.5f, 0.5f, -0.5f);
00053   _boxVertexArray[6].normal = SFVec3f(0.0f, 0.0f, -1.0f);
00054   _boxVertexArray[6].vertex = SFVec3f(-0.5f, 0.5f, -0.5f);
00055   _boxVertexArray[7].normal = SFVec3f(0.0f, 0.0f, -1.0f);
00056   _boxVertexArray[7].vertex = SFVec3f(-0.5f, -0.5f, -0.5f);  
00057   
00058   //left face 
00059   _boxVertexArray[8].normal = SFVec3f(-1.0f, 0.0f, 0.0f);
00060   _boxVertexArray[8].vertex = SFVec3f(-0.5f, -0.5f, -0.5f);
00061   _boxVertexArray[9].normal = SFVec3f(-1.0f, 0.0f, 0.0f);
00062   _boxVertexArray[9].vertex = SFVec3f(-0.5f, 0.5f, -0.5f);
00063   _boxVertexArray[10].normal = SFVec3f(-1.0f, 0.0f, 0.0f);
00064   _boxVertexArray[10].vertex = SFVec3f(-0.5f, 0.5f, 0.5f);
00065   _boxVertexArray[11].normal = SFVec3f(-1.0f, 0.0f, 0.0f);
00066   _boxVertexArray[11].vertex = SFVec3f(-0.5f, -0.5f, 0.5f);  
00067   
00068   //right face 
00069   _boxVertexArray[12].normal = SFVec3f(1.0f, 0.0f, 0.0f);
00070   _boxVertexArray[12].vertex = SFVec3f(0.5f, -0.5f, 0.5f);
00071   _boxVertexArray[13].normal = SFVec3f(1.0f, 0.0f, 0.0f);
00072   _boxVertexArray[13].vertex = SFVec3f(0.5f, 0.5f, 0.5f);
00073   _boxVertexArray[14].normal = SFVec3f(1.0f, 0.0f, 0.0f);
00074   _boxVertexArray[14].vertex = SFVec3f(0.5f, 0.5f, -0.5f);
00075   _boxVertexArray[15].normal = SFVec3f(1.0f, 0.0f, 0.0f);
00076   _boxVertexArray[15].vertex = SFVec3f(0.5f, -0.5f, -0.5f);  
00077   
00078   //bottom face 
00079   _boxVertexArray[16].normal = SFVec3f(0.0f, -1.0f, 0.0f);
00080   _boxVertexArray[16].vertex = SFVec3f(-0.5f, -0.5f, -0.5f);
00081   _boxVertexArray[17].normal = SFVec3f(0.0f, -1.0f, 0.0f);
00082   _boxVertexArray[17].vertex = SFVec3f(-0.5f, -0.5f, 0.5f);
00083   _boxVertexArray[18].normal = SFVec3f(0.0f, -1.0f, 0.0f);
00084   _boxVertexArray[18].vertex = SFVec3f(0.5f, -0.5f, 0.5f);
00085   _boxVertexArray[19].normal = SFVec3f(0.0f, -1.0f, 0.0f);
00086   _boxVertexArray[19].vertex = SFVec3f(0.5f, -0.5f, -0.5f);  
00087   
00088   //top face 
00089   _boxVertexArray[20].normal = SFVec3f(0.0f, 1.0f, 0.0f);
00090   _boxVertexArray[20].vertex = SFVec3f(-0.5f, 0.5f, 0.5f);
00091   _boxVertexArray[21].normal = SFVec3f(0.0f, 1.0f, 0.0f);
00092   _boxVertexArray[21].vertex = SFVec3f(-0.5f, 0.5f, -0.5f);
00093   _boxVertexArray[22].normal = SFVec3f(0.0f, 1.0f, 0.0f);
00094   _boxVertexArray[22].vertex = SFVec3f(0.5f, 0.5f, -0.5f);
00095   _boxVertexArray[23].normal = SFVec3f(0.0f, 1.0f, 0.0f);
00096   _boxVertexArray[23].vertex = SFVec3f(0.5f, 0.5f, 0.5f);  
00097   
00098   //computing the index array
00099   for (unsigned short face = 0; face < 6; ++face)
00100   {
00101     _boxIndexArray[6*face + 0] = 4*face + 0;
00102     _boxIndexArray[6*face + 1] = 4*face + 1;
00103     _boxIndexArray[6*face + 2] = 4*face + 3;
00104     _boxIndexArray[6*face + 3] = 4*face + 3;
00105     _boxIndexArray[6*face + 4] = 4*face + 1;
00106     _boxIndexArray[6*face + 5] = 4*face + 2;
00107   }  
00108 }  
00109 
00110 unsigned int BoxDrawArray::getBoxSize() const
00111 {
00112   return _boxIndexArray.size();
00113 }
00114 
00115 const void *BoxDrawArray::getBoxVertexArrayAddress() const
00116 {
00117   return &_boxVertexArray.front();
00118 }
00119 
00120 const unsigned int *BoxDrawArray::getBoxIndexArrayAddress() const
00121 {
00122   return &_boxIndexArray.front();
00123 }
00124 

Generated on Wed May 14 10:03:07 2003 for X3DToolKit by doxygen1.3