source: projectionDesigner/trunk/projdesigner/include/gmtl/EulerAngle.h @ 210

Last change on this file since 210 was 4, checked in by Torben Dannhauer, 15 years ago
File size: 5.1 KB
RevLine 
[4]1/************************************************************** ggt-head beg
2 *
3 * GGT: Generic Graphics Toolkit
4 *
5 * Original Authors:
6 *   Allen Bierbaum
7 *
8 * -----------------------------------------------------------------
9 * File:          EulerAngle.h,v
10 * Date modified: 2003/04/01 13:21:47
11 * Version:       1.11
12 * -----------------------------------------------------------------
13 *
14 *********************************************************** ggt-head end */
15/*************************************************************** ggt-cpr beg
16*
17* GGT: The Generic Graphics Toolkit
18* Copyright (C) 2001,2002 Allen Bierbaum
19*
20* This library is free software; you can redistribute it and/or
21* modify it under the terms of the GNU Lesser General Public
22* License as published by the Free Software Foundation; either
23* version 2.1 of the License, or (at your option) any later version.
24*
25* This library is distributed in the hope that it will be useful,
26* but WITHOUT ANY WARRANTY; without even the implied warranty of
27* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
28* Lesser General Public License for more details.
29*
30* You should have received a copy of the GNU Lesser General Public
31* License along with this library; if not, write to the Free Software
32* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
33*
34 ************************************************************ ggt-cpr end */
35#ifndef _GMTL_EULERANGLE_H_
36#define _GMTL_EULERANGLE_H_
37
38#include <gmtl/Math.h>     // for rotation order
39 
40namespace gmtl
41{
42
43/** EulerAngle: Represents a group of euler angles.
44 *  Euler angle can be used to represent rotations in 3-space.
45 *
46 *  To some people this rotation format can be more intuitive to specify than
47 *  Matrix, Quat, or AxisAngle formatted rotation.
48 *
49 *  For efficiency and to minimize problems from gimbal-lock, you should use
50 *  one of the other rotation formats instead (Quat or Matrix are preferred).
51 *
52 *  The internal data format is an array of 3 DATA_TYPE angle values,
53 *  plus a RotationOrder that specifies how to build a rotation transform
54 *  from the 3 angle value.
55 *
56 *  IMPORTANT:
57 *  The 3 angles are in the order set ::getOrder(), not XYZ.
58 *  The values do not swap when order is changed after setting the angles.
59 *
60 * @pre all angles are in radians.
61 *
62 * @see EulerAnglef, EulerAngled
63 * @see Matrix, Quat, AxisAngle
64 * @ingroup Types
65 */
66template <typename DATA_TYPE, typename ROTATION_ORDER>
67class EulerAngle
68{
69public:
70   /// Use this to declare single value types of the same type as this object.
71   typedef DATA_TYPE DataType;
72
73   enum Params { Size = 3, Order = ROTATION_ORDER::ID };
74
75   /** default constructor. initializes to identity rotation (no rotation). */
76   EulerAngle()
77   {
78      gmtlASSERT( ROTATION_ORDER::IS_ROTORDER == 1 && 
79            "you must specify a RotationOrder derived type for the rotationorder in euler angle." );
80      mData[0] = DATA_TYPE( 0 );
81      mData[1] = DATA_TYPE( 0 );
82      mData[2] = DATA_TYPE( 0 );
83   }
84
85   /** copy constructor. */
86   EulerAngle( const EulerAngle& e )
87   {
88      mData[0] = e.mData[0];
89      mData[1] = e.mData[1];
90      mData[2] = e.mData[2];
91   }
92
93   /** data constructor.   angles are in radians. */
94   EulerAngle( DATA_TYPE p0, DATA_TYPE p1, DATA_TYPE p2 )
95   {
96      mData[0] = p0;
97      mData[1] = p1;
98      mData[2] = p2;
99   }
100   
101   /** set data.   angles are in radians. */
102   void set( const DATA_TYPE& p0, const DATA_TYPE& p1, 
103             const DATA_TYPE& p2 )
104   {
105      mData[0] = p0;
106      mData[1] = p1;
107      mData[2] = p2;
108   }
109   
110   //@{
111   /** Gets the ith component in this EulerAngle.
112    *  @param i    the zero-based index of the component to access.
113    *  @pre 0 <= i < 3
114    *  @return  a reference to the ith component
115    */
116   inline DATA_TYPE& operator[]( const unsigned i )
117   {
118      gmtlASSERT( i < Size );
119      return mData[i];
120   }
121   inline const DATA_TYPE&  operator[]( const unsigned i ) const
122   {
123      gmtlASSERT( i < Size );
124      return mData[i];
125   }
126   //@}
127   
128   //@{
129   /** Gets the internal array of the components.
130    *  @return  a pointer to the component array with length SIZE
131    */
132   DATA_TYPE* getData() { return mData; }
133   
134   /** Gets the internal array of the components (const version)
135    *  @return  a pointer to the component array with length SIZE
136    */
137   const DATA_TYPE* getData() const { return mData; }
138   //@}
139   
140private:
141   DATA_TYPE mData[Size];
142};
143
144const EulerAngle<float, XYZ> EULERANGLE_IDENTITY_XYZF( 0.0f, 0.0f, 0.0f );
145const EulerAngle<double, XYZ> EULERANGLE_IDENTITY_XYZD( 0.0, 0.0, 0.0 );
146const EulerAngle<float, ZYX> EULERANGLE_IDENTITY_ZYXF( 0.0f, 0.0f, 0.0f );
147const EulerAngle<double, ZYX> EULERANGLE_IDENTITY_ZYXD( 0.0, 0.0, 0.0 );
148const EulerAngle<float, ZXY> EULERANGLE_IDENTITY_ZXYF( 0.0f, 0.0f, 0.0f );
149const EulerAngle<double, ZXY> EULERANGLE_IDENTITY_ZXYD( 0.0, 0.0, 0.0 );
150
151typedef EulerAngle<float, XYZ> EulerAngleXYZf;
152typedef EulerAngle<double, XYZ> EulerAngleXYZd;
153typedef EulerAngle<float, ZYX> EulerAngleZYXf;
154typedef EulerAngle<double, ZYX> EulerAngleZYXd;
155typedef EulerAngle<float, ZXY> EulerAngleZXYf;
156typedef EulerAngle<double, ZXY> EulerAngleZXYd;
157
158} // end of namespace gmtl
159
160#endif
Note: See TracBrowser for help on using the repository browser.