Google

Main Page   Class Hierarchy   Compound List   File List   Compound Members  

forces.h

00001 /*
00002     Dynamics/Kinematics modeling and simulation library.
00003     Copyright (C) 1999 by Michael Alexander Ewert
00004                   2001 Anders Stenberg
00005 
00006     This library is free software; you can redistribute it and/or
00007     modify it under the terms of the GNU Library General Public
00008     License as published by the Free Software Foundation; either
00009     version 2 of the License, or (at your option) any later version.
00010 
00011     This library is distributed in the hope that it will be useful,
00012     but WITHOUT ANY WARRANTY; without even the implied warranty of
00013     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014     Library General Public License for more details.
00015 
00016     You should have received a copy of the GNU Library General Public
00017     License along with this library; if not, write to the Free
00018     Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00019 
00020 */
00021 
00022 #ifndef __CT_THEFORCES_H__
00023 #define __CT_THEFORCES_H__
00024 
00025 #include "csphyzik/phyzent.h"
00026 #include "csphyzik/bodyforc.h"
00027 
00028 class ctDynamicEntity;
00029 
00031 class ctGravityF : public ctForce
00032 {
00033 public:
00034   ctGravityF ( real pg = 9.81*M_PER_WORLDUNIT,
00035                ctVector3 pd = ctVector3( 0.0, -1.0, 0.0 ) );
00036 
00037   ctGravityF ( ctReferenceFrame &rf, real pg = 9.81*M_PER_WORLDUNIT,
00038                ctVector3 pd = ctVector3( 0.0, -1.0, 0.0 ) );
00039 
00040   virtual ctVector3 apply_F ( ctDynamicEntity &pe );
00041 
00042 };
00043 
00049 class ctAirResistanceF : public ctForce
00050 {
00051 public:
00052 
00053   ctAirResistanceF ( real pk = DEFAULT_AIR_RESISTANCE );
00054 
00055   virtual ctVector3 apply_F( ctDynamicEntity &pe );
00056 
00057 };
00058 
00060 class ctTorqueF : public ctForce
00061 {
00062 public:
00063   ctTorqueF ( ctVector3 dir, real pm );
00064   virtual ctVector3 apply_F ( ctDynamicEntity &pe );
00065 
00066 };
00067 
00068 class ctAppliedF : public ctForce
00069 {
00070 public:
00071   ctAppliedF ( ctVector3 dir, real pm );
00072   virtual ctVector3 apply_F ( ctDynamicEntity &pe );
00073 
00074 
00075 };
00076 
00078 class ctSpringF : public ctNBodyForce
00079 {
00080 protected:
00081   ctLinkList<ctVector3> attachment_point_vector;
00082   real rest_length;
00083 
00084 public:
00086   ctSpringF ( ctPhysicalEntity *b1, ctVector3 p1,
00087               ctPhysicalEntity *b2, ctVector3 p2 )
00088   {
00089     body_vector.add_link( b1 );
00090     attachment_point_vector.add_link( new ctVector3(p1) );
00091     body_vector.add_link( b2 );
00092     attachment_point_vector.add_link( new ctVector3(p2) );
00093     rest_length = 1;
00094   }
00095 
00096   ~ctSpringF ()
00097   {
00098     attachment_point_vector.delete_link ( attachment_point_vector.get_first() );
00099     attachment_point_vector.delete_link ( attachment_point_vector.get_first() );
00100   }
00101 
00103   void set_rest_length( real len )
00104   { rest_length = len; }
00105 
00106   virtual ctVector3 apply_F ( ctDynamicEntity &pe );
00107 
00109   virtual void add_body ( ctPhysicalEntity *bod )
00110   { if ( body_vector.get_size () < 2 ) body_vector.add_link( bod ); }
00111 };
00112 
00113 
00114 class ctCappedSpringF : public ctNBodyForce
00115 {
00116 protected:
00117   ctLinkList<ctVector3> attachment_point_vector;
00118   real cap_min, cap_max;
00119 
00120 public:
00122   ctCappedSpringF ( ctPhysicalEntity *b1, ctVector3 p1,
00123               ctPhysicalEntity *b2, ctVector3 p2 )
00124   {
00125     body_vector.add_link( b1 );
00126     attachment_point_vector.add_link( new ctVector3(p1) );
00127     body_vector.add_link( b2 );
00128     attachment_point_vector.add_link( new ctVector3(p2) );
00129     cap_min = cap_max = 1;
00130   }
00131 
00132   ~ctCappedSpringF ()
00133   {
00134     attachment_point_vector.delete_link ( attachment_point_vector.get_first() );
00135     attachment_point_vector.delete_link ( attachment_point_vector.get_first() );
00136   }
00137 
00139   void set_cap_lengths( real min, real max )
00140   { cap_min = min; cap_max = max; }
00141 
00142   virtual ctVector3 apply_F ( ctDynamicEntity &pe );
00143 
00145   virtual void add_body ( ctPhysicalEntity *bod )
00146   { if ( body_vector.get_size () < 2 ) body_vector.add_link( bod ); }
00147 };
00148 
00149 
00161 class ctGravityWell : public ctNBodyForce
00162 {
00163 public:
00164   ctGravityWell( ctPhysicalEntity *BIG_mass )
00165   {
00166     magnitude = PHYZ_CONSTANT_G;
00167     body_vector.add_link( BIG_mass );
00168   }
00169 
00171   virtual ~ctGravityWell()
00172   { }
00173 
00174   virtual ctVector3 apply_F ( ctDynamicEntity &pe );
00175 
00176 protected:
00177 
00178 };
00179 
00180 #endif // __CT_THEFORCES_H__

Generated for Crystal Space by doxygen 1.2.5 written by Dimitri van Heesch, ©1997-2000