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/gator/GlueOperator.h

Go to the documentation of this file.
00001 #ifndef GLUE_OPER
00002 #define GLUE_OPER
00003 #include <vector>
00004 #include "ani/Dynamics/Operator.h"
00005 #include "ani/Dynamics/DynamicSystem.h"
00006 
00007 namespace gator
00008 {
00012    class GlueOperator : public ani::Operator<ani::Body>
00013    {
00014    public:
00015       typedef boost::shared_ptr<ani::Body> EntityTypePtr;
00016 
00017    public:
00018       GlueOperator( EntityTypePtr& e1, gmtl::Vec3f pos1,
00019                     EntityTypePtr& e2, gmtl::Vec3f pos2 ) :
00020                                          ani::Operator<ani::Body>(),
00021                                          mBody1( e1 ), mBodyPosition1( pos1 ),
00022                                          mBody2( e2 ), mBodyPosition2( pos2 )
00023       {
00024       }
00025       
00026       virtual ~GlueOperator()
00027       {
00028       }
00029       
00031       void setEntities( EntityTypePtr& e1, gmtl::Vec3f pos1,
00032                         EntityTypePtr& e2, gmtl::Vec3f pos2 )
00033       {
00034          mBody1 = e1;
00035          mBody2 = e2;
00036          mBodyPosition1 = pos1;
00037          mBodyPosition2 = pos2;
00038          mBody2->setPosition( mBody1->position() + pos2 );
00039       }
00040 
00042       virtual void exec( ani::DynamicSystem<ani::Body>& ps, float timeDelta )
00043       {
00044          // @todo this doesn't even attempt to work...
00045 
00046          
00047          // @todo consider the torque momentum too...
00048          // force from 1 in 2's coord frame
00049          gmtl::Vec3f force_from1( mBody1->linearMomentum() - 
00050                                   mBody2->linearMomentum()), 
00051                      force_from2( mBody2->linearMomentum() -
00052                                   mBody1->linearMomentum());
00053          mBody1->applyForce( force_from2, mBodyPosition2 );
00054          //mBody2->applyForce( force_from1, mBodyPosition2 );
00055          //mBody1->setPosition( mBody2->position() + mBodyPosition1 -
00056          //mBodyPosition1 );
00057          mBody2->setPosition( mBody1->position() + mBodyPosition2 -
00058          mBodyPosition2 );
00059       }
00060 
00061    private:
00062       EntityTypePtr mBody1, mBody2;
00063       gmtl::Vec3f mBodyPosition1, mBodyPosition2;
00064    };
00065 } // end namespace gator
00066    
00067 
00068 
00069 
00070 #endif

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