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
lvr2::Renderable::pitch
void pitch(bool invert=0)
Definition: Renderable.cpp:187
lvr2::Renderable::m_visible
bool m_visible
Definition: Renderable.hpp:142
lvr2::Renderable::rotX
void rotX(bool invert=0)
Definition: Renderable.cpp:213
lvr2::Renderable::roll
void roll(bool invert=0)
Definition: Renderable.cpp:200
lvr2::Matrix4
A 4x4 matrix class implementation for use with the provided vertex types.
Definition: Matrix4.hpp:64
lvr2::Renderable::strafe
void strafe(bool invert=0)
Definition: Renderable.cpp:281
lvr2::Renderable::m_model
ModelPtr m_model
Definition: Renderable.hpp:167
lvr2::Renderable::computeMatrix
void computeMatrix()
Definition: Renderable.cpp:296
lvr2::Renderable::yaw
void yaw(bool invert=0)
Definition: Renderable.cpp:175
lvr2::Renderable::m_scaleFactor
float m_scaleFactor
Definition: Renderable.hpp:154
lvr2::Renderable::m_z_Axis
Normal< typename Vec::CoordType > m_z_Axis
Definition: Renderable.hpp:160
lvr2::Quaternion
Definition: Quaternion.hpp:64
lvr2::Renderable::m_selected
bool m_selected
Definition: Renderable.hpp:145
lvr2::Renderable::lift
void lift(bool invert=0)
Definition: Renderable.cpp:272
lvr2::BaseVector::x
CoordT x
Definition: BaseVector.hpp:65
lvr2::Quaternion::fromAxis
void fromAxis(ValueType *vec, ValueType angle)
lvr2::Renderable::setTransformationMatrix
void setTransformationMatrix(Matrix4< Vec > m)
Definition: Renderable.cpp:359
lvr2::Renderable::m_name
string m_name
Definition: Renderable.hpp:156
lvr2::Normal< typename Vec::CoordType >
lvr2::Renderable::m_boundingBox
BoundingBox< Vec > * m_boundingBox
Definition: Renderable.hpp:165
lvr2::Renderable::m_xAxis
Normal< typename Vec::CoordType > m_xAxis
Definition: Renderable.hpp:158
lvr2::Renderable::m_rotationSpeed
float m_rotationSpeed
Definition: Renderable.hpp:152
lvr2::Renderable::m_transformation
Matrix4< Vec > m_transformation
Definition: Renderable.hpp:164
lvr2::BaseVector::y
CoordT y
Definition: BaseVector.hpp:66
lvr2::Renderable::m_translationSpeed
float m_translationSpeed
Definition: Renderable.hpp:153
lvr2::Renderable::m_lineWidth
float m_lineWidth
Definition: Renderable.hpp:169
lvr2::Renderable::m_axesListIndex
int m_axesListIndex
Definition: Renderable.hpp:150
lvr2::Renderable
Definition: Renderable.hpp:65
Renderable.hpp
lvr2::Renderable::m_active
bool m_active
Definition: Renderable.hpp:144
lvr2::Renderable::Renderable
Renderable()
Definition: Renderable.cpp:40
lvr2::Renderable::m_yAxis
Normal< typename Vec::CoordType > m_yAxis
Definition: Renderable.hpp:159
lvr2::Renderable::m_showAxes
bool m_showAxes
Definition: Renderable.hpp:143
lvr2::BoundingBox
A dynamic bounding box class.
Definition: BoundingBox.hpp:49
lvr2::Renderable::m_activeListIndex
int m_activeListIndex
Definition: Renderable.hpp:149
lvr2::Renderable::Vec
BaseVector< float > Vec
Definition: Renderable.hpp:69
lvr2::Renderable::scale
void scale(float s)
Definition: Renderable.cpp:161
lvr2::BaseVector::z
CoordT z
Definition: BaseVector.hpp:67
lvr2::Renderable::rotY
void rotY(bool invert=0)
Definition: Renderable.cpp:230
lvr2::Renderable::rotZ
void rotZ(bool invert=0)
Definition: Renderable.cpp:246
lvr2
Definition: BaseBufferManipulators.hpp:39
lvr2::Renderable::~Renderable
virtual ~Renderable()
Definition: Renderable.cpp:291
lvr2::Renderable::m_pointSize
float m_pointSize
Definition: Renderable.hpp:170
lvr2::Renderable::accel
void accel(bool invert=0)
Definition: Renderable.cpp:262
lvr2::Renderable::m_position
Vec m_position
Definition: Renderable.hpp:162
lvr2::Renderable::m_listIndex
int m_listIndex
Definition: Renderable.hpp:148
lvr2::Renderable::transform
virtual void transform()
Definition: Renderable.cpp:373
lvr2::Matrix4::set
void set(int i, ValueType value)
Sets the given index of the Matrix's data field to the provided value.
Definition: Matrix4.hpp:401
lvr2::Renderable::compileAxesList
void compileAxesList()
Definition: Renderable.cpp:329


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 Wed Mar 2 2022 00:37:24