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

c:/home/kevn/src/animaniac/ani/KeyFrame/PosQuatKey.h

Go to the documentation of this file.
00001 
00002 /*************** <auto-copyright.pl BEGIN do not edit this line> **************
00003  *
00004  * Animaniac is (C) Copyright 2000,2001 Kevin Meinert
00005  *
00006  * Original Authors:
00007  *   Kevin Meinert
00008  *
00009  *
00010  *
00011  * This library is free software; you can redistribute it and/or
00012  * modify it under the terms of the GNU Library General Public
00013  * License as published by the Free Software Foundation; either
00014  * version 2 of the License, or (at your option) any later version.
00015  *
00016  * This library is distributed in the hope that it will be useful,
00017  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00018  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00019  * Library General Public License for more details.
00020  *
00021  * You should have received a copy of the GNU Library General Public
00022  * License along with this library; if not, write to the
00023  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00024  * Boston, MA 02111-1307, USA.
00025  *
00026  * -----------------------------------------------------------------
00027  * File:          $RCSfile: PosQuatKey.h,v $
00028  * Date modified: $Date: 2002/06/10 03:08:01 $
00029  * Version:       $Revision: 1.8 $
00030  * -----------------------------------------------------------------
00031  *
00032  *************** <auto-copyright.pl END do not edit this line> ***************/
00033 
00034 
00035 // NOTE: for best results, read this file using an editor that supports
00036 // color syntax highlighting.  (i.e. nedit, gvim, visual studio, visual 
00037 // slick edit)
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    //: One Key for the KeyFramer
00054    class PosQuatKey : public ani::Key
00055    {
00056    public:
00057       PosQuatKey() : Key(), mRot(), mPos()
00058       {
00059       }
00060       // matrix constructor
00061       PosQuatKey( const float& timeVal, const gmtl::Matrix44f& mat ) : Key( timeVal )
00062       {
00063          this->setTime( timeVal );
00064          gmtl::set( mRot, mat );
00065          //mRot.makeRot( mat ); // juggler
00066          gmtl::setTrans( mPos, mat ); 
00067       }
00068       // pos/quat constructor
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          // base class functionality 
00090          this->setTime( key.time() );
00091          
00092          mRot = key.mRot;
00093          mPos = key.mPos;
00094       }
00095       
00096    // set/get
00097    public:
00098       // quat/pos -> matrix conversion
00099       // navMatrix == false for animating objects
00100       //              true if you are animating a nav matrix
00101       inline void getMatrix( gmtl::Matrix44f& mat, bool navMatrix = true ) const
00102       {  
00103          // premult if doing navigation, post if not...
00104          if (navMatrix == true)
00105          {
00106             gmtl::Matrix44f rot;
00107             gmtl::Matrix44f pos;
00108             gmtl::set( rot, mRot );
00109             // rot.makekev::Quaternion( mRot );
00110             gmtl::setTrans( pos, mPos );
00111             mat = rot * pos;
00112          }
00113          else
00114          {
00115             gmtl::set( mat, mRot );
00116             //mat.makeQuaternion( mRot );
00117             gmtl::setTrans( mat, mPos );
00118          }
00119       }
00120 
00121       //: set this key to the interpolated value of key0 to key1
00122       //  interp is a number from key0.time() to key1.time(), 
00123       // 
00124       // where: 
00125       //  interp == key0.time()              sets the Key to key0
00126       //  key0.time() < interp < key1.time() sets the Key to interpolated 
00127       //                                      value of key0 to key1
00128       //  interp == key1.time()              sets the Key to key1
00129       //
00131       virtual void setInterpolate( float interp, const PosQuatKey& key0, const PosQuatKey& key1 )
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          // degenerate case where you're interpolating between two keys of the same time value..
00140          if (size <= 0.00001f)
00141          {
00142             this->set( key1 );
00143             return;
00144          }
00145 
00146          // find the distance between [key0Time, time_needed, key1Time] to  [0, normalize, 1]
00147          time_needed -= gmtl::Math::Min( key0.time(), key1.time() );
00148          float normalize = time_needed / size;
00149 
00150          // interpolate. 
00151          // TODO: change the lerps to bezier curve interpolation funcs (TODO: implement those funcs too!!!)
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    // aliases
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

Generated on Wed Jun 12 01:54:02 2002 for Animaniac by doxygen1.2.15