Developer Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
TransformNode.hh
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 TransformNode
56 //
57 //=============================================================================
58 
59 #ifndef ACG_TRANSFORM_NODE_HH
60 #define ACG_TRANSFORM_NODE_HH
61 
62 
63 //== INCLUDES =================================================================
64 
65 
66 #include "BaseNode.hh"
67 #include "../Math/GLMatrixT.hh"
68 #include "../Math/VectorT.hh"
69 #include "../Math/QuaternionT.hh"
70 
71 
72 //== NAMESPACES ==============================================================
73 
74 
75 namespace ACG {
76 namespace SceneGraph {
77 
78 
79 //== CLASS DEFINITION =========================================================
80 
81 
95 class ACGDLLEXPORT TransformNode : public BaseNode
96 {
97 public:
98 
99 
101  TransformNode( BaseNode* _parent=0,
102  const std::string& _name="<TransformNode>" );
103 
105  virtual ~TransformNode(){}
106 
108  ACG_CLASSNAME(TransformNode);
109 
110 
112  void enter(GLState& _state, const DrawModes::DrawMode& _drawmode);
114  void leave(GLState& _state, const DrawModes::DrawMode& _drawmode);
115 
116 
117 
119  void set_center(const Vec3d& _c) { center_ = _c; }
121  const Vec3d& center() const { return center_; }
122 
123 
126  void loadIdentity();
130  virtual void setIdentity();
131 
132 
133 
134  //--- set values ---
135 
136 
138  void translate(const Vec3d& _v);
139 
142  void rotate(double _angle, const Vec3d& _axis);
143 
145  void scale(double _s) { scale(Vec3d(_s, _s, _s)); }
146 
148  void scale(const Vec3d& _s);
149 
151  void scale(const GLMatrixd& _m);
152 
153 
154  //--- get values ---
155 
156 
158  const GLMatrixd& matrix() const { return matrix_; }
160  const GLMatrixd& inverse_matrix() const { return inverse_matrix_; }
161 
163  void rotation(Vec3d& _axis, double& _angle) const {
164  quaternion_.axis_angle(_axis, _angle);
165  _angle *= 180.0/M_PI;
166  }
168  const GLMatrixd& rotation() const {
169  return rotation_matrix_;
170  }
172  const GLMatrixd& inverse_rotation() const {
173  return inverse_rotation_matrix_;
174  }
175 
176 
178  const Vec3d& translation() const { return translation_; }
179 
181  const GLMatrixd& scale() const {
182  return scale_matrix_;
183  }
185  const GLMatrixd& inverse_scale() const {
186  return inverse_scale_matrix_;
187  }
188 
189  bool apply_transformation() { return applyTransformation_; }
190 
191  void apply_transformation(bool _applyTransformation) { applyTransformation_ = _applyTransformation; }
192 
193 
194  // ortho 2d mode
195  bool is2D(){return is2DObject_;};
196  void set2D(bool _2d){is2DObject_ = _2d;};
197 
198  bool isPerSkeletonObject(){return isPerSkeletonObject_;};
199  void setPerSkeletonObject(bool _is){isPerSkeletonObject_ = _is;};
200  void setPerSkeletonModelView(GLMatrixd _is){perSkeletonModelView_ = _is;};
201 
202  void ortho2DMode(GLState& _state);
203  void perSkeletonMode(GLState& _state);
204  void update2DOffset(ACG::Vec2d _offset){offset_ += _offset;};
205  void scale2D(double _scale){scaleFactor2D_ = _scale;};
206  void setImageDimensions(ACG::Vec2i _dim){imageDimensions_ = _dim;};
207 
208 private:
209 
211  void updateMatrix();
212 
213 
214  // ELEMENTS
215  GLMatrixd matrix_, inverse_matrix_;
216  GLMatrixd rotation_matrix_, inverse_rotation_matrix_, scale_matrix_, inverse_scale_matrix_;
217  Vec3d center_;
218  Vec3d translation_;
219  Quaterniond quaternion_;
220 
221 
222  bool applyTransformation_;
223 
224 public:
225  // ortho 2d mode
226  bool is2DObject_;
227  bool isPerSkeletonObject_;
228  GLMatrixd perSkeletonModelView_;
229  double scaleFactor2D_;
230  ACG::Vec2i imageDimensions_;
231  ACG::Vec2d offset_;
232 
233 };
234 
235 
236 //=============================================================================
237 } // namespace SceneGraph
238 } // namespace ACG
239 //=============================================================================
240 #endif // ACG_TRANSFORM_NODE_HH
241 //=============================================================================
Namespace providing different geometric functions concerning angles.
Definition: DBSCANT.cc:51
void set_center(const Vec3d &_c)
set center
const GLMatrixd & inverse_scale() const
return inverse scale matrix
void rotation(Vec3d &_axis, double &_angle) const
return rotation axis & angle
VectorT< double, 3 > Vec3d
Definition: VectorT.hh:127
const Vec3d & center() const
get center
GLMatrixT< double > GLMatrixd
typedef
Definition: GLMatrixT.hh:327
4x4 matrix implementing OpenGL commands.
Definition: GLMatrixT.hh:85
const GLMatrixd & scale() const
return scale matrix
const GLMatrixd & matrix() const
Returns a const reference to the current transformation matrix.
const GLMatrixd & inverse_rotation() const
return inverse rotation matrix
virtual ~TransformNode()
Destructor.
void scale(double _s)
Add scaling to the current Transformation.
const GLMatrixd & rotation() const
return rotation matrix
const Vec3d & translation() const
returns ref. to translation vector
const GLMatrixd & inverse_matrix() const
return inverse matrix