Main Page   Modules   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

Quat.h

Go to the documentation of this file.
00001 /************************************************************** ggt-head beg
00002  *
00003  * GGT: Generic Graphics Toolkit
00004  *
00005  * Original Authors:
00006  *   Allen Bierbaum
00007  *
00008  * -----------------------------------------------------------------
00009  * File:          $RCSfile: Quat.h,v $
00010  * Date modified: $Date: 2003/03/29 22:02:19 $
00011  * Version:       $Revision: 1.22 $
00012  * -----------------------------------------------------------------
00013  *
00014  *********************************************************** ggt-head end */
00015 /*************************************************************** ggt-cpr beg
00016 *
00017 * GGT: The Generic Graphics Toolkit
00018 * Copyright (C) 2001,2002 Allen Bierbaum
00019 *
00020 * This library is free software; you can redistribute it and/or
00021 * modify it under the terms of the GNU Lesser General Public
00022 * License as published by the Free Software Foundation; either
00023 * version 2.1 of the License, or (at your option) any later version.
00024 *
00025 * This library is distributed in the hope that it will be useful,
00026 * but WITHOUT ANY WARRANTY; without even the implied warranty of
00027 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
00028 * Lesser General Public License for more details.
00029 *
00030 * You should have received a copy of the GNU Lesser General Public
00031 * License along with this library; if not, write to the Free Software
00032 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
00033 *
00034  ************************************************************ ggt-cpr end */
00035 #ifndef _GMTL_QUAT_H_
00036 #define _GMTL_QUAT_H_
00037 
00038 #include <gmtl/Defines.h>
00039 #include <gmtl/Vec.h>
00040  
00041 namespace gmtl
00042 {
00043 
00075 template <typename DATA_TYPE>
00076 class Quat
00077 {
00078 public:
00081    typedef DATA_TYPE DataType;
00082 
00083    enum Params { Size = 4 };
00084 
00089    Quat<DATA_TYPE>()
00090          : mData( (DATA_TYPE)0.0, (DATA_TYPE)0.0, (DATA_TYPE)0.0, (DATA_TYPE)1.0 )
00091    {
00092    }
00093    
00098    Quat<DATA_TYPE>( const DATA_TYPE x, const DATA_TYPE y,
00099                     const DATA_TYPE z, const DATA_TYPE w )
00100          : mData( x, y, z, w )
00101    {
00102    }
00103 
00106    Quat<DATA_TYPE>( const Quat<DATA_TYPE>& q ) : mData( q.mData )
00107    {
00108    }
00109 
00114    void set( const DATA_TYPE x, const DATA_TYPE y, const DATA_TYPE z, const DATA_TYPE w )
00115    {
00116       mData.set( x, y, z, w );
00117    }
00118 
00122    void get( DATA_TYPE& x, DATA_TYPE& y, DATA_TYPE& z, DATA_TYPE& w )
00123    {
00124       x = mData[Xelt];
00125       y = mData[Yelt];
00126       z = mData[Zelt];
00127       w = mData[Welt];
00128    }
00129 
00144    DATA_TYPE& operator[]( const int x )
00145    {
00146       gmtlASSERT( x >= 0 && x < 4 && "out of bounds error" );
00147       return mData[x];
00148    }
00149 
00161    const DATA_TYPE& operator[]( const int x ) const
00162    {
00163       gmtlASSERT( x >= 0 && x < 4 && "out of bounds error" );
00164       return mData[x];
00165    }
00166 
00170    const DATA_TYPE*  getData() const { return (DATA_TYPE*)mData.getData();}
00171 
00172 public:
00173    // Order x, y, z, w
00174    Vec<DATA_TYPE, 4> mData;
00175 };
00176 
00177 const Quat<float> QUAT_MULT_IDENTITYF( 0.0f, 0.0f, 0.0f, 1.0f );
00178 const Quat<float> QUAT_ADD_IDENTITYF( 0.0f, 0.0f, 0.0f, 0.0f );
00179 const Quat<float> QUAT_IDENTITYF( QUAT_MULT_IDENTITYF );
00180 const Quat<double> QUAT_MULT_IDENTITYD( 0.0, 0.0, 0.0, 1.0 );
00181 const Quat<double> QUAT_ADD_IDENTITYD( 0.0, 0.0, 0.0, 0.0 );
00182 const Quat<double> QUAT_IDENTITYD( QUAT_MULT_IDENTITYD );
00183 
00184 typedef Quat<float> Quatf;
00185 typedef Quat<double> Quatd;
00186 
00187 } // end of namespace gmtl
00188 
00189 #endif

Generated on Mon Apr 7 15:28:55 2003 for GenericMathTemplateLibrary by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002