Developer Documentation
CoordinateSystemNode.cc
1 /*===========================================================================*\
2  * *
3  * OpenFlipper *
4  * Copyright (c) 2001-2015, RWTH-Aachen University *
5  * Department of Computer Graphics and Multimedia *
6  * All rights reserved. *
7  * www.openflipper.org *
8  * *
9  *---------------------------------------------------------------------------*
10  * This file is part of OpenFlipper. *
11  *---------------------------------------------------------------------------*
12  * *
13  * Redistribution and use in source and binary forms, with or without *
14  * modification, are permitted provided that the following conditions *
15  * are met: *
16  * *
17  * 1. Redistributions of source code must retain the above copyright notice, *
18  * this list of conditions and the following disclaimer. *
19  * *
20  * 2. Redistributions in binary form must reproduce the above copyright *
21  * notice, this list of conditions and the following disclaimer in the *
22  * documentation and/or other materials provided with the distribution. *
23  * *
24  * 3. Neither the name of the copyright holder nor the names of its *
25  * contributors may be used to endorse or promote products derived from *
26  * this software without specific prior written permission. *
27  * *
28  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
29  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
30  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
31  * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
32  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
33  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
34  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
35  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
36  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
37  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
38  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
39  * *
40 \*===========================================================================*/
41 
42 /*===========================================================================*\
43  * *
44  * $Revision$ *
45  * $Author$ *
46  * $Date$ *
47  * *
48 \*===========================================================================*/
49 
50 
51 
52 
53 //=============================================================================
54 //
55 // CLASS CoordsysNode - IMPLEMENTATION
56 //
57 //=============================================================================
58 
59 //== INCLUDES =================================================================
60 
61 #include <ObjectTypes/Coordsys/CoordinateSystemNode.hh>
62 
63 
64 
65 //== NAMESPACES ===============================================================
66 
67 namespace ACG {
68 namespace SceneGraph {
69 
70 
71 //== IMPLEMENTATION ==========================================================
72 
73 
75  std::string _name)
76  : BaseNode(_parent, _name),
77  coordsysSize_(1.0),
78  slices_(10),
79  stacks_(10),
80  loops_(10)
81 {
83  sphere_ = new GLSphere(slices_, stacks_);
84  cone_ = new GLCone(slices_, stacks_, 1.0f, 1.0f, false, true);
85  cylinder_ = new GLCylinder(slices_, stacks_, 1.0f, false, false);
86  disk_ = new GLDisk(slices_, loops_, 0.1f, 1.0f);
87 }
88 
89 //----------------------------------------------------------------------------
90 
92  if (sphere_)
93  delete sphere_;
94 
95  if (cone_)
96  delete cone_;
97 
98  if (cylinder_)
99  delete cylinder_;
100 
101  if (disk_)
102  delete disk_;
103 }
104 
105 //----------------------------------------------------------------------------
106 
107 void
109 boundingBox(Vec3d& _bbMin, Vec3d& _bbMax)
110 {
111  //TODO!!
112  Vec3d topLeft = position_ + coordsysSize_ * ACG::Vec3d(1.0,1.0,1.0);
113 
114  _bbMin.minimize( topLeft );
115  _bbMin.minimize( position_ );
116 
117  _bbMax.maximize( topLeft );
118  _bbMax.maximize( position_ );
119 
120 }
121 
122 
123 //----------------------------------------------------------------------------
124 
125 
129 {
131 }
132 
133 
134 //----------------------------------------------------------------------------
135 
136 void
137 CoordinateSystemNode::
138 drawCoordsys( GLState& _state) {
139 
140  double topRadius = 0.1 * coordsysSize_;
141  double arrowLength = 0.4 * coordsysSize_;
142  double bodyRadius = 0.04 * coordsysSize_;
143  double bodyLength = 0.6 * coordsysSize_;
144  double sphereRadius = 0.1 * coordsysSize_;
145 
146  // Origin
147  glColor3f(0.5, 0.5, 0.5);
148  sphere_->draw(_state, sphereRadius);
149 
150  // X-Axis
151  glColor3f(1.0, 0.0, 0.0);
152  _state.push_modelview_matrix ();
153  _state.rotate (-90, 0, 1, 0);
154  _state.translate ( 0, 0, -bodyLength );
155  cylinder_->setBottomRadius(bodyRadius);
156  cylinder_->setTopRadius(bodyRadius);
157  cylinder_->draw(_state, bodyLength);
158  disk_->setInnerRadius(0.0f);
159  disk_->setOuterRadius(topRadius);
160  disk_->draw(_state);
161  _state.translate ( 0, 0, -arrowLength );
162  cone_->setBottomRadius(0.0f);
163  cone_->setTopRadius(topRadius);
164  cone_->draw(_state, arrowLength);
165  _state.pop_modelview_matrix ();
166 
167  // Y-Axis
168  glColor3f(0.0, 1.0, 0.0);
169  _state.push_modelview_matrix ();
170  _state.rotate (90, 1, 0, 0);
171  _state.translate ( 0, 0, -bodyLength );
172  cylinder_->draw(_state, bodyLength);
173  disk_->draw(_state);
174  _state.translate ( 0, 0, -arrowLength );
175  cone_->draw(_state, arrowLength);
176  _state.pop_modelview_matrix ();
177 
178  // Z-Axis
179  glColor3f(0.0, 0.0, 1.0);
180  _state.push_modelview_matrix ();
181  _state.rotate (180, 0, 1, 0);
182  _state.translate ( 0, 0, -bodyLength );
183  cylinder_->draw(_state, bodyLength);
184  disk_->draw(_state);
185  _state.translate ( 0, 0, -arrowLength );
186  cone_->draw(_state, arrowLength);
187  _state.pop_modelview_matrix ();
188 }
189 
190 //============================================================================
191 
192 
193 void
194 CoordinateSystemNode::drawCoordsysPick( GLState& _state) {
195 
196  double topRadius = 0.1 * coordsysSize_;
197  double arrowLength = 0.4 * coordsysSize_;
198  double bodyRadius = 0.04 * coordsysSize_;
199  double bodyLength = 0.6 * coordsysSize_;
200  double sphereRadius = 0.1 * coordsysSize_;
201 
202  // Origin
203  _state.pick_set_name (1);
204  sphere_->draw(_state, sphereRadius);
205 
206  // X-Axis
207  _state.pick_set_name (2);
208  _state.push_modelview_matrix ();
209  _state.rotate (-90, 0, 1, 0);
210  _state.translate ( 0, 0, -bodyLength );
211  cylinder_->setBottomRadius(bodyRadius);
212  cylinder_->setTopRadius(bodyRadius);
213  cylinder_->draw(_state, bodyLength);
214  disk_->setInnerRadius(0.0f);
215  disk_->setOuterRadius(topRadius);
216  disk_->draw(_state);
217  _state.translate ( 0, 0, -arrowLength );
218  cone_->setBottomRadius(0.0f);
219  cone_->setTopRadius(topRadius);
220  cone_->draw(_state, arrowLength);
221  _state.pop_modelview_matrix ();
222 
223  // Y-Axis
224  _state.pick_set_name (3);
225  _state.push_modelview_matrix ();
226  _state.rotate (90, 1, 0, 0);
227  _state.translate ( 0, 0, -bodyLength );
228  cylinder_->draw(_state, bodyLength);
229  disk_->draw(_state);
230  _state.translate ( 0, 0, -arrowLength );
231  cone_->draw(_state, arrowLength);
232  _state.pop_modelview_matrix ();
233 
234  // Z-Axis
235  _state.pick_set_name (4);
236  _state.push_modelview_matrix ();
237  _state.rotate (180, 0, 1, 0);
238  _state.translate ( 0, 0, -bodyLength );
239  cylinder_->draw(_state, bodyLength);
240  disk_->draw(_state);
241  _state.translate ( 0, 0, -arrowLength );
242  cone_->draw(_state, arrowLength);
243  _state.pop_modelview_matrix ();
244 }
245 
246 
247 //============================================================================
248 
249 
250 void
252 draw(GLState& _state , const DrawModes::DrawMode& /*_drawMode*/)
253 {
254  glPushAttrib(GL_ENABLE_BIT);
255 
256  // Push Modelview-Matrix
257  _state.push_modelview_matrix();
258 
259  Vec4f lastBaseColor = _state.base_color();
260 
261  glColorMaterial ( GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE ) ;
262  ACG::GLState::enable(GL_COLOR_MATERIAL);
263  ACG::GLState::enable(GL_LIGHTING);
264  ACG::GLState::shadeModel(GL_SMOOTH);
265 
266  // Translate to right position
267  _state.translate(position_);
268 
269  // Apply rotation matrix
270  GLMatrixd modelview = _state.modelview();
271  modelview *= rotation_;
272  _state.set_modelview(modelview);
273 
274  // Draw coordsys
275  drawCoordsys(_state);
276 
277  glColor4fv(lastBaseColor.data());
278 
279  // Reload old configuration
280  _state.pop_modelview_matrix();
281 
282  glPopAttrib();
283 }
284 
285 
286 void
288 position(const Vec3d& _pos)
289 {
290  position_ = _pos;
291 }
292 
293 
294 Vec3d
297  return position_;
298 }
299 
301 {
302  rotation_ = _rotation;
303 }
304 
306 {
307  return rotation_;
308 }
309 
310 
311 void
313 size(const double _size) {
314  coordsysSize_ = _size;
315 }
316 
317 double
319 size() {
320  return coordsysSize_;
321 }
322 
323 
324 void
326 {
327 
328 
329  if (_target == PICK_ANYTHING) {
330 
331  _state.pick_set_maximum(5);
332  _state.pick_set_name(0);
333 
334  // Push Modelview-Matrix
335  _state.push_modelview_matrix();
336 
337  // Translate to right position
338  _state.translate(position_);
339 
340  // Apply rotation matrix
341  GLMatrixd modelview = _state.modelview();
342  modelview *= rotation_;
343  _state.set_modelview(modelview);
344 
345  // Koordinatensystem zeichnen
346  drawCoordsysPick(_state);
347 
348  // Reload old configuration
349  _state.pop_modelview_matrix();
350 
351  }
352 }
353 
354 
355 //=============================================================================
356 } // namespace SceneGraph
357 } // namespace ACG
358 //=============================================================================
DrawMode SOLID_SMOOTH_SHADED
draw smooth shaded (Gouraud shaded) faces (requires halfedge normals)
Definition: DrawModes.cc:88
void draw(GLState &_state, const DrawModes::DrawMode &_drawMode)
draw Coordsys
void push_modelview_matrix()
push modelview matrix
Definition: GLState.cc:1006
Matrix4x4d rotation()
Get current rotation of the coordinate system;.
PickTarget
What target to use for picking.
Definition: BaseNode.hh:99
void identity()
setup an identity matrix
Definition: Matrix4x4T.cc:256
vector_type & maximize(const vector_type &_rhs)
maximize values: same as *this = max(*this, _rhs), but faster
Definition: Vector11T.hh:562
static void enable(GLenum _cap)
replaces glEnable, but supports locking
CoordinateSystemNode(BaseNode *_parent=0, std::string _name="<TextNode>")
const Vec4f & base_color() const
get base color (used when lighting is off)
Definition: GLState.hh:929
Vec3d position()
Get current position of the coordinate system;.
Vec3d position_
3d position of the coordsys origin
void translate(double _x, double _y, double _z, MultiplyFrom _mult_from=MULT_FROM_RIGHT)
translate by (_x, _y, _z)
Definition: GLState.cc:531
bool pick_set_maximum(unsigned int _idx)
Set the maximal number of primitives/components of your object.
Definition: GLState.cc:1047
void set_modelview(const GLMatrixd &_m)
set modelview
Definition: GLState.hh:731
Namespace providing different geometric functions concerning angles.
Definition: DBSCANT.cc:51
void pop_modelview_matrix()
pop modelview matrix
Definition: GLState.cc:1022
void pick_set_name(unsigned int _idx)
sets the current name/color (like glLoadName(_idx))
Definition: GLState.cc:1057
void rotate(double _angle, double _x, double _y, double _z, MultiplyFrom _mult_from=MULT_FROM_RIGHT)
rotate around axis (_x, _y, _z) by _angle
Definition: GLState.cc:562
const GLMatrixd & modelview() const
get modelview matrix
Definition: GLState.hh:794
void pick(GLState &_state, PickTarget _target)
draw Coordsys for object picking
pick any of the prior targets (should be implemented for all nodes)
Definition: BaseNode.hh:110
vector_type & minimize(const vector_type &_rhs)
minimize values: same as *this = min(*this, _rhs), but faster
Definition: Vector11T.hh:534
double coordsysSize_
Size of the coordsys.
Matrix4x4d rotation_
Orientation of coordsys.
VectorT< double, 3 > Vec3d
Definition: VectorT.hh:127
void boundingBox(Vec3d &_bbMin, Vec3d &_bbMax)
update bounding box
ACG::SceneGraph::DrawModes::DrawMode availableDrawModes() const
return available draw modes
static void shadeModel(GLenum _mode)
replaces glShadeModel, supports locking
Scalar * data()
access to Scalar array
Definition: Vector11T.hh:193