source: projectionDesigner/trunk/projdesigner/include/gmtl/Coord.h @ 128

Last change on this file since 128 was 4, checked in by Torben Dannhauer, 15 years ago
File size: 7.1 KB
Line 
1/************************************************************** ggt-head beg
2 *
3 * GGT: Generic Graphics Toolkit
4 *
5 * Original Authors:
6 *   Allen Bierbaum
7 *
8 * -----------------------------------------------------------------
9 * File:          Coord.h,v
10 * Date modified: 2004/11/12 01:34:48
11 * Version:       1.16
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_COORD_H_
36#define _GMTL_COORD_H_
37
38#include <gmtl/Defines.h>
39#include <gmtl/Vec.h>
40#include <gmtl/AxisAngle.h>
41#include <gmtl/EulerAngle.h>
42#include <gmtl/Quat.h>
43#include <gmtl/Util/Meta.h>
44#include <gmtl/Util/StaticAssert.h>
45
46namespace gmtl
47{
48   
49/** coord is a position/rotation pair.
50 *  coord consists of a position element and a rotation element.
51 *
52 * <h3> "How to define an Vector/Euler pair (32 bit float precision):" </h3>
53 * \code
54 *    Coord<Vec3f, EulerAngleXYZf> myEulerCoord;
55 * \endcode
56 *
57 * <h3> "Or use the built in typedefs:" </h3>
58 * \code
59 *    CoordVec3fEulerAngleXYZf myEulerCoord;
60 *    Coord3fQuat myOtherEulerCoord;
61 * \endcode
62 * @see Vec, AxisAngle, EulerAngle
63 * @ingroup Types
64 */
65template <typename POS_TYPE, typename ROT_TYPE>
66class Coord
67{
68public:
69   Coord() : mPos(), mRot()
70   {
71   }
72   
73   typedef typename POS_TYPE::DataType DataType;
74   typedef POS_TYPE PosDataType;
75   typedef ROT_TYPE RotDataType;
76   enum Params
77   {
78       PosSize = POS_TYPE::Size,
79       RotSize = ROT_TYPE::Size
80   };
81   
82   Coord( const Coord<POS_TYPE, ROT_TYPE>& coord ) : mPos( coord.mPos ), mRot( coord.mRot )
83   {
84   }
85   
86   Coord( const POS_TYPE& pos, const ROT_TYPE& rot ) : mPos( pos ), mRot( rot )
87   {
88   }
89
90   /** @name Multi-arg Constructors
91   *  Construct objects from primitive types
92   *  Just assigns values in order to the pos and rot members' members.
93   */
94   //@{
95   Coord( DataType a0, DataType a1, DataType a2, DataType a3, DataType a4, DataType a5 )
96   {
97      GMTL_STATIC_ASSERT(PosSize == 3, Using_incorrect_number_of_args_for_type_size);
98      GMTL_STATIC_ASSERT(RotSize == 3, Using_incorrect_number_of_args_for_type_size);
99      if(PosSize == 3)
100      {
101         mPos[0] = a0; mPos[1] = a1; mPos[2] = a2;
102         mRot[0] = a3; mRot[1] = a4; mRot[2] = a5; 
103      }
104      else
105      {
106         gmtlASSERT(false && "Constructor not supported for pos size");
107      }
108   }
109
110   Coord( DataType a0, DataType a1, DataType a2, DataType a3, DataType a4, DataType a5, DataType a6 )
111   {
112      GMTL_STATIC_ASSERT( (PosSize == 3 && RotSize == 4) || (PosSize == 4 && RotSize == 3), Using_incorrect_number_of_args_for_type_size);
113      if(PosSize == 3)
114      {
115         mPos[0] = a0; mPos[1] = a1; mPos[2] = a2;
116         mRot[0] = a3; mRot[1] = a4; mRot[2] = a5; mRot[3] = a6; 
117      }
118      else if(PosSize == 4)
119      {
120         mPos[0] = a0; mPos[1] = a1; mPos[2] = a2; mPos[3] = a3;
121         mRot[0] = a4; mRot[1] = a5; mRot[2] = a6; 
122      }
123      else
124      {
125         gmtlASSERT(false && "Constructor not supported for pos size");
126      }
127
128   }
129 
130   Coord( DataType a0, DataType a1, DataType a2, DataType a3, DataType a4, DataType a5, DataType a6, DataType a7 )
131   {
132      GMTL_STATIC_ASSERT(PosSize == 4, Using_incorrect_number_of_args_for_type_size);
133      GMTL_STATIC_ASSERT(RotSize == 4, Using_incorrect_number_of_args_for_type_size);
134      if(PosSize == 4)
135      {
136         mPos[0] = a0; mPos[1] = a1; mPos[2] = a2; mPos[3] = a3;
137         mRot[0] = a4; mRot[1] = a5; mRot[2] = a6; mRot[3] = a7;   
138      }
139      else
140      {
141         gmtlASSERT(false && "Constructor not supported for pos size");
142      }
143   }
144   //@}
145
146   const POS_TYPE& getPos() const { return mPos; }
147   const ROT_TYPE& getRot() const { return mRot; }
148   
149   /// @todo what about having a pos, and a const_pos naming convention?
150   /// @todo what about having a rot, and a const_rot naming convention?
151   
152   /** accessor to the position element */
153   POS_TYPE& pos() { return mPos; }
154
155   /** accessor to the rotation element */
156   ROT_TYPE& rot() { return mRot; }
157   
158   /** const accessor to the position element */
159   //const POS_TYPE& pos() const { return mPos; }
160
161   /** const accessor to the rotation element */
162   //const ROT_TYPE& rot() const  { return mRot; }
163
164public:
165   POS_TYPE mPos;
166   ROT_TYPE mRot;
167};
168
169typedef Coord<Vec3d, EulerAngleXYZd> CoordVec3EulerAngleXYZd;
170typedef Coord<Vec3f, EulerAngleXYZf> CoordVec3EulerAngleXYZf;
171typedef Coord<Vec4d, EulerAngleXYZd> CoordVec4EulerAngleXYZd;
172typedef Coord<Vec4f, EulerAngleXYZf> CoordVec4EulerAngleXYZf;
173
174typedef Coord<Vec3d, EulerAngleZYXd> CoordVec3EulerAngleZYXd;
175typedef Coord<Vec3f, EulerAngleZYXf> CoordVec3EulerAngleZYXf;
176typedef Coord<Vec4d, EulerAngleZYXd> CoordVec4EulerAngleZYXd;
177typedef Coord<Vec4f, EulerAngleZYXf> CoordVec4EulerAngleZYXf;
178
179typedef Coord<Vec3d, EulerAngleZXYd> CoordVec3EulerAngleZXYd;
180typedef Coord<Vec3f, EulerAngleZXYf> CoordVec3EulerAngleZXYf;
181typedef Coord<Vec4d, EulerAngleZXYd> CoordVec4EulerAngleZXYd;
182typedef Coord<Vec4f, EulerAngleZXYf> CoordVec4EulerAngleZXYf;
183
184typedef Coord<Vec3d, AxisAngled> CoordVec3AxisAngled;
185typedef Coord<Vec3f, AxisAnglef> CoordVec3AxisAnglef;
186typedef Coord<Vec4d, AxisAngled> CoordVec4AxisAngled;
187typedef Coord<Vec4f, AxisAnglef> CoordVec4AxisAnglef;
188
189
190
191/** 3 elt types */
192typedef Coord<Vec3f, EulerAngleXYZf> Coord3fXYZ;
193typedef Coord<Vec3f, EulerAngleZYXf> Coord3fZYX;
194typedef Coord<Vec3f, EulerAngleZXYf> Coord3fZXY;
195typedef Coord<Vec3d, EulerAngleXYZd> Coord3dXYZ;
196typedef Coord<Vec3d, EulerAngleZYXd> Coord3dZYX;
197typedef Coord<Vec3d, EulerAngleZXYd> Coord3dZXY;
198
199/** 4 elt types */
200typedef Coord<Vec4f, EulerAngleXYZf> Coord4fXYZ;
201typedef Coord<Vec4f, EulerAngleZYXf> Coord4fZYX;
202typedef Coord<Vec4f, EulerAngleZXYf> Coord4fZXY;
203typedef Coord<Vec4d, EulerAngleXYZd> Coord4dXYZ;
204typedef Coord<Vec4d, EulerAngleZYXd> Coord4dZYX;
205typedef Coord<Vec4d, EulerAngleZXYd> Coord4dZXY;
206
207/** 3 elt types */
208typedef Coord<Vec3f, Quatf> Coord3fQuat;
209typedef Coord<Vec3d, Quatd> Coord3dQuat;
210
211/** 4 elt types */
212typedef Coord<Vec4f, Quatf> Coord4fQuat;
213typedef Coord<Vec4d, Quatd> Coord4dQuat;
214
215
216/** 3 elt types */
217typedef Coord<Vec3f, AxisAnglef> Coord3fAxisAngle;
218typedef Coord<Vec3d, AxisAngled> Coord3dAxisAngle;
219
220/** 4 elt types */
221typedef Coord<Vec4f, AxisAnglef> Coord4fAxisAngle;
222typedef Coord<Vec4d, AxisAngled> Coord4dAxisAngle;
223
224}
225
226#endif
Note: See TracBrowser for help on using the repository browser.