Renderable.cpp
Go to the documentation of this file.
1 
28  /*
29  * Renderable.cpp
30  *
31  * Created on: 26.08.2008
32  * Author: Thomas Wiemann
33  */
34 
36 
37 namespace lvr2
38 {
39 
41 {
42  m_name = "<NO NAME>";
43  m_listIndex = -1;
44  m_activeListIndex = -1;
45  m_axesListIndex = -1;
46  m_visible = true;
47 
48  m_rotationSpeed = 0.02f;
49  m_translationSpeed = 10.0f;
50  m_scaleFactor = 1.0f;
51 
52  m_lineWidth = 1.0;
53  m_pointSize = 1.0;
54 
55  m_showAxes = false;
56  m_active = true;
57  m_selected = false;
58 
59  m_xAxis = Vec(1.0f, 0.0f, 0.0f);
60  m_yAxis = Vec(0.0f, 1.0f, 0.0f);
61  m_z_Axis = Vec(0.0f, 0.0f, 1.0f);
62 
63  m_boundingBox = 0;
64 
65  m_model.reset();
66 
67  computeMatrix();
68  //compileAxesList();
69 
70 }
71 
73 {
74  m_transformation = m;
75  m_name = n;
76  m_listIndex = -1;
77  m_axesListIndex = -1;
78  m_visible = true;
79  m_rotationSpeed = 0.02f;
80  m_translationSpeed = 10.0f;
81 
82  m_scaleFactor = 1.0f;
83  m_boundingBox = 0;
84 
85  m_lineWidth = 1.0;
86  m_pointSize = 1.0;
87 
88  m_model.reset();
89  m_boundingBox = 0;
90 
91  m_showAxes = false;
92  m_active = false;
93 
95  computeMatrix();
97 }
98 
100 {
102  m_name = other.m_name;
103  m_listIndex = other.m_listIndex;
105  m_visible = other.m_visible;
108 
109  m_showAxes = other.m_showAxes;
110  m_active = other.m_active;
111 
112  m_xAxis = other.m_xAxis;
113  m_yAxis = other.m_yAxis;
114  m_z_Axis = other.m_z_Axis;
115 
117 
119 
120  m_lineWidth = 1.0;
121  m_pointSize = 1.0;
122 
123  m_model = other.m_model;
124 
125  computeMatrix();
126  compileAxesList();
127 }
128 
130 {
131  m_name = n;
132  m_visible = true;
133  m_listIndex = -1;
134  m_axesListIndex = -1;
135  m_activeListIndex = -1;
136  m_visible = true;
137  m_rotationSpeed = 0.02f;
138  m_translationSpeed = 10.0f;
139 
140  m_showAxes = false;
141  m_active = false;
142 
143  m_lineWidth = 1.0;
144  m_pointSize = 1.0;
145 
146  m_xAxis = Vec(1.0f, 0.0f, 0.0f);
147  m_yAxis = Vec(0.0f, 1.0f, 0.0f);
148  m_z_Axis = Vec(0.0f, 0.0f, 1.0f);
149 
150  m_scaleFactor = 1.0f;
151 
152  m_boundingBox = 0;
153 
154  m_model.reset();
155 
156  computeMatrix();
157  //compileAxesList();
158 
159 }
160 
161 void Renderable::scale(float d)
162 {
163 
164  m_scaleFactor = d;
165 
166  float m0 = m_transformation[0 ] * d;
167  float m5 = m_transformation[5 ] * d;
168  float m10 = m_transformation[10] * d;
169 
170  m_transformation.set(0 , m0 );
171  m_transformation.set(5 , m5 );
172  m_transformation.set(10, m10);
173 }
174 
175 void Renderable::yaw(bool invert)
176 {
177  float speed;
178  invert ? speed = m_rotationSpeed : speed = -m_rotationSpeed;
179 
180  Quaternion<Vec> q;
181  q.fromAxis(m_xAxis, speed);
182  m_yAxis = q * m_yAxis;
183  m_z_Axis = q * m_z_Axis;
184  computeMatrix();
185 }
186 
187 void Renderable::pitch(bool invert)
188 {
189  float speed;
190  invert ? speed = m_rotationSpeed : speed = -m_rotationSpeed;
191 
192  Quaternion<Vec> q;
193  q.fromAxis(m_yAxis, speed);
194  m_xAxis = q * m_xAxis;
195  m_z_Axis = q * m_z_Axis;
196 
197  computeMatrix();
198 }
199 
200 void Renderable::roll(bool invert)
201 {
202  float speed;
203  invert ? speed = m_rotationSpeed : speed = -m_rotationSpeed;
204 
205  Quaternion<Vec> q;
206  q.fromAxis(m_z_Axis, speed);
207  m_xAxis = q * m_xAxis;
208  m_yAxis = q * m_yAxis;
209 
210  computeMatrix();
211 }
212 
213 void Renderable::rotX(bool invert)
214 {
215 
216  float speed;
217  invert ? speed = m_rotationSpeed : speed = -m_rotationSpeed;
218 
219  Quaternion<Vec> q;
220  q.fromAxis(Vec(1.0, 0.0, 0.0), speed);
221 
222  m_xAxis = q * m_xAxis;
223  m_yAxis = q * m_yAxis;
224  m_z_Axis = q * m_z_Axis;
225 
226  computeMatrix();
227 
228 }
229 
230 void Renderable::rotY(bool invert)
231 {
232  float speed;
233  invert ? speed = m_rotationSpeed : speed = -m_rotationSpeed;
234 
235  Quaternion<Vec> q;
236  q.fromAxis(Vec(0.0, 1.0, 0.0), speed);
237 
238  m_xAxis = q * m_xAxis;
239  m_yAxis = q * m_yAxis;
240  m_z_Axis = q * m_z_Axis;
241 
242  computeMatrix();
243 
244 }
245 
246 void Renderable::rotZ(bool invert)
247 {
248  float speed;
249  invert ? speed = m_rotationSpeed : speed = -m_rotationSpeed;
250 
251  Quaternion<Vec> q;
252  q.fromAxis(Vec(0.0, 0.0, 1.0), speed);
253 
254  m_xAxis = q * m_xAxis;
255  m_yAxis = q * m_yAxis;
256  m_z_Axis = q * m_z_Axis;
257 
258  computeMatrix();
259 
260 }
261 
262 void Renderable::accel(bool invert)
263 {
264 
266  if(invert) direction = direction * -1;
267  m_position = m_position + direction * m_translationSpeed;
268 
269  computeMatrix();
270 }
271 
272 void Renderable::lift(bool invert)
273 {
275  if(invert) direction = direction * -1;
276  m_position = m_position + direction * m_translationSpeed;
277 
278  computeMatrix();
279 }
280 
281 void Renderable::strafe(bool invert)
282 {
283 
285  if(invert) direction = direction * -1;
286  m_position = m_position + direction * m_translationSpeed;
287 
288  computeMatrix();
289 }
290 
292  if (m_boundingBox)
293  delete m_boundingBox;
294 }
295 
297 
298  Matrix4<Vec> m;
299 
300  m.set(1 , m_xAxis.y);
301  m.set(2 , m_xAxis.z);
302 
303  m.set(4 , m_yAxis.x);
304  m.set(6 , m_yAxis.z);
305 
306  m.set(8 , m_z_Axis.x);
307  m.set(9 , m_z_Axis.y);
308 
309  m.set(12, m_position.x);
310  m.set(13, m_position.y);
311  m.set(14, m_position.z);
312 
313  if(m_scaleFactor == 1.0)
314  {
315  m.set(0 , m_xAxis.x);
316  m.set(5 , m_yAxis.y);
317  m.set(10, m_z_Axis.z);
318  }
319  else
320  {
321  m.set(0 , m_scaleFactor * m_xAxis.x);
322  m.set(5 , m_scaleFactor * m_yAxis.y);
323  m.set(10, m_scaleFactor * m_z_Axis.z);
324  }
325 
326  m_transformation = m;
327 }
328 
330 
331  m_axesListIndex = glGenLists(1);
332  glNewList(m_axesListIndex, GL_COMPILE);
333 
334  glDisable(GL_LIGHTING);
335  glBegin(GL_LINES);
336  glColor3f(1.0, 0.0, 0.0);
337  glVertex3f(-1000000, 0.0, 0.0);
338  //glVertex3f(0.0, 0.0, 0.0);
339  glVertex3f(+1000000, 0.0, 0.0);
340 
341  glColor3f(0.0, 1.0, 0.0);
342  glVertex3f(0.0, -1000000, 0.0);
343  //glVertex3f(0.0, 0.0, 0.0);
344  glVertex3f(0.0, +1000000, 0.0);
345 
346  glColor3f(0.0, 0.0, 1.0);
347  glVertex3f(0.0, 0.0, -100000);
348  //glVertex3f(0.0, 0.0, 0.0);
349  glVertex3f(0.0, 0.0, +100000);
350 
351  glEnd();
352  glEnable(GL_LIGHTING);
353  //glEnd();
354 
355  glEndList();
356 
357 }
358 
360 {
361 
362  m_transformation = m;
363  m_xAxis = Normal<typename Vec::CoordType>(m[0 ], m[1 ], m[2 ]);
364  m_yAxis = Normal<typename Vec::CoordType>(m[4 ], m[5 ], m[6 ]);
365  m_z_Axis = Normal<typename Vec::CoordType>(m[8 ], m[9 ], m[10]);
366 
367  m_position.x = m[12];
368  m_position.y = m[13];
369  m_position.z = m[14];
370 
371 }
372 
374 
375 }
376 
377 
378 } // namespace lvr2
virtual ~Renderable()
Definition: Renderable.cpp:291
float m_translationSpeed
Definition: Renderable.hpp:153
Normal< typename Vec::CoordType > m_z_Axis
Definition: Renderable.hpp:160
void yaw(bool invert=0)
Definition: Renderable.cpp:175
A 4x4 matrix class implementation for use with the provided vertex types.
Definition: Matrix4.hpp:64
Normal< typename Vec::CoordType > m_xAxis
Definition: Renderable.hpp:158
void rotX(bool invert=0)
Definition: Renderable.cpp:213
void lift(bool invert=0)
Definition: Renderable.cpp:272
BaseVector< float > Vec
Definition: Renderable.hpp:69
void strafe(bool invert=0)
Definition: Renderable.cpp:281
A dynamic bounding box class.
Definition: BoundingBox.hpp:49
void set(int i, ValueType value)
Sets the given index of the Matrix&#39;s data field to the provided value.
Definition: Matrix4.hpp:401
void pitch(bool invert=0)
Definition: Renderable.cpp:187
void compileAxesList()
Definition: Renderable.cpp:329
void roll(bool invert=0)
Definition: Renderable.cpp:200
void fromAxis(ValueType *vec, ValueType angle)
void accel(bool invert=0)
Definition: Renderable.cpp:262
virtual void transform()
Definition: Renderable.cpp:373
void setTransformationMatrix(Matrix4< Vec > m)
Definition: Renderable.cpp:359
void rotY(bool invert=0)
Definition: Renderable.cpp:230
BoundingBox< Vec > * m_boundingBox
Definition: Renderable.hpp:165
void scale(float s)
Definition: Renderable.cpp:161
Matrix4< Vec > m_transformation
Definition: Renderable.hpp:164
Normal< typename Vec::CoordType > m_yAxis
Definition: Renderable.hpp:159
void rotZ(bool invert=0)
Definition: Renderable.cpp:246


lvr2
Author(s): Thomas Wiemann , Sebastian Pütz , Alexander Mock , Lars Kiesow , Lukas Kalbertodt , Tristan Igelbrink , Johan M. von Behren , Dominik Feldschnieders , Alexander Löhr
autogenerated on Mon Feb 28 2022 22:46:09