Developer Documentation
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 
45 
46 
47 //=============================================================================
48 //
49 // CLASS TransformNode
50 //
51 //=============================================================================
52 
53 #ifndef ACG_TRANSFORM_NODE_HH
54 #define ACG_TRANSFORM_NODE_HH
55 
56 
57 //== INCLUDES =================================================================
58 
59 
60 #include "BaseNode.hh"
61 #include "../Math/GLMatrixT.hh"
62 #include "../Math/VectorT.hh"
63 #include "../Math/QuaternionT.hh"
64 
65 
66 //== NAMESPACES ==============================================================
67 
68 
69 namespace ACG {
70 namespace SceneGraph {
71 
72 
73 //== CLASS DEFINITION =========================================================
74 
75 
89 class ACGDLLEXPORT TransformNode : public BaseNode
90 {
91 public:
92 
93 
95  TransformNode( BaseNode* _parent=0,
96  const std::string& _name="<TransformNode>" );
97 
99  virtual ~TransformNode(){}
100 
102  ACG_CLASSNAME(TransformNode);
103 
104 
106  void enter(GLState& _state, const DrawModes::DrawMode& _drawmode) override;
108  void leave(GLState& _state, const DrawModes::DrawMode& _drawmode) override;
109 
110 
111 
113  void set_center(const Vec3d& _c) { center_ = _c; }
115  const Vec3d& center() const { return center_; }
116 
117 
120  void loadIdentity();
124  virtual void setIdentity();
125 
126 
127 
128  //--- set values ---
129 
130 
132  void translate(const Vec3d& _v);
133 
135  void setTranslation(const Vec3d& _v);
136 
139  void rotate(double _angle, const Vec3d& _axis);
140 
142  void setRotation(const Quaterniond& rotation);
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 //=============================================================================
virtual ~TransformNode()
Destructor.
const Vec3d & center() const
get center
Namespace providing different geometric functions concerning angles.
const GLMatrixd & matrix() const
Returns a const reference to the current transformation matrix.
void rotation(Vec3d &_axis, double &_angle) const
return rotation axis & angle
const GLMatrixd & inverse_scale() const
return inverse scale matrix
const GLMatrixd & inverse_matrix() const
return inverse matrix
const GLMatrixd & inverse_rotation() const
return inverse rotation matrix
void set_center(const Vec3d &_c)
set center
const Vec3d & translation() const
returns ref. to translation vector
void scale(double _s)
Add scaling to the current Transformation.
const GLMatrixd & rotation() const
return rotation matrix
const GLMatrixd & scale() const
return scale matrix
VectorT< double, 3 > Vec3d
Definition: VectorT.hh:121