V-ART
box.cpp
Go to the documentation of this file.
1 
5 #ifdef WIN32
6 #include <windows.h>
7 #endif
8 #ifdef VART_OGL
9 #include <GL/glu.h>
10 #endif
11 #include "vart/box.h"
12 #include <iostream>
13 
14 #include "vart/mesh.h"
15 #include "vart/meshobject.h"
16 #include "vart/file.h"
17 #include <sstream>
18 #include <cassert>
19 #include <fstream>
20 #include <cstdlib>
21 
22 
23 using namespace std;
24 
26 }
27 
28 void VART::Box::MakeBox(double minX,
29  double maxX,
30  double minY,
31  double maxY, double minZ, double maxZ, bool oneMesh) {
32  assert((minX <= maxX) && (minY <= maxY) && (minZ <= maxZ));
33  // each vertex must repeat 3 times because there must be a vertex/normal correspondence
34  // of 1:1
35  double coordinateArray[] = { minX,minY,minZ, //0
36  minX,maxY,minZ, //1
37  maxX,maxY,minZ, //2
38  maxX,minY,minZ, //3
39  minX,minY,maxZ, //4
40  minX,maxY,maxZ, //5
41  maxX,maxY,maxZ, //6
42  maxX,minY,maxZ, //7
43  minX,minY,minZ, //8
44  minX,maxY,minZ, //9
45  maxX,maxY,minZ, //10
46  maxX,minY,minZ, //11
47  minX,minY,maxZ, //12
48  minX,maxY,maxZ, //13
49  maxX,maxY,maxZ, //14
50  maxX,minY,maxZ, //15
51  minX,minY,minZ, //16
52  minX,maxY,minZ, //17
53  maxX,maxY,minZ, //18
54  maxX,minY,minZ, //19
55  minX,minY,maxZ, //20
56  minX,maxY,maxZ, //21
57  maxX,maxY,maxZ, //22
58  maxX,minY,maxZ }; //23
59  double* endOfCoordinateArray = coordinateArray + sizeof(coordinateArray)/sizeof(double);
60  unsigned int indexArray[] = { 0,1,2,3, // back face
61  4,7,6,5, // front face
62  11,10,14,15, // right face
63  13,9,8,12, // left face
64  22,18,17,21, // top face
65  23,20,16,19 }; // bottom face
66  unsigned int* endOfIndexArray = indexArray + sizeof(indexArray)/sizeof(int);
67  double normalArray[] = { 0,0,-1, 0,0,-1, 0,0,-1, 0,0,-1,
68  0,0,1, 0,0,1, 0,0,1, 0,0,1,
69  -1,0,0, -1,0,0, 1,0,0, 1,0,0,
70  -1,0,0, -1,0,0, 1,0,0, 1,0,0,
71  0,-1,0, 0,1,0, 0,1,0, 0,-1,0,
72  0,-1,0, 0,1,0, 0,1,0, 0,-1,0 };
73  double* endOfNormalArray = normalArray + sizeof(normalArray)/sizeof(double);
74  float textArray[] = { 1,0,0, 1,1,0, 0,1,0, 0,0,0,
75  0,0,0, 0,1,0, 1,1,0, 1,0,0,
76  0,0,0, 0,1,0, 1,1,0, 1,0,0,
77  1,0,0, 1,1,0, 0,1,0, 0,0,0,
78  0,0,0, 0,1,0, 1,1,0, 1,0,0,
79  0,1,0, 0,0,0, 1,0,0, 1,1,0 };
80  float* endOfTextArray = textArray + sizeof(textArray)/sizeof(float);
81 
82  vertCoordVec.clear();
83  normCoordVec.clear();
84  textCoordVec.clear();
85  meshList.clear();
86  vertCoordVec.assign(coordinateArray,endOfCoordinateArray);
87  normCoordVec.assign(normalArray,endOfNormalArray);
88  textCoordVec.assign(textArray,endOfTextArray);
89  if (oneMesh) { // One mesh cube
90  VART::Mesh mesh;
91  mesh.type = VART::Mesh::QUADS;
92  mesh.indexVec.assign(indexArray,endOfIndexArray);
93  mesh.material = VART::Material::DARK_PLASTIC_GRAY(); // default material
94  meshList.push_back(mesh);
95  }
96  else { // six meshes cube
97  unsigned int* index = indexArray;
98  for(int i = 0 ; i < 6 ; ++i, index += 4){
99  VART::Mesh mesh;
100  mesh.type = VART::Mesh::QUADS;
101  mesh.indexVec.assign(index, index + 4);
102  mesh.material = VART::Material::DARK_PLASTIC_GRAY(); // default material
103  meshList.push_back(mesh);
104  }
105  }
106 
107  ComputeBoundingBox();
108  ComputeRecursiveBoundingBox();
109 }
110 
111 void VART::Box::SetMaterialBoxFace(const VART::Material& mat, int numberFace){
112  // Set a material for an specific face of the box or for all faces.
113  // numberFace = 0 -> back face
114  // numberFace = 1 -> front face
115  // numberFace = 2 -> right face
116  // numberFace = 3 -> left face
117  // numberFace = 4 -> top face
118  // numberFace = 5 -> bottom face
119  // numberFace = 6 -> all faces
120 
121  if ((numberFace >= 0) && (numberFace <= 5)) {
122  list<VART::Mesh>::iterator iter = meshList.begin();
123  for (int i = 0 ; i < numberFace; ++iter, ++i);
124 
125  iter->material = mat;
126  }
127  else if (numberFace == 6)
128  this->SetMaterial(mat);
129 }
130 
MeshType type
Definition: mesh.h:66
Header file for V-ART class "Mesh".
static const Material & DARK_PLASTIC_GRAY()
Definition: material.cpp:70
Header file for V-ART class "File".
A mesh is part of an graphical object, in which faces are made of vertices according to some rule of ...
Definition: mesh.h:30
Box()
Creates an uninitialized box.
Definition: box.cpp:25
void MakeBox(double minX, double maxX, double minY, double maxY, double minZ, double maxZ, bool oneMesh=true)
Creates a box aligned with the 3 reference planes (XY, XZ and YZ).
Definition: box.cpp:28
Header file for V-ART class "Box".
Material properties for graphical objects.
Definition: material.h:16
std::vector< unsigned int > indexVec
indexes of the vertices (start at 0) defining faces
Definition: mesh.h:62
void SetMaterialBoxFace(const Material &mat, int numberFace=6)
Assigns a material to the mesh of one (or all) face of a box object.
Definition: box.cpp:111
Header file for V-ART class "MeshObject".
Graphical object made of polygon meshes.
Definition: meshobject.h:25
Material material
Definition: mesh.h:65