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

# QuatC.h

    00001 //-------------------------------------------------------------------------
    00002 //
    00003 // File:        QuatC.h
    00004 // Desc:        Quaternion class.
    00005 // Author:      memon <memon@inside.org>
    00006 //
    00007 //-------------------------------------------------------------------------
    00008 //  Copyright (c) 2000-2002 Moppi Productions. All Rights Reserved.
    00009 //  This file is part of Moppi Demopaja SDK. For conditions of
    00010 //  distribution and use, see the accompanying license.txt file.
    00011 //  http://moppi.inside.org/demopaja/
    00012 //-------------------------------------------------------------------------
    00013
    00014 #ifndef __DEMOPAJA_QUATC_H__
    00015 #define __DEMOPAJA_QUATC_H__
    00016
    00017 #include "PajaTypes.h"
    00018 #include "Vector3C.h"
    00019 #include "Matrix3C.h"
    00020
    00021 namespace PajaTypes {
    00022
    00023     class Matrix3C;
    00024
    00026
    00032     class QuatC {
    00033     public:
    00035         QuatC( float32 f32X = 0, float32 f32Y = 0, float32 f32Z = 0, float32 f32W = 1 );
    00036
    00038         QuatC( const QuatC& rQuat );
    00039
    00041         virtual ~QuatC();
    00042
    00044         void            from_rot_matrix( const Matrix3C& rMat );
    00045
    00047         Matrix3C        to_rot_matrix() const;
    00048
    00050         void            from_axis_angle( const Vector3C& rVec, float32 f32Angle );
    00051
    00053         void            from_axis_angle( float32 f32X, float32 f32Y, float32 f32Z, float32 f32Angle );
    00054
    00056         void            to_axis_angle( Vector3C& rVec, float32& f32Angle ) const;
    00057
    00059         void            to_axis_angle( float32& f32X, float32& f32Y, float32& f32Z, float32& f32Angle ) const;
    00060
    00062         QuatC           operator-() const;
    00063
    00065
    00068         float32&        operator[]( int32 i );
    00069
    00071
    00074         const float32&  operator[]( int32 i ) const;
    00075
    00077         QuatC           operator+( const QuatC& rQuat ) const;
    00078
    00080         QuatC           operator-( const QuatC& rQuat ) const;
    00081
    00083         QuatC           operator*( const QuatC& rQuat ) const;
    00084
    00086         QuatC           operator/( const QuatC& rQuat ) const;
    00087
    00089         QuatC           operator*( float32 f32Scalar ) const;
    00090
    00092         friend QuatC    operator*( float32 f32Scalar, const QuatC& rQuat );
    00093
    00095         bool            operator==( const QuatC& rQuat ) const;
    00096
    00098         bool            operator!=( const QuatC& rQuat ) const;
    00099
    00101         float32         dot( const QuatC& rQuat ) const;
    00102
    00104         float32         norm() const;
    00105
    00107
    00108         QuatC           inverse() const;
    00109
    00111
    00112         QuatC           unit_inverse() const;
    00113
    00115         QuatC           exp() const;
    00116
    00118         QuatC           log() const;
    00119
    00121         QuatC           normalize() const;
    00122
    00124
    00131         static QuatC    slerp( float32 f32T, const QuatC& rQ, const QuatC& rP );
    00132
    00133
    00134     private:
    00135         float32 m_f32Quat[4];
    00136
    00137     };
    00138
    00139
    00140     //
    00141     //
    00142     // inlines
    00143     //
    00144     //
    00145
    00146     inline
    00147     float32&
    00148     QuatC::operator[]( int32 i )
    00149     {
    00150         assert( i >= 0 && i < 4 );
    00151         return m_f32Quat[i];
    00152     }
    00153
    00154     inline
    00155     const float32&
    00156     QuatC::operator[]( int32 i ) const
    00157     {
    00158         assert( i >= 0 && i < 4 );
    00159         return m_f32Quat[i];
    00160     }
    00161
    00162     inline
    00163     bool
    00164     QuatC::operator==( const QuatC& a ) const
    00165     {
    00166         return (m_f32Quat[0] == a.m_f32Quat[0]) &&
    00167                (m_f32Quat[1] == a.m_f32Quat[1]) &&
    00168                (m_f32Quat[2] == a.m_f32Quat[2]) &&
    00169                (m_f32Quat[3] == a.m_f32Quat[3]);
    00170     }
    00171
    00172     inline
    00173     bool
    00174     QuatC::operator!=( const QuatC& a ) const
    00175     {
    00176         return (m_f32Quat[0] != a.m_f32Quat[0]) ||
    00177                (m_f32Quat[1] != a.m_f32Quat[1]) ||
    00178                (m_f32Quat[2] != a.m_f32Quat[2]) ||
    00179                (m_f32Quat[3] != a.m_f32Quat[3]);
    00180     }
    00181
    00182     inline
    00183     QuatC
    00184     QuatC::operator+( const QuatC& rQuat ) const
    00185     {
    00186         return QuatC( m_f32Quat[0] + rQuat.m_f32Quat[0],
    00187                       m_f32Quat[1] + rQuat.m_f32Quat[1],
    00188                       m_f32Quat[2] + rQuat.m_f32Quat[2],
    00189                       m_f32Quat[3] + rQuat.m_f32Quat[3] );
    00190     }
    00191
    00192     inline
    00193     QuatC
    00194     QuatC::operator-( const QuatC& rQuat ) const
    00195     {
    00196         return QuatC( m_f32Quat[0] - rQuat.m_f32Quat[0],
    00197                       m_f32Quat[1] - rQuat.m_f32Quat[1],
    00198                       m_f32Quat[2] - rQuat.m_f32Quat[2],
    00199                       m_f32Quat[3] - rQuat.m_f32Quat[3] );
    00200     }
    00201
    00202     inline
    00203     QuatC
    00204     QuatC::operator*( float32 f32Scalar ) const
    00205     {
    00206         return QuatC( m_f32Quat[0] * f32Scalar,
    00207                       m_f32Quat[1] * f32Scalar,
    00208                       m_f32Quat[2] * f32Scalar,
    00209                       m_f32Quat[3] * f32Scalar );
    00210     }
    00211
    00212     inline
    00213     QuatC
    00214     operator*( float32 f32Scalar, const QuatC& rQuat )
    00215     {
    00216         return QuatC( rQuat[0] * f32Scalar,
    00217                       rQuat[1] * f32Scalar,
    00218                       rQuat[2] * f32Scalar,
    00219                       rQuat[3] * f32Scalar );
    00220     }
    00221
    00222     inline
    00223     QuatC
    00224     QuatC::operator-() const
    00225     {
    00226         QuatC   rRes = *this; //->normalize();
    00227         rRes = rRes.normalize();
    00228         return QuatC( -rRes.m_f32Quat[0],
    00229                       -rRes.m_f32Quat[1],
    00230                       -rRes.m_f32Quat[2],
    00231                        rRes.m_f32Quat[3] );
    00232     }
    00233
    00234     inline
    00235     float32
    00236     QuatC::dot( const QuatC& rQuat ) const
    00237     {
    00238         return m_f32Quat[0] * rQuat.m_f32Quat[0] +
    00239                m_f32Quat[1] * rQuat.m_f32Quat[1] +
    00240                m_f32Quat[2] * rQuat.m_f32Quat[2] +
    00241                m_f32Quat[3] * rQuat.m_f32Quat[3];
    00242     }
    00243
    00244     inline
    00245     float32
    00246     QuatC::norm() const
    00247     {
    00248         return m_f32Quat[0] * m_f32Quat[0] +
    00249                m_f32Quat[1] * m_f32Quat[1] +
    00250                m_f32Quat[2] * m_f32Quat[2] +
    00251                m_f32Quat[3] * m_f32Quat[3];
    00252     }
    00253
    00254
    00255     inline
    00256     QuatC
    00257     QuatC::unit_inverse() const
    00258     {
    00259         return QuatC( -m_f32Quat[0], -m_f32Quat[1], -m_f32Quat[2], m_f32Quat[3]);
    00260     }
    00261
    00262
    00263 }
    00264
    00265 #endif