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
00045
00046
00047
00048
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
00055
00056
00057 mBody2->setPosition( mBody1->position() + mBodyPosition2 -
00058 mBodyPosition2 );
00059 }
00060
00061 private:
00062 EntityTypePtr mBody1, mBody2;
00063 gmtl::Vec3f mBodyPosition1, mBodyPosition2;
00064 };
00065 }
00066
00067
00068
00069
00070 #endif