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/Dynamics/Convert.h

Go to the documentation of this file.
00001 #ifndef ANIMATION_PRIMITIVE_CONVERTERS
00002 #define ANIMATION_PRIMITIVE_CONVERTERS
00003 
00004 #include <gmtl/Output.h>
00005 
00006 namespace ani
00007 {
00011    inline gmtl::Matrix44f matrix( const ani::Body& body ) 
00012    {
00013       gmtl::Matrix44f trans, rot;
00014       gmtl::setTrans( trans, (gmtl::Vec3f)body.position() );
00015       gmtl::set( rot, body.rotation() );
00016 
00017       return trans * rot; 
00018    }
00019 
00023    inline gmtl::Matrix44f invMatrix( const ani::Body& body ) 
00024    {
00025       gmtl::Matrix44f mat( matrix( body ) );
00026       return gmtl::invert( mat );
00027    }
00028 
00029    inline std::vector<gmtl::Point3f> getLocalBox( const ani::Body& body )
00030    {
00031       std::vector<gmtl::Point3f> corners;
00032       corners.resize( 8 );
00033       assert( corners.size() == 8 );
00034       corners[0].set( 1.0f, 1.0f, 1.0f );
00035       corners[1].set( 1.0f, 1.0f, -1.0f );
00036       corners[2].set( 1.0f, -1.0f, 1.0f );
00037       corners[3].set( 1.0f, -1.0f, -1.0f );
00038       corners[4].set( -1.0f, 1.0f, 1.0f );
00039       corners[5].set( -1.0f, 1.0f, -1.0f );
00040       corners[6].set( -1.0f, -1.0f, 1.0f );
00041       corners[7].set( -1.0f, -1.0f, -1.0f );
00042 
00043       for (unsigned int x = 0; x < corners.size(); ++x)
00044       {
00045          // expand the unit cube to the volume size.
00046          (corners[x])[0] *= body.volume()[0];
00047          (corners[x])[1] *= body.volume()[1];
00048          (corners[x])[2] *= body.volume()[2];
00049 
00050          // rotate the cube.
00051          gmtl::xform( corners[x], body.rotation(), corners[x] );
00052       }
00053       return corners;
00054    }
00055 
00056    inline std::vector<gmtl::Point3f> getWorldBox( const ani::Body& body )
00057    {
00058       std::vector<gmtl::Point3f> corners = getLocalBox( body );
00059       for (unsigned int x = 0; x < corners.size(); ++x)
00060       {
00061          // translate the cube
00062          corners[x] += body.position();
00063       }
00064       return corners;
00065    }
00066 };
00067 
00068 #endif

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