Robotran C Documentation
MbsWorld3D.hh
Go to the documentation of this file.
1 
6 #ifdef OPEN_GL
7 
8 #ifndef _MBS_WORLD_3D_HH_
9 #define _MBS_WORLD_3D_HH_
10 
11 #include "MbsLight.hh"
12 #include "MbsViewPoint.hh"
13 #include "MbsShape3D.hh"
14 #include "Base3D.hh"
15 #include "MbsRead.hh"
16 
17 #include <vector>
18 
19 
20 #include "MbsWorldRenderer.hh"
21 #include "MbsWindowManager.hh"
22 
23 // shader types
24 enum {NO_LIGHT_SHADER, LIGHTS_NO_SPEC_SHADER, LIGHTS_SHADER, SHADOW_MAPPING_SHADER};
25 
26 namespace OpenGLMbs{
27 
28 // forward declaration
29 
30 class MbsBox;
31 class MbsCylinder;
32 class MbsCone;
33 class MbsSphere;
34 class MbsInline;
35 
36 class Joint3D;
37 
38 class MbsPointLight;
39 class MbsSpotLight;
40 class MbsDirLight;
41 
42 #define MAX_NB_LIGHTS 10
43 
44 
46 class MbsWorld3D
47 {
48  public:
49  MbsWorld3D(int x_width=1024, int y_width=768, int shader_flag=LIGHTS_NO_SPEC_SHADER, int multi_samp=4,
50  glm::vec3 const& background_color = glm::vec3(0.8, 0.8, 0.8),
51  MbsWorldRenderer* renderer=0,
52  MbsWindowManager* winMngr=0);
53  ~MbsWorld3D();
54 
56  int GetXWidth() const { return winManager->GetXWidth(); }
57 
59  int GetYWidth() const { return winManager->GetYWidth(); }
60 
62  double GetT() const { return t; }
63 
65  int GetNbMbs() const { return (int) mbs_list.size(); }
66 
68  int GetNbModels() const { return (int)model_list.size(); }
69 
71  int GetNbLights() const { return (int) light_list.size(); }
72 
74  int GetNbViews() const { return (int) view_list.size(); }
75 
77  int GetNbJoints(int i) const { return (int) joint_tab[i].size(); }
78 
80  int GetShaderFlag() const { return (int) shader_flag; }
81 
83  MbsShape3D* GetModel(int i) { return model_list[i]; }
84 
86  std::vector<MbsShape3D*> GetModels() { return model_list; }
87 
89  MbsLight* GetLight(int i) { return light_list[i]; }
90 
92  MbsViewPoint* GetView(int i) { return view_list[i]; }
93 
95  MbsViewPoint* GetCurView() { return view_list[cur_view]; }
96 
97  // add a joint list corresponding to a single .mbs file
98  void AddJointList(std::vector<Joint3D*> const& joint_list)
99  {
100  joint_tab.push_back(joint_list);
101  }
102 
104  void AddBase(Base3D *new_mbs)
105  {
106  new_mbs->UpdateAbsMatTree();
107  mbs_list.push_back(new_mbs);
108  }
109  void Update();
110  void UpdateTime();
111  int CheckClose();
112 
113  void NextViewPoint();
114  void SetViewPoint(int view_id);
115 
116  void AddMbs(const char* mbs_filename);
117 
118  void UpdateJoints(int model_id, int nb_q, double *q_vec);
119 
120  void SetBackgroundColor(glm::vec3 const& background_color);
121 
122  MbsBox* AddBox(double d, double w, double h, glm::vec3 color,
123  float transparency = 1.0,
124  glm::vec3 const& trans_pos = glm::vec3(0.0f),
125  glm::vec3 const& trans_scale = glm::vec3(1.0, 1.0, 1.0),
126  glm::vec3 const& trans_rot = glm::vec3(0.0f),
127  float shiny_mat = 250.f,
128  glm::vec3 const& specular_mat = glm::vec3(1.0f, 1.0f, 1.0f),
129  const char* name = "none");
130 
131  MbsCylinder* AddCylinder(double r, double h, glm::vec3 color,
132  float transparency = 1.0,
133  glm::vec3 const& trans_pos = glm::vec3(0.0f),
134  glm::vec3 const& trans_scale = glm::vec3(1.0, 1.0, 1.0),
135  glm::vec3 const& trans_rot = glm::vec3(0.0f),
136  float shiny_mat = 250.f,
137  glm::vec3 const& specular_mat = glm::vec3(1.0f, 1.0f, 1.0f),
138  const char* name = "none");
139 
140  MbsCone* AddCone(double r, double h, glm::vec3 color,
141  float transparency = 1.0,
142  glm::vec3 const& trans_pos = glm::vec3(0.0f),
143  glm::vec3 const& trans_scale = glm::vec3(1.0, 1.0, 1.0),
144  glm::vec3 const& trans_rot = glm::vec3(0.0f),
145  float shiny_mat = 250.f,
146  glm::vec3 const& specular_mat = glm::vec3(1.0f, 1.0f, 1.0f),
147  const char* name = "none");
148 
149  MbsSphere* AddSphere(double r, glm::vec3 color,
150  float transparency = 1.0,
151  glm::vec3 const& trans_pos = glm::vec3(0.0f),
152  glm::vec3 const& trans_scale = glm::vec3(1.0, 1.0, 1.0),
153  glm::vec3 const& trans_rot = glm::vec3(0.0f),
154  float shiny_mat = 250.f,
155  glm::vec3 const& specular_mat = glm::vec3(1.0f, 1.0f, 1.0f),
156  const char* name = "none");
157 
158  MbsInline* AddInline(std::string cad_file, glm::vec3 color,
159  float transparency = 1.0,
160  glm::vec3 const& trans_pos = glm::vec3(0.0f),
161  glm::vec3 const& trans_scale = glm::vec3(1.0, 1.0, 1.0),
162  glm::vec3 const& trans_rot = glm::vec3(0.0f),
163  float shiny_mat = 250.f,
164  glm::vec3 const& specular_mat = glm::vec3(1.0f, 1.0f, 1.0f),
165  const char* name = "none");
166 
167  MbsPointLight* AddPointLight(glm::vec3 const& rel_pos = glm::vec3(0.0f),
168  glm::vec3 const& attenuation = glm::vec3(1.0f, 0.0f, 0.0f),
169  glm::mat4 const& parent_mat = glm::mat4(1.0f),
170  glm::vec3 const& color = glm::vec3(1.0f),
171  float ambient = 0.05f,
172  bool active = true,
173  int depth_x_width = 1024, int depth_y_width = 1024, float shadow_bias = 0.0f,
174  float depth_near = 0.1f, float depth_far = 100.0f,
175  glm::vec3 const& shadow_z_up = glm::vec3(0.0, 0.0, 1.0),
176  float depth_FoV_rad = 1.0f,
177  glm::vec3 const& shadow_rel_dir = glm::vec3(0.0f, -1.0f, 0.0f));
178 
179  MbsSpotLight* AddSpotLight(glm::vec3 const& rel_pos = glm::vec3(0.0f),
180  glm::vec3 const& attenuation = glm::vec3(1.0f, 0.0f, 0.0f),
181  glm::vec3 const& rel_dir = glm::vec3(0.0f, 0.0f, -1.0f),
182  glm::mat4 const& parent_mat = glm::mat4(1.0f),
183  glm::vec3 const& color = glm::vec3(1.0f),
184  float ambient = 0.05f,
185  float spread_angle = 3.1415927f,
186  float concentration = 0.0f,
187  bool active = true,
188  int depth_x_width = 1024, int depth_y_width = 1024, float shadow_bias = 0.0f,
189  float depth_near = 0.1f, float depth_far = 100.0f,
190  glm::vec3 const& shadow_z_up = glm::vec3(0.0, 0.0, 1.0),
191  float depth_FoV_rad = 1.0f);
192 
193  MbsDirLight* AddDirLight(glm::vec3 const& rel_dir = glm::vec3(0.0f, 0.0f, -1.0f),
194  glm::mat4 const& parent_mat = glm::mat4(1.0f),
195  glm::vec3 const& color = glm::vec3(1.0f),
196  float ambient = 0.05f,
197  bool active = true,
198  int depth_x_width = 1024, int depth_y_width = 1024, float shadow_bias = 0.0f,
199  float depth_near = -10.0f, float depth_far = 20.0f,
200  glm::vec3 const& shadow_z_up = glm::vec3(0.0, 0.0, 1.0),
201  float depth_scale = 0.0015f,
202  glm::vec3 const& rel_shadow_point = glm::vec3(0.0f));
203 
204  MbsViewPoint* AddViewPoint(glm::vec3 const&rel_pos, glm::vec3 const&rel_look_at, glm::vec3 const&z_up,
205  bool pers_flag=true,
206  float FoV_scale=0.785f, float camera_near=0.1f, float camera_far=100.0f,
207  glm::mat4 const& parent_mat = glm::mat4(1.0f));
208 
209 
210  MbsWorldRenderer* GetWorldRenderer(){
211  return worldRenderer;
212  }
213 
214  void AddViewPointRenderer(MbsViewPointRenderer* rdr){worldRenderer->AddViewPointRenderer(rdr);}
215 
216  protected:
217  // renderer
218  MbsWorldRenderer* worldRenderer;
219 
220  MbsWindowManager* winManager;
221 
222  private:
223  MbsRead mbs_read;
224 
225  std::vector<MbsViewPoint*> view_list;
226 
227  std::vector<MbsShape3D*> model_list;
228 
229  std::vector<MbsLight*> light_list;
230 
231  std::vector< std::vector<Joint3D*> > joint_tab;
232 
233  std::vector<Base3D*> mbs_list;
234 
235  std::string main_vert_sh;
236  std::string main_frag_sh;
237 
238  int cur_view;
239 
240  bool flag_first;
241 
242  double t;
243  double init_t;
244 
245  int shader_flag;
246 
247  bool hasInitOwnWorldRenderer;
248  bool hasInitOwnWindowManager;
249 };
250 
251 }
252 #endif
253 #endif
MbsSpotLight.hh
MbsSpotLight class.
MbsCone.hh
MbsCone class.
OpenGLMbs
Definition: MpegFrameCaptureOptions.hh:6
MbsWorld3D.hh
MbsWorld3D class.
MbsPointLight.hh
MbsPointLight class.
MbsShape3D.hh
MbsShape3D class.
MbsBox.hh
MbsBox class.
MbsWindowManager.hh
MbsWindowManager class.
MbsInline.hh
MbsInline class.
MbsDirLight.hh
MbsDirLight class.
MbsCylinder.hh
MbsCylinder class.
DefaultWindowManager.hh
DefaultWindowManager class.
MbsWorldRenderer.hh
MbsWorldRenderer class.
Base3D.hh
Base3D class.
MbsViewPoint.hh
MbsViewPoint class.
MbsRead.hh
MbsRead class.
MbsShape3D
MbsLight.hh
MbsLight class.
MbsSphere.hh
MbsSphere class.
DefaultWorldRenderer.hh
DefaultShapeRenderer class.