home *** CD-ROM | disk | FTP | other *** search
/ GameStar 2006 March / Gamestar_82_2006-03_dvd.iso / DVDStar / Editace / quake4_sdkv10.exe / source / game / physics / Physics.h < prev    next >
C/C++ Source or Header  |  2005-11-14  |  9KB  |  180 lines

  1.  
  2. #ifndef __PHYSICS_H__
  3. #define __PHYSICS_H__
  4.  
  5. /*
  6. ===============================================================================
  7.  
  8.     Physics abstract class
  9.  
  10.     A physics object is a tool to manipulate the position and orientation of
  11.     an entity. The physics object is a container for idClipModels used for
  12.     collision detection. The physics deals with moving these collision models
  13.     through the world according to the laws of physics or other rules.
  14.  
  15.     The mass of a clip model is the volume of the clip model times the density.
  16.     An arbitrary mass can however be set for specific clip models or the
  17.     whole physics object. The contents of a clip model is a set of bit flags
  18.     that define the contents. The clip mask defines the contents a clip model
  19.     collides with.
  20.  
  21.     The linear velocity of a physics object is a vector that defines the
  22.     translation of the center of mass in units per second. The angular velocity
  23.     of a physics object is a vector that passes through the center of mass. The
  24.     direction of this vector defines the axis of rotation and the magnitude
  25.     defines the rate of rotation about the axis in radians per second.
  26.     The gravity is the change in velocity per second due to gravitational force.
  27.  
  28.     Entities update their visual position and orientation from the physics
  29.     using GetOrigin() and GetAxis(). Direct origin and axis changes of
  30.     entities should go through the physics. In other words the physics origin
  31.     and axis are updated first and the entity updates it's visual position
  32.     from the physics.
  33.  
  34. ===============================================================================
  35. */
  36.  
  37. #define CONTACT_EPSILON            0.25f                // maximum contact seperation distance
  38.  
  39. class idEntity;
  40.  
  41. typedef struct impactInfo_s {
  42.     float                        invMass;            // inverse mass
  43.     idMat3                        invInertiaTensor;    // inverse inertia tensor
  44.     idVec3                        position;            // impact position relative to center of mass
  45.     idVec3                        velocity;            // velocity at the impact position
  46. } impactInfo_t;
  47.  
  48.  
  49. class idPhysics : public idClass {
  50.  
  51. public:
  52.     ABSTRACT_PROTOTYPE( idPhysics );
  53.  
  54.     virtual                        ~idPhysics( void );
  55.     static int                    SnapTimeToPhysicsFrame( int t );
  56.  
  57.     // Must not be virtual
  58.     void                        Save( idSaveGame *savefile ) const;
  59.     void                        Restore( idRestoreGame *savefile );
  60.  
  61. public:    // common physics interface
  62.                                 // set pointer to entity using physics
  63.     virtual void                SetSelf( idEntity *e ) = 0;
  64.                                 // clip models
  65.     virtual void                SetClipModel( idClipModel *model, float density, int id = 0, bool freeOld = true ) = 0;
  66.     virtual void                SetClipBox( const idBounds &bounds, float density );
  67.     virtual idClipModel *        GetClipModel( int id = 0 ) const = 0;
  68.     virtual int                    GetNumClipModels( void ) const = 0;
  69.                                 // get/set the mass of a specific clip model or the whole physics object
  70.     virtual void                SetMass( float mass, int id = -1 ) = 0;
  71.     virtual float                GetMass( int id = -1 ) const = 0;
  72.  
  73. // RAVEN BEGIN
  74. // bdube: added center mass    
  75.                                 // get the center of mass origin
  76.     virtual idVec3                GetCenterMass ( int id = -1 ) const = 0;
  77. // RAVEN END
  78.  
  79.                                 // get/set the contents of a specific clip model or the whole physics object
  80.     virtual void                SetContents( int contents, int id = -1 ) = 0;
  81.     virtual int                    GetContents( int id = -1 ) const = 0;
  82.                                 // get/set the contents a specific clip model or the whole physics object collides with
  83.     virtual void                SetClipMask( int mask, int id = -1 ) = 0;
  84.     virtual int                    GetClipMask( int id = -1 ) const = 0;
  85.                                 // get the bounds of a specific clip model or the whole physics object
  86.     virtual const idBounds &    GetBounds( int id = -1 ) const = 0;
  87.     virtual const idBounds &    GetAbsBounds( int id = -1 ) const = 0;
  88.                                 // evaluate the physics with the given time step, returns true if the object moved
  89.     virtual bool                Evaluate( int timeStepMSec, int endTimeMSec ) = 0;
  90.                                 // update the time without moving
  91.     virtual void                UpdateTime( int endTimeMSec ) = 0;
  92.                                 // get the last physics update time
  93.     virtual int                    GetTime( void ) const = 0;
  94.                                 // collision interaction between different physics objects
  95.     virtual void                GetImpactInfo( const int id, const idVec3 &point, impactInfo_t *info ) const = 0;
  96.     virtual void                ApplyImpulse( const int id, const idVec3 &point, const idVec3 &impulse ) = 0;
  97.     virtual void                AddForce( const int id, const idVec3 &point, const idVec3 &force ) = 0;
  98.     virtual void                Activate( void ) = 0;
  99.     virtual void                PutToRest( void ) = 0;
  100.     virtual bool                IsAtRest( void ) const = 0;
  101.     virtual int                    GetRestStartTime( void ) const = 0;
  102.     virtual bool                IsPushable( void ) const = 0;
  103. // RAVEN BEGIN
  104. // bdube: water interraction
  105.     virtual bool                IsInWater ( void ) const = 0;
  106. // RAVEN END    
  107.                                 // save and restore the physics state
  108.     virtual void                SaveState( void ) = 0;
  109.     virtual void                RestoreState( void ) = 0;
  110.                                 // set the position and orientation in master space or world space if no master set
  111.     virtual void                SetOrigin( const idVec3 &newOrigin, int id = -1 ) = 0;
  112.     virtual void                SetAxis( const idMat3 &newAxis, int id = -1 ) = 0;
  113.                                 // translate or rotate the physics object in world space
  114.     virtual void                Translate( const idVec3 &translation, int id = -1 ) = 0;
  115.     virtual void                Rotate( const idRotation &rotation, int id = -1 ) = 0;
  116.                                 // get the position and orientation in world space
  117.     virtual const idVec3 &        GetOrigin( int id = 0 ) const = 0;
  118.     virtual const idMat3 &        GetAxis( int id = 0 ) const = 0;
  119.                                 // set linear and angular velocity
  120.     virtual void                SetLinearVelocity( const idVec3 &newLinearVelocity, int id = 0 ) = 0;
  121.     virtual void                SetAngularVelocity( const idVec3 &newAngularVelocity, int id = 0 ) = 0;
  122.                                 // get linear and angular velocity
  123.     virtual const idVec3 &        GetLinearVelocity( int id = 0 ) const = 0;
  124.     virtual const idVec3 &        GetAngularVelocity( int id = 0 ) const = 0;
  125.                                 // gravity
  126.     virtual void                SetGravity( const idVec3 &newGravity ) = 0;
  127.     virtual const idVec3 &        GetGravity( void ) const = 0;
  128.     virtual const idVec3 &        GetGravityNormal( void ) const = 0;
  129.                                 // get first collision when translating or rotating this physics object
  130.     virtual void                ClipTranslation( trace_t &results, const idVec3 &translation, const idClipModel *model ) const = 0;
  131.     virtual void                ClipRotation( trace_t &results, const idRotation &rotation, const idClipModel *model ) const = 0;
  132.     virtual int                    ClipContents( const idClipModel *model ) const = 0;
  133.                                 // disable/enable the clip models contained by this physics object
  134.     virtual void                DisableClip( void ) = 0;
  135.     virtual void                EnableClip( void ) = 0;
  136.                                 // link/unlink the clip models contained by this physics object
  137.     virtual void                UnlinkClip( void ) = 0;
  138.     virtual void                LinkClip( void ) = 0;
  139.                                 // contacts
  140.     virtual bool                EvaluateContacts( void ) = 0;
  141.     virtual int                    GetNumContacts( void ) const = 0;
  142.     virtual const contactInfo_t &GetContact( int num ) const = 0;
  143.     virtual void                ClearContacts( void ) = 0;
  144.     virtual void                AddContactEntity( idEntity *e ) = 0;
  145.     virtual void                 RemoveContactEntity( idEntity *e ) = 0;
  146.                                 // ground contacts
  147.     virtual bool                HasGroundContacts( void ) const = 0;
  148.     virtual bool                IsGroundEntity( int entityNum ) const = 0;
  149.     virtual bool                IsGroundClipModel( int entityNum, int id ) const = 0;
  150. // RAVEN BEGIN
  151. // abahr
  152.     virtual const idVec3        GetContactNormal() const { return vec3_zero; }
  153.     virtual const idVec3        GetGroundContactNormal() const { return vec3_zero; }
  154.     virtual idEntity*            GetSelf() const = 0;
  155. // RAVEN END
  156.                                 // set the master entity for objects bound to a master
  157.     virtual void                SetMaster( idEntity *master, const bool orientated = true ) = 0;
  158.                                 // set pushed state
  159.     virtual void                SetPushed( int deltaTime ) = 0;
  160.     virtual const idVec3 &        GetPushedLinearVelocity( const int id = 0 ) const = 0;
  161.     virtual const idVec3 &        GetPushedAngularVelocity( const int id = 0 ) const = 0;
  162.                                 // get blocking info, returns NULL if the object is not blocked
  163.     virtual const trace_t *        GetBlockingInfo( void ) const = 0;
  164.     virtual idEntity *            GetBlockingEntity( void ) const = 0;
  165.                                 // movement end times in msec for reached events at the end of predefined motion
  166.     virtual int                    GetLinearEndTime( void ) const = 0;
  167.     virtual int                    GetAngularEndTime( void ) const = 0;
  168.                                 // networking
  169.     virtual void                WriteToSnapshot( idBitMsgDelta &msg ) const = 0;
  170.     virtual void                ReadFromSnapshot( const idBitMsgDelta &msg ) = 0;
  171.  
  172. // RAVEN BEGIN
  173. // kfuller: we want to debug draw the bbox
  174.     virtual void                DebugDraw() {}
  175. // RAVEN END
  176.  
  177. };
  178.  
  179. #endif /* !__PHYSICS_H__ */
  180.