V-ART
mesh.cpp
Go to the documentation of this file.
1 
5 #include "vart/mesh.h"
6 
7 using namespace std;
8 
10  : type(NONE) {}
11 
13  indexVec = mesh.indexVec;
14  normIndVec = mesh.normIndVec;
15  type = mesh.type;
16  material = mesh.material;
17 }
18 
20  indexVec = mesh.indexVec;
21  normIndVec = mesh.normIndVec;
22  type = mesh.type;
23  material = mesh.material;
24  return *this;
25 }
26 
27 void VART::Mesh::IncrementIndices(unsigned int increment) {
28  for (unsigned int i=0; i < indexVec.size(); ++i)
29  indexVec[i] += increment;
30 }
31 
32 #ifdef VART_OGL
33 GLenum VART::Mesh::GetOglType(MeshType type) {
34  switch (type) {
35  case POINTS:
36  return GL_POINTS;
37  case LINES:
38  return GL_LINES;
39  case LINE_STRIP:
40  return GL_LINE_STRIP;
41  case LINE_LOOP:
42  return GL_LINE_LOOP;
43  case TRIANGLES:
44  return GL_TRIANGLES;
45  case TRIANGLE_STRIP:
46  return GL_TRIANGLE_STRIP;
47  case TRIANGLE_FAN:
48  return GL_TRIANGLE_FAN;
49  case QUADS:
50  return GL_QUADS;
51  case QUAD_STRIP:
52  return GL_QUAD_STRIP;
53  default:
54  return GL_POLYGON;
55  }
56 }
57 #endif
58 
59 
61 #ifdef VART_OGL
62  bool result = material.DrawOGL();
63  if (material.HasTexture())
64  glEnableClientState(GL_TEXTURE_COORD_ARRAY);
65  else
66  glDisableClientState(GL_TEXTURE_COORD_ARRAY);
67  glDrawElements(GetOglType(type), indexVec.size(), GL_UNSIGNED_INT, &indexVec[0]);
68  return result;
69 #else
70  return false;
71 #endif
72 }
73 
74 //~ bool VART::Mesh::DrawOglUnoptimized(const vector<VART::Point4D>& vertVec) const {
75 //~ #ifdef VART_OGL
76  //~ bool result = material.DrawOGL();
77  //~ glBegin(GetOglType(type));
78  //~ for (unsigned int i=0; i < indexVec.size(); ++i)
79  //~ //glNormal3dv(normVec
80  //~ glVertex4dv(vertVec[indexVec[i]].VetXYZW());
81  //~ glEnd();
82  //~ return result;
83 //~ #else
84  //~ return false;
85 //~ #endif
86 //~ }
87 
88 namespace VART {
89  ostream& operator<<(ostream& output, const Mesh::MeshType mt) {
90  switch (mt)
91  {
92  case VART::Mesh::POINTS:
93  output << "POINTS";
94  break;
95  case VART::Mesh::LINES:
96  output << "LINES";
97  break;
99  output << "LINE_STRIP";
100  break;
102  output << "LINE_LOOP";
103  break;
105  output << "TRIANGLES";
106  break;
108  output << "TRIANGLE_STRIP";
109  break;
111  output << "TRIANGLE_FAN";
112  break;
113  case VART::Mesh::QUADS:
114  output << "QUADS";
115  break;
117  output << "QUAD_STRIP";
118  break;
119  case VART::Mesh::POLYGON:
120  output << "POLYGON";
121  break;
122  default:
123  output << "NO MESH TYPE";
124  }
125  return output;
126  }
127 
128  ostream& operator<<(ostream& output, const Mesh& mesh) {
129  output << mesh.type << " indexVec: ";
130  for (auto& index: mesh.indexVec)
131  output << index << " ";
132  //output << "material: " << mesh.material;
133  return output;
134  }
135 }
std::vector< unsigned int > normIndVec
indexes of the normals (for unoptimized meshes)
Definition: mesh.h:64
MeshType type
Definition: mesh.h:66
Header file for V-ART class "Mesh".
std::ostream & operator<<(std::ostream &output, const Joint::DofID &dofId)
Mesh()
Creates an uninitialized mesh.
Definition: mesh.cpp:9
A mesh is part of an graphical object, in which faces are made of vertices according to some rule of ...
Definition: mesh.h:30
void IncrementIndices(unsigned int increment)
Returns the mesh type as OpenGL enum.
Definition: mesh.cpp:27
MeshType
Definition: mesh.h:34
std::vector< unsigned int > indexVec
indexes of the vertices (start at 0) defining faces
Definition: mesh.h:62
Mesh & operator=(const Mesh &mesh)
Definition: mesh.cpp:19
Material material
Definition: mesh.h:65
bool DrawInstanceOGL() const
Draws the mesh assuming that its MeshObject is optimized.
Definition: mesh.cpp:60