Google

Main Page   Class Hierarchy   Compound List   File List   Compound Members  

entity.h

00001 /*
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_ENTITY_H__
00022 #define __CT_ENTITY_H__
00023 
00024 #include <stdarg.h>
00025 
00026 #include "csphyzik/phyztype.h"
00027 #include "csphyzik/force.h"
00028 #include "csphyzik/linklist.h"
00029 #include "csphyzik/refframe.h"
00030 
00031 class ctSolver;
00032 class ctPhysicalEntity;
00033 
00034 
00035 // flags
00036 #define CTF_NOREWIND 0x1
00037 
00038 // parent class of all physical bodies ( or even some non-physical ones... )
00039 class ctEntity
00040 {
00041 protected:
00042   int state_offset;
00043 
00048   ctSolver *solver;
00049 
00051   ctLinkList<ctForce> forces;
00052 
00053  public:
00054 /*
00055 **  Constructors/destructors/statics
00056 */
00057   ctEntity();
00058   virtual ~ctEntity();
00059 
00060 /*
00061 **  Member functions
00062 */
00068   virtual void solve ( real t );
00069 
00071   void set_solver ( ctSolver *pslv )
00072   { solver = pslv; }
00073 
00074   //**********  ODE interface ****************
00075   // Init values that will influence the calculation of the change in state.
00076   // These are normally forces, torques, etc.
00077   virtual void init_state() {}
00078   // Return the size of this enities state vector
00079   virtual int get_state_size() { return 0; }
00080   // Add this body's state to the state vector buffer passed in.
00081   virtual int set_state( real *sa ) = 0;
00082   // download state from buffer into this entity
00083   virtual int get_state( const real *sa ) = 0;
00084   // add change in state vector over time to state buffer parameter.
00085   virtual int set_delta_state( real *state_array ) = 0;
00086 
00087   int  get_state_offset() { return state_offset; }
00088   void set_state_offset(int of) { state_offset = of; }
00089 
00090   void add_force( ctForce *f ){ forces.add_link( f ); }
00091   void remove_force( ctForce *f ){ forces.remove_link( f ); }
00092 
00093   // add this force to the list of forces that will be applied each frame
00094   virtual void apply_given_F( ctForce &frc );
00095   void print_force() {}
00096 
00097   // collision routines.  return something we can collide with if possible
00098   virtual ctPhysicalEntity *get_collidable_entity(){ return NULL; }
00099 
00100   // Stereotype of funcs to replace flags array
00101   virtual bool will_rewind () { return !(flags & CTF_NOREWIND); }
00102   virtual void set_rewind (bool dorewind)
00103   {
00104     flags &= ~CTF_NOREWIND;
00105     if(!dorewind) flags |= CTF_NOREWIND;
00106   }
00107 
00109   unsigned long flags;
00110 };
00111 
00112 #endif // __CT_ENTITY_H__

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