00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
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
00043
00045 ctPhysicalEntity ();
00047 ctPhysicalEntity( ctReferenceFrame &ref, ctDeltaReferenceFrame &dref );
00048 virtual ~ctPhysicalEntity();
00049
00050
00051
00052
00053
00055
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
00105
00106 { F += f; }
00108 void sum_torque( const ctVector3 &t ){ T += t; }
00109
00110
00112 virtual void apply_given_F( ctForce &frc );
00114 void print_force ()
00115 { }
00116
00118 virtual ctPhysicalEntity *get_collidable_entity ()
00119 { return this; }
00120
00126 virtual void apply_impulse ( ctVector3 impulse_point, ctVector3 impulse_vector );
00127
00128
00129
00130
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
00176
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
00193
00194 protected:
00196 real m;
00197 };
00198
00199 #endif // __CT_PHYZENT_H__