00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039 #ifndef ANIMANIAC_POSITION_ORIENTATION_KEY
00040 #define ANIMANIAC_POSITION_ORIENTATION_KEY
00041
00042 #include <assert.h>
00043 #include <gmtl/Vec.h>
00044 #include <gmtl/Matrix.h>
00045 #include <gmtl/Quat.h>
00046 #include <gmtl/Math.h>
00047 #include <gmtl/Generate.h>
00048
00049 #include "ani/KeyFrame/Key.h"
00050
00051 namespace ani
00052 {
00053
00054 class PosQuatKey : public ani::Key
00055 {
00056 public:
00057 PosQuatKey() : Key(), mRot(), mPos()
00058 {
00059 }
00060
00061 PosQuatKey( const float& timeVal, const gmtl::Matrix44f& mat ) : Key( timeVal )
00062 {
00063 this->setTime( timeVal );
00064 gmtl::set( mRot, mat );
00065
00066 gmtl::setTrans( mPos, mat );
00067 }
00068
00069 PosQuatKey( const float& timeVal, const gmtl::Vec3f& pos, const gmtl::Quatf& rot ) : Key( timeVal )
00070 {
00071 this->setTime( timeVal );
00072 mRot = rot;
00073 mPos = pos;
00074 }
00075
00076 PosQuatKey( const PosQuatKey& key )
00077 {
00078 this->set( key );
00079 }
00080
00081 PosQuatKey& operator=( const PosQuatKey& key )
00082 {
00083 this->set( key );
00084 return *this;
00085 }
00086
00087 virtual void set( const PosQuatKey& key )
00088 {
00089
00090 this->setTime( key.time() );
00091
00092 mRot = key.mRot;
00093 mPos = key.mPos;
00094 }
00095
00096
00097 public:
00098
00099
00100
00101 inline void getMatrix( gmtl::Matrix44f& mat, bool navMatrix = true ) const
00102 {
00103
00104 if (navMatrix == true)
00105 {
00106 gmtl::Matrix44f rot;
00107 gmtl::Matrix44f pos;
00108 gmtl::set( rot, mRot );
00109
00110 gmtl::setTrans( pos, mPos );
00111 mat = rot * pos;
00112 }
00113 else
00114 {
00115 gmtl::set( mat, mRot );
00116
00117 gmtl::setTrans( mat, mPos );
00118 }
00119 }
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00131
00132 {
00133 float time_needed( interp );
00134 assert( (time_needed >= key1.time() && time_needed <= key0.time()) ||
00135 (time_needed >= key0.time() && time_needed <= key1.time()) &&
00136 "time_needed need to be in between the two times" );
00137 float size = gmtl::Math::abs( key1.time() - key0.time() );
00138
00139
00140 if (size <= 0.00001f)
00141 {
00142 this->set( key1 );
00143 return;
00144 }
00145
00146
00147 time_needed -= gmtl::Math::Min( key0.time(), key1.time() );
00148 float normalize = time_needed / size;
00149
00150
00151
00152 gmtl::Math::lerp( this->time(), normalize, key0.time(), key1.time() );
00153 gmtl::lerp( this->position(), normalize, key0.position(), key1.position() );
00154 gmtl::slerp( this->rotation(), normalize, key0.rotation(), key1.rotation() );
00155 }
00156
00157
00158 public:
00159 const gmtl::Quatf& rotation() const { return mRot; }
00160 const gmtl::Vec3f& position() const { return mPos; }
00161 gmtl::Quatf& rotation() { return mRot; }
00162 gmtl::Vec3f& position() { return mPos; }
00163
00164 private:
00165 gmtl::Quatf mRot;
00166 gmtl::Vec3f mPos;
00167 };
00168
00169 };
00170
00171 #endif