|
phyzent.h00001 /* 00002 Dynamics/Kinematics modeling and simulation library. 00003 Copyright (C) 1999 by Michael Alexander Ewert 00004 00005 This library is free software; you can redistribute it and/or 00006 modify it under the terms of the GNU Library General Public 00007 License as published by the Free Software Foundation; either 00008 version 2 of the License, or (at your option) any later version. 00009 00010 This library is distributed in the hope that it will be useful, 00011 but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 Library General Public License for more details. 00014 00015 You should have received a copy of the GNU Library General Public 00016 License along with this library; if not, write to the Free 00017 Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00018 00019 */ 00020 00021 #ifndef __CT_PHYZENT_H__ 00022 #define __CT_PHYZENT_H__ 00023 00024 #include "csphyzik/phyztype.h" 00025 #include "csphyzik/linklist.h" 00026 #include "csphyzik/refframe.h" 00027 #include "csphyzik/entity.h" 00028 class ctForce; 00029 00030 #define DEFAULT_ENTITY_MASS 10.0 00031 00032 #define PHYSICALENTITY_STATESIZE 12 // Rmatrix, x 00033 00034 class ctSolver; 00035 class ctCollidingContact; 00036 00038 class ctPhysicalEntity : public ctEntity 00039 { 00040 public: 00041 /* 00042 ** Constructors/destructors/statics 00043 */ 00045 ctPhysicalEntity (); 00047 ctPhysicalEntity( ctReferenceFrame &ref, ctDeltaReferenceFrame &dref ); 00048 virtual ~ctPhysicalEntity(); 00049 00050 /* 00051 ** Member functions 00052 */ 00053 //********** ODE interface **************** 00055 virtual void init_state () 00056 { 00057 F[0] = 0; F[1] = 0; F[2] = 0; 00058 T[0] = 0; T[1] = 0; T[2] = 0; 00059 } 00061 virtual int get_state_size () 00062 { return PHYSICALENTITY_STATESIZE; } 00063 00068 virtual int set_state ( real *sa ); 00069 00071 virtual int get_state( const real *sa ); 00072 00074 virtual int set_delta_state( real *state_array ); 00075 00077 virtual void rotate_around_line( ctVector3 &paxis, real ptheta ); 00079 virtual void set_pos ( const ctVector3 &px ) 00080 { RF.set_offset( px ); } 00082 virtual void set_v ( const ctVector3 &pv ); 00084 virtual ctVector3 get_v () 00085 { return dRF.v; } 00087 virtual void set_angular_v ( const ctVector3 &pw ); 00089 virtual ctVector3 get_angular_v () 00090 { return dRF.w; } 00092 ctVector3 get_F () 00093 { return F; } 00095 ctVector3 get_torque () 00096 { return T; } 00098 void set_F( const ctVector3 &pF ) 00099 { F = pF; } 00101 void set_torque( const ctVector3 &pT ) 00102 { T = pT; } 00103 //void add_force( ctForce *f ){ forces.add_link( f ); } 00105 void sum_force ( const ctVector3 &f ) 00106 { F += f; } 00108 void sum_torque( const ctVector3 &t ){ T += t; } 00109 //void remove_force( ctForce *f ){ forces.remove_link( f ); } 00110 00112 virtual void apply_given_F( ctForce &frc ); 00114 void print_force () 00115 {/*cout << "F: " << F*F << "\n";*/ } 00116 00118 virtual ctPhysicalEntity *get_collidable_entity () 00119 { return this; } 00120 00126 virtual void apply_impulse ( ctVector3 impulse_point, ctVector3 impulse_vector ); 00127 00128 // virtual real get_impulse_m(){ return DEFAULT_ENTITY_MASS; } 00129 // virtual ctMatrix3 get_impulse_I_inv() { 00130 // return ctMatrix3( 1.0/get_impulse_m() ); 00131 // } 00132 00137 virtual void get_impulse_m_and_I_inv ( real *pm, ctMatrix3 *pI_inv, 00138 const ctVector3 &impulse_point, const ctVector3 &unit_length_impulse_vector ) 00139 { 00140 (void)unit_length_impulse_vector; 00141 (void)impulse_point; 00142 *pm = DEFAULT_ENTITY_MASS; 00143 pI_inv->identity(); 00144 *pI_inv *= 1.0/DEFAULT_ENTITY_MASS; 00145 } 00146 00147 const ctMatrix3 &get_R () { return RF.get_R(); } 00148 const ctMatrix3 &get_T () { return RF.get_T(); } 00149 const ctVector3 &get_pos () { return RF.get_offset(); } 00150 const ctVector3 &get_org_world () { return RF.get_offset(); } 00151 const ctMatrix3 &get_world_to_this () { return RF.get_parent_to_this(); } 00152 const ctMatrix3 &get_this_to_world () { return RF.get_this_to_parent(); } 00153 void v_this_to_world ( ctVector3 &pv ) { RF.this_to_world( pv ); } 00154 00155 ctVector3 get_v_this_to_world ( ctVector3 &pv ) 00156 { ctVector3 pret = pv; RF.this_to_world( pret ); return pret; } 00157 00158 ctReferenceFrame *get_RF() { return &RF; } 00159 ctDeltaReferenceFrame *get_dRF() { return &dRF; } 00160 00161 protected: 00162 00164 ctReferenceFrame &RF; 00166 ctDeltaReferenceFrame &dRF; 00168 ctVector3 F; 00170 ctVector3 T; 00171 }; 00172 00173 class ctSimpleDynamicsSolver; 00174 00175 // solved with ctSimpleDynamicsSolver 00176 // just a body affected by simple forces 00177 class ctDynamicEntity : public ctPhysicalEntity 00178 { 00179 public: 00180 friend class ctSimpleDynamicsSolver; 00181 00182 ctDynamicEntity(); 00183 ctDynamicEntity( ctReferenceFrame &ref, ctDeltaReferenceFrame &dref ); 00184 virtual ~ctDynamicEntity(); 00185 00186 virtual void apply_given_F( ctForce &frc ); 00187 00188 virtual void set_m ( real pm ); 00189 00190 real get_m () 00191 { return m; } 00192 // virtual real get_impulse_m () { return m; } 00193 00194 protected: 00196 real m; 00197 }; 00198 00199 #endif // __CT_PHYZENT_H__ Generated for Crystal Space by doxygen 1.2.5 written by Dimitri van Heesch, ©1997-2000 |