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/io/KeyFramerImporter.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: KeyFramerImporter.h,v $
00028  * Date modified: $Date: 2002/06/11 22:10:57 $
00029  * Version:       $Revision: 1.7 $
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 #include <fstream>              // for ifstream
00040 #include <gmtl/Matrix.h>
00041 #include <gmtl/Vec.h>
00042 #include <gmtl/Quat.h>
00043 #include <gmtl/Generate.h>
00044 #include <gmtl/Math.h>
00045 
00046 #include "ani/KeyFrame/KeyFramer.h"  // for the KeyFramer class
00047 #include "ani/KeyFrame/PosQuatKey.h"
00048 
00049 namespace ani
00050 {
00051    class KeyFramerImporter
00052    {
00053    public:
00054       KeyFramerImporter()
00055       {
00056       }
00057 
00058       void output( ani::PosQuatKey& key )
00059       {
00060          gmtl::AxisAnglef aangle;
00061          gmtl::set( aangle, key.rotation() );
00062          std::cout<<"KEY "<<key.time()<<": "<<key.position()[0]<<", \t"<<key.position()[1]<<", \t"<<key.position()[2]<<", |#| "<<gmtl::Math::rad2Deg( aangle[0] )<<", "<<aangle[1]<<", "<<aangle[2]<<", "<<aangle[3]<<"\n"<<std::flush;
00063       }
00064    
00065       void execute( const char* const filename, ani::KeyFramer<PosQuatKey>& kf )
00066       {
00067          kf.clear();
00068          
00069          std::ifstream frames_file( filename, std::ios::in );
00070                             
00071          if (frames_file.bad())
00072          {
00073             std::cout << "WARNING: "
00074                            << "couldn't open keyframe file: " 
00075                            << filename <<"\n"
00076                            << std::flush;
00077             return;
00078          }
00079          
00080          std::cout << "Reading keyframe(s) in file: "
00081                 <<filename<<"\n"<<std::flush;
00082          
00083          float time;
00084          float deg;
00085          gmtl::Vec3f vec;
00086          gmtl::Vec3f pos;
00087          while (!frames_file.eof())
00088          {
00089             frames_file>>time;
00090             
00091             // if EOF then return...
00092             if (time == -1)
00093             {
00094                std::cout<<"time==-1: "<<time<<"\n"<<std::flush;
00095                return;
00096             }
00097             frames_file>>pos[0]>>pos[1]>>pos[2]>>deg>>vec[0]>>vec[1]>>vec[2];
00098             
00099             // convert [TWIST, VEC] to Quat
00100             gmtl::Quatf rot;
00101             float rad = gmtl::Math::deg2Rad( deg );
00102             gmtl::normalize( vec );
00103             gmtl::set( rot, gmtl::AxisAnglef( rad, vec ) );
00104          
00105             ani::PosQuatKey key( time, pos, rot );
00106             kf.addkey( key );
00107             output( key );
00108          }
00109       }   
00110    };
00111 };

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