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 
84  std::vector<glm::vec3> vertices;
85  std::vector<glm::vec3> colors;
86  std::vector<glm::vec3> normals;
87 
88  std::vector<unsigned int> indexes;
89 
90  glm::mat4 proj_mat;
91  glm::mat4 view_mat;
92  glm::mat4 model_mat;
93  glm::mat4 MVP;
94  glm::mat3 M_inv_trans;
95 
96  glm::vec3 trans_pos;
97  glm::vec3 trans_scale;
98  glm::vec3 trans_rot;
99 
100  MbsWorld3D *world_3d;
101 
102  float transparency;
103 
104  float shiny_mat;
105  glm::vec3 specular_mat;
106 
107  int nb_triangles;
108  int nb_vertices;
109 
110  // function prototypes
111  void Init();
112  void SetNbTriangles(int nb_triangles);
113  void NormalsCompute();
114  void ApplyTransform();
115  void VBOIndexing();
116  void BasicLoad(GLdouble *tmp_vert, GLfloat *tmp_coord, int nb_tri, int nb_vert, glm::vec3 const& color);
117 
118  void ColorHeight(std::vector<glm::vec3> const& vertices, std::vector<glm::vec3> &colors,
119  int axis, bool inv_color, bool bound_flag, float min_range, float max_range, const char* name);
120 
122  glm::mat4 TransMat(float x, float y, float z)
123  {
124  return glm::mat4(
125  1.0f, 0.0f, 0.0f, 0.0f,
126  0.0f, 1.0f, 0.0f, 0.0f,
127  0.0f, 0.0f, 1.0f, 0.0f,
128  x, y, z, 1.0f
129  );
130  }
131 
133  glm::mat4 ScaleMat(float x, float y, float z)
134  {
135  return glm::mat4(
136  x , 0.0f, 0.0f, 0.0f,
137  0.0f, y , 0.0f, 0.0f,
138  0.0f, 0.0f, z , 0.0f,
139  0.0f, 0.0f, 0.0f, 1.0f
140  );
141  }
142 
144  glm::mat4 RotMatX(float angle_rad)
145  {
146  float cos_a, sin_a;
147 
148  cos_a = cos(angle_rad);
149  sin_a = sin(angle_rad);
150 
151  return glm::mat4(
152  1.0f, 0.0f , 0.0f , 0.0f,
153  0.0f, cos_a, sin_a, 0.0f,
154  0.0f, -sin_a, cos_a, 0.0f,
155  0.0f, 0.0f , 0.0f , 1.0f
156  );
157  }
158 
160  glm::mat4 RotMatY(float angle_rad)
161  {
162  float cos_a, sin_a;
163 
164  cos_a = cos(angle_rad);
165  sin_a = sin(angle_rad);
166 
167  return glm::mat4(
168  cos_a, 0.0f, -sin_a, 0.0f,
169  0.0f , 1.0f, 0.0f , 0.0f,
170  sin_a, 0.0f, cos_a, 0.0f,
171  0.0f , 0.0f, 0.0f , 1.0f
172  );
173  }
174 
176  glm::mat4 RotMatZ(float angle_rad)
177  {
178  float cos_a, sin_a;
179 
180  cos_a = cos(angle_rad);
181  sin_a = sin(angle_rad);
182 
183  return glm::mat4(
184  cos_a, sin_a, 0.0f, 0.0f,
185  -sin_a, cos_a, 0.0f, 0.0f,
186  0.0f , 0.0f , 1.0f, 0.0f,
187  0.0f , 0.0f , 0.0f, 1.0f
188  );
189  }
190 
192  MbsShapeRenderer* shRenderer;
193 
194 };
195 
196 }
197 #endif
198 #endif
MbsSpotLight.hh
MbsSpotLight class.
OpenGLMbs
Definition: MpegFrameCaptureOptions.hh:6
MbsWorld3D.hh
MbsWorld3D class.
MbsPointLight.hh
MbsPointLight class.
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.
normalize
void normalize(double v[4], double vn[4])
DEPRECATED: See normalize_dvec_1()
Definition: mbs_1D_array.c:347
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:22