source: projectionDesigner/trunk/projdesigner/include/gmtl/AxisAngle.h @ 373

Last change on this file since 373 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:          AxisAngle.h,v
10 * Date modified: 2003/03/30 00:56:58
11 * Version:       1.4
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_AXISANGLE_H_
36#define _GMTL_AXISANGLE_H_
37
38#include <gmtl/Math.h>     // for rotation order
39#include <gmtl/VecBase.h>  // base class of AxisAngle
40#include <gmtl/Vec.h>      // axis data format
41 
42namespace gmtl
43{
44
45/** AxisAngle: Represents a "twist about an axis"
46 *  AxisAngle is used to specify a rotation in 3-space.
47 *
48 *  To some people this rotation format can be more intuitive to specify than
49 *  Matrix, Quat, or EulerAngle formatted rotation.
50 *
51 *  AxisAngle is very similar to Quat, except it is human readable.
52 *  For efficiency, you should use Quat instead (Quat or Matrix are preferred).
53 *
54 *  The internal data format is an array of 4 DATA_TYPE values.
55 *  Angle is first, the axis is the last 3.
56 *
57 * @pre angles are in radians, the axis is usually normalized by the user.
58 *
59 * @see AxisAnglef, AxisAngled
60 * @see Matrix, Quat, EulerAngle
61 * @ingroup Types
62 */
63template <typename DATA_TYPE>
64class AxisAngle : public VecBase<DATA_TYPE, 4>
65{
66public:
67   enum Params { Size = 4 };
68   
69   /** default constructor. initializes to identity rotation (no rotation). */
70   AxisAngle() : 
71      VecBase<DATA_TYPE, 4>( (DATA_TYPE)0.0, (DATA_TYPE)1.0, 
72                             (DATA_TYPE)0.0, (DATA_TYPE)0.0 )
73   {
74   }
75   
76   /** copy constructor. */
77   AxisAngle( const AxisAngle& e ) : VecBase<DATA_TYPE, 4>( e )
78   {
79   }
80   
81   /** data constructor (angle/x,y,z).   angles are in radians. */
82   AxisAngle( const DATA_TYPE& rad_angle, const DATA_TYPE& x, 
83              const DATA_TYPE& y, const DATA_TYPE& z ) :
84            VecBase<DATA_TYPE, 4>( rad_angle, x, y, z )
85   {
86   }
87   
88   /** data constructor (angle/Vec3).   angles are in radians. */
89   AxisAngle( const DATA_TYPE& rad_angle, const Vec<DATA_TYPE, 3>& axis ) :
90            VecBase<DATA_TYPE, 4>( rad_angle, axis[0], axis[1], axis[2] )
91   {
92   }
93   
94   /** set raw data.   angles are in radians. */
95   void set( const DATA_TYPE& rad_angle, const DATA_TYPE& x, 
96             const DATA_TYPE& y, const DATA_TYPE& z )
97   {
98      VecBase<DATA_TYPE, 4>::set( rad_angle, x, y, z );
99   }
100   
101   /** set data.   angles are in radians. */
102   void set( const DATA_TYPE& rad_angle, const Vec<DATA_TYPE, 3>& axis )
103   {
104      VecBase<DATA_TYPE, 4>::set( rad_angle, axis[0], axis[1], axis[2] );
105   }
106   
107   /** set the axis portion of the AxisAngle
108    *   @param axis     the desired 3D vector axis to rotate about
109    *   @post           the axis of the object is set
110    */
111   void setAxis( const Vec<DATA_TYPE, 3>& axis ) 
112   { 
113      VecBase<DATA_TYPE, 4>::operator[]( 1 ) = axis[0];
114      VecBase<DATA_TYPE, 4>::operator[]( 2 ) = axis[1];
115      VecBase<DATA_TYPE, 4>::operator[]( 3 ) = axis[2];
116   }
117   
118   /** set the angle (twist) part of the AxisAngle, as a radian value.
119    *  @param rad_angle    the desired twist angle, in radians
120    *  @post the angle of the object is set
121    */
122   void setAngle( const DATA_TYPE& rad_angle ) 
123   {
124      VecBase<DATA_TYPE, 4>::operator[]( 0 ) = rad_angle;
125   }
126   
127   /** get the axis portion of the AxisAngle
128    *  @return  a vector of the axis, which may or may not be normalized.
129    */
130   Vec<DATA_TYPE, 3> getAxis() const 
131   { 
132      return Vec<DATA_TYPE, 3>( VecBase<DATA_TYPE, 4>::operator[]( 1 ),
133                                VecBase<DATA_TYPE, 4>::operator[]( 2 ),
134                                VecBase<DATA_TYPE, 4>::operator[]( 3 ) );
135   }
136   
137   /** get the angle (twist) part of the AxisAngle.
138    *  @return the twist value in radians
139    */
140   const DATA_TYPE& getAngle() const 
141   {
142      return VecBase<DATA_TYPE, 4>::operator[]( 0 );
143   }
144};
145
146const AxisAngle<float> AXISANGLE_IDENTITYF( 0.0f, 1.0f, 0.0f, 0.0f );
147const AxisAngle<double> AXISANGLE_IDENTITYD( 0.0, 1.0, 0.0, 0.0 );
148
149typedef AxisAngle<float> AxisAnglef;
150typedef AxisAngle<double> AxisAngled;
151
152} // end of namespace gmtl
153
154#endif
Note: See TracBrowser for help on using the repository browser.