Robotran C Documentation
MbsShape3D.hh
Go to the documentation of this file.
1 
6 #ifdef OPEN_GL
7 
8 #ifndef _MBS_SHAPE_3D_HH_
9 #define _MBS_SHAPE_3D_HH_
10 
11 #ifndef degreesToRadians
12  #define degreesToRadians(x) x*(3.141592f/180.0f)
13 #endif
14 
15 #ifndef GLM_FORCE_RADIANS
16  #define GLM_FORCE_RADIANS
17 #endif
18 
19 #include <glm.hpp>
20 #include <string>
21 #include <vector>
22 
23 #include "MbsShapeRenderer.hh"
24 
25 #include "Mbs3DTypes.hh"
26 
27 
28 namespace OpenGLMbs{
29 
30 // forward declaration
31 class MbsWorld3D;
32 class MbsLight;
33 class MbsViewPoint;
34 
37 class MbsShape3D
38 {
39  public:
40  MbsShape3D(MbsWorld3D *world_3d,
41  float transparency = 1.0,
42  glm::vec3 const& trans_pos = glm::vec3(0.0f),
43  glm::vec3 const& trans_scale = glm::vec3(1.0, 1.0, 1.0),
44  glm::vec3 const& trans_rot = glm::vec3(0.0f),
45  float shiny_mat = 250.f,
46  glm::vec3 const& specular_mat = glm::vec3(1.0f, 1.0f, 1.0f),
47  const char* name = "none");
48  virtual ~MbsShape3D();
49 
51  void SetModelMat(glm::mat4 const& model_mat)
52  {
53  this->model_mat = model_mat;
54 
55  M_inv_trans = glm::transpose(glm::inverse(glm::mat3(model_mat)));
56 
57  shRenderer->SetModelMat(model_mat);
58  }
59 
60  void Update();
61 
62  // call the shape renderer associated to this shape
63  void Render(MbsViewPoint *viewpoint);
64  void Render();
65 
66  void ShadowDepth(int index){shRenderer->ShadowDepth(index);}
67 
69  void SetShinyMat(float val) { shiny_mat = val; }
70 
72  void SetSpecularMat(glm::vec3 const& vec) { specular_mat = vec; }
73 
75  MbsShapeRenderer* GetShapeRenderer(){ return shRenderer; }
76 
77  protected:
78  char* name;
79 
80  std::vector<glm::vec3> temp_vertices;
81  std::vector<glm::vec3> temp_colors;
82  std::vector<glm::vec3> temp_normals;
83  std::vector<glm::vec3> temp_line_vertices;
84  std::vector<glm::vec3> temp_line_colors;
85 
86  std::vector<glm::vec3> vertices;
87  std::vector<glm::vec3> colors;
88  std::vector<glm::vec3> normals;
89  std::vector<glm::vec3> line_vertices;
90  std::vector<glm::vec3> line_colors;
91 
92  std::vector<unsigned int> indexes;
93  std::vector<unsigned int> line_indexes;
94 
95  glm::mat4 proj_mat;
96  glm::mat4 view_mat;
97  glm::mat4 model_mat;
98  glm::mat4 MVP;
99  glm::mat3 M_inv_trans;
100 
101  glm::vec3 trans_pos;
102  glm::vec3 trans_scale;
103  glm::vec3 trans_rot;
104 
105  MbsWorld3D *world_3d;
106 
107  float transparency;
108 
109  float shiny_mat;
110  glm::vec3 specular_mat;
111 
112  int nb_triangles;
113  int nb_vertices;
114 
115  // function prototypes
116  void Init();
117  void SetNbTriangles(int nb_triangles);
118  void NormalsCompute();
119  void ApplyTransform();
120  void VBOIndexing();
121  void VBOLineIndexing();
122  void BasicLoad(GLdouble *tmp_vert, GLfloat *tmp_coord, int nb_tri, int nb_vert, glm::vec3 const& color);
123 
124  void ColorHeight(std::vector<glm::vec3> const& vertices, std::vector<glm::vec3> &colors,
125  int axis, bool inv_color, bool bound_flag, float min_range, float max_range, const char* name);
126 
128  glm::mat4 TransMat(float x, float y, float z)
129  {
130  return glm::mat4(
131  1.0f, 0.0f, 0.0f, 0.0f,
132  0.0f, 1.0f, 0.0f, 0.0f,
133  0.0f, 0.0f, 1.0f, 0.0f,
134  x, y, z, 1.0f
135  );
136  }
137 
139  glm::mat4 ScaleMat(float x, float y, float z)
140  {
141  return glm::mat4(
142  x , 0.0f, 0.0f, 0.0f,
143  0.0f, y , 0.0f, 0.0f,
144  0.0f, 0.0f, z , 0.0f,
145  0.0f, 0.0f, 0.0f, 1.0f
146  );
147  }
148 
150  glm::mat4 RotMatX(float angle_rad)
151  {
152  float cos_a, sin_a;
153 
154  cos_a = cos(angle_rad);
155  sin_a = sin(angle_rad);
156 
157  return glm::mat4(
158  1.0f, 0.0f , 0.0f , 0.0f,
159  0.0f, cos_a, sin_a, 0.0f,
160  0.0f, -sin_a, cos_a, 0.0f,
161  0.0f, 0.0f , 0.0f , 1.0f
162  );
163  }
164 
166  glm::mat4 RotMatY(float angle_rad)
167  {
168  float cos_a, sin_a;
169 
170  cos_a = cos(angle_rad);
171  sin_a = sin(angle_rad);
172 
173  return glm::mat4(
174  cos_a, 0.0f, -sin_a, 0.0f,
175  0.0f , 1.0f, 0.0f , 0.0f,
176  sin_a, 0.0f, cos_a, 0.0f,
177  0.0f , 0.0f, 0.0f , 1.0f
178  );
179  }
180 
182  glm::mat4 RotMatZ(float angle_rad)
183  {
184  float cos_a, sin_a;
185 
186  cos_a = cos(angle_rad);
187  sin_a = sin(angle_rad);
188 
189  return glm::mat4(
190  cos_a, sin_a, 0.0f, 0.0f,
191  -sin_a, cos_a, 0.0f, 0.0f,
192  0.0f , 0.0f , 1.0f, 0.0f,
193  0.0f , 0.0f , 0.0f, 1.0f
194  );
195  }
196 
198  MbsShapeRenderer* shRenderer;
199 
200 };
201 
202 }
203 #endif
204 #endif
MbsSpotLight.hh
MbsSpotLight class.
OpenGLMbs
Definition: MpegFrameCaptureOptions.hh:6
MbsWorld3D.hh
MbsWorld3D class.
MbsPointLight.hh
MbsPointLight class.
normalize
void normalize(double v[4], double vn[4])
DEPRECATED: See normalize_dvec_1()
Definition: norm.c:33
MbsShape3D.hh
MbsShape3D class.
MbsShapeRenderer.hh
MbsShapeRenderer class.
OpenGLMbs::int_in_range
bool int_in_range(int x, int min, int max)
check if integer is in range
Definition: MbsInline.cc:17
MbsDirLight.hh
MbsDirLight class.
Mbs3DTypes.hh
MbsShape3D
MbsLight.hh
MbsLight class.
transpose
void transpose(double M[4][4], double Mt[4][4])
Compute the transpose of a matrix with first index is 1.
Definition: mbs_matrix.c:24