Robotran C Documentation
Mbs3DComponent.hh
Go to the documentation of this file.
1 
6 #ifdef OPEN_GL
7 
8 #ifndef _MBS_3D_COMPONENT_HH_
9 #define _MBS_3D_COMPONENT_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 <vector>
21 
22 namespace OpenGLMbs{
23 
24 // forward declaration
25 class MbsWorld3D;
26 class Joint3D;
27 class Base3D;
28 
29 // mbs component types
30 enum {COMP_TYPE_COMPONENT, COMP_TYPE_BODY, COMP_TYPE_ABSTRACT, COMP_TYPE_ANCHOR, COMP_TYPE_JOINT, COMP_TYPE_BASE};
31 
34 class Mbs3DComponent
35 {
36  public:
37  Mbs3DComponent(MbsWorld3D *world_3d, const char* name, glm::mat4 const& abs_mat = glm::mat4(1.0f));
38  virtual ~Mbs3DComponent();
39 
41  void SetAbsMat(glm::mat4 const& abs_mat) { this->abs_mat = abs_mat; }
42 
44  glm::mat4 GetAbsMat() const { return abs_mat; }
45 
47  int GetCompType() const { return comp_type; }
48 
49  void ReleaseChildList();
50 
51  Joint3D* AddT1(const char* name, float joint_value = 0.0f);
52  Joint3D* AddT2(const char* name, float joint_value = 0.0f);
53  Joint3D* AddT3(const char* name, float joint_value = 0.0f);
54  Joint3D* AddR1(const char* name, float joint_value = 0.0f);
55  Joint3D* AddR2(const char* name, float joint_value = 0.0f);
56  Joint3D* AddR3(const char* name, float joint_value = 0.0f);
57 
58  Base3D* AddBaseJoint();
59 
60  bool IsName(const char* name);
61 
62  Mbs3DComponent* Get3DCompName(int comp_type, const char* name);
63 
64  virtual void UpdateAbsMatTree();
65 
66  virtual void PrintTree(int level);
67 
68  protected:
69  MbsWorld3D *world_3d;
70 
71  glm::mat4 abs_mat;
72 
73  std::vector<Joint3D*> joint_child_list;
74 
75  std::vector<Mbs3DComponent*> mbs_3d_child_list;
76 
77  char* name;
78 
79  int comp_type;
80 
81  // function prototypes
82  Joint3D* AddJoint(const char* name, int joint_type, float joint_value);
83  void PrintName(int level);
84  void PrintChildList(int level);
85 
87  glm::mat4 TransMat(float x, float y, float z)
88  {
89  return glm::mat4(
90  1.0f, 0.0f, 0.0f, 0.0f,
91  0.0f, 1.0f, 0.0f, 0.0f,
92  0.0f, 0.0f, 1.0f, 0.0f,
93  x, y, z, 1.0f
94  );
95  }
96 
98  glm::mat4 ScaleMat(float x, float y, float z)
99  {
100  return glm::mat4(
101  x , 0.0f, 0.0f, 0.0f,
102  0.0f, y , 0.0f, 0.0f,
103  0.0f, 0.0f, z , 0.0f,
104  0.0f, 0.0f, 0.0f, 1.0f
105  );
106  }
107 
109  glm::mat4 RotMatX(float angle_rad)
110  {
111  float cos_a, sin_a;
112 
113  cos_a = cos(angle_rad);
114  sin_a = sin(angle_rad);
115 
116  return glm::mat4(
117  1.0f, 0.0f , 0.0f , 0.0f,
118  0.0f, cos_a, sin_a, 0.0f,
119  0.0f, -sin_a, cos_a, 0.0f,
120  0.0f, 0.0f , 0.0f , 1.0f
121  );
122  }
123 
125  glm::mat4 RotMatY(float angle_rad)
126  {
127  float cos_a, sin_a;
128 
129  cos_a = cos(angle_rad);
130  sin_a = sin(angle_rad);
131 
132  return glm::mat4(
133  cos_a, 0.0f, -sin_a, 0.0f,
134  0.0f , 1.0f, 0.0f , 0.0f,
135  sin_a, 0.0f, cos_a, 0.0f,
136  0.0f , 0.0f, 0.0f , 1.0f
137  );
138  }
139 
141  glm::mat4 RotMatZ(float angle_rad)
142  {
143  float cos_a, sin_a;
144 
145  cos_a = cos(angle_rad);
146  sin_a = sin(angle_rad);
147 
148  return glm::mat4(
149  cos_a, sin_a, 0.0f, 0.0f,
150  -sin_a, cos_a, 0.0f, 0.0f,
151  0.0f , 0.0f , 1.0f, 0.0f,
152  0.0f , 0.0f , 0.0f, 1.0f
153  );
154  }
155 };
156 
157 }
158 
159 #endif
160 #endif
OpenGLMbs
Definition: MpegFrameCaptureOptions.hh:6
MbsWorld3D.hh
MbsWorld3D class.
Joint3D.hh
Joint3D class.
Mbs3DComponent.hh
Mbs3DComponent class.
Base3D.hh
Base3D class.