DOOM-3-BFG

DOOM 3 BFG Edition
Log | Files | Refs

Physics_Static.h (6804B)


      1 /*
      2 ===========================================================================
      3 
      4 Doom 3 BFG Edition GPL Source Code
      5 Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company. 
      6 
      7 This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").  
      8 
      9 Doom 3 BFG Edition Source Code is free software: you can redistribute it and/or modify
     10 it under the terms of the GNU General Public License as published by
     11 the Free Software Foundation, either version 3 of the License, or
     12 (at your option) any later version.
     13 
     14 Doom 3 BFG Edition Source Code is distributed in the hope that it will be useful,
     15 but WITHOUT ANY WARRANTY; without even the implied warranty of
     16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     17 GNU General Public License for more details.
     18 
     19 You should have received a copy of the GNU General Public License
     20 along with Doom 3 BFG Edition Source Code.  If not, see <http://www.gnu.org/licenses/>.
     21 
     22 In addition, the Doom 3 BFG Edition Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 BFG Edition Source Code.  If not, please request a copy in writing from id Software at the address below.
     23 
     24 If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
     25 
     26 ===========================================================================
     27 */
     28 
     29 #ifndef __PHYSICS_STATIC_H__
     30 #define __PHYSICS_STATIC_H__
     31 
     32 /*
     33 ===============================================================================
     34 
     35 	Physics for a non moving object using at most one collision model.
     36 
     37 ===============================================================================
     38 */
     39 
     40 class idBitMsg;
     41 
     42 typedef struct staticPState_s {
     43 	idVec3					origin;
     44 	idMat3					axis;
     45 	idVec3					localOrigin;
     46 	idMat3					localAxis;
     47 } staticPState_t;
     48 
     49 // Storing the state used for interpolation with quaternions
     50 // means I don't have to do a bunch of conversions between
     51 // idMat3s and idQuats every frame.
     52 struct staticInterpolatePState_t {
     53 	idVec3					origin;
     54 	idQuat					axis;
     55 	idVec3					localOrigin;
     56 	idQuat					localAxis;
     57 };
     58 
     59 /*
     60 ================
     61 ReadStaticInterpolatePStateFromSnapshot
     62 ================
     63 */
     64 staticInterpolatePState_t ReadStaticInterpolatePStateFromSnapshot( const idBitMsg & msg );
     65 staticPState_s	ConvertInterpolateStateToPState( const staticInterpolatePState_t & interpolateState  );
     66 staticInterpolatePState_t ConvertPStateToInterpolateState( const staticPState_t & state );
     67 
     68 class idPhysics_Static : public idPhysics {
     69 
     70 public:
     71 	CLASS_PROTOTYPE( idPhysics_Static );
     72 
     73 							idPhysics_Static();
     74 							~idPhysics_Static();
     75 
     76 	void					Save( idSaveGame *savefile ) const;
     77 	void					Restore( idRestoreGame *savefile );
     78 
     79 public:	// common physics interface
     80 	void					SetSelf( idEntity *e );
     81 
     82 	void					SetClipModel( idClipModel *model, float density, int id = 0, bool freeOld = true );
     83 	idClipModel *			GetClipModel( int id = 0 ) const;
     84 	int						GetNumClipModels() const;
     85 
     86 	void					SetMass( float mass, int id = -1 );
     87 	float					GetMass( int id = -1 ) const;
     88 
     89 	void					SetContents( int contents, int id = -1 );
     90 	int						GetContents( int id = -1 ) const;
     91 
     92 	void					SetClipMask( int mask, int id = -1 );
     93 	int						GetClipMask( int id = -1 ) const;
     94 
     95 	const idBounds &		GetBounds( int id = -1 ) const;
     96 	const idBounds &		GetAbsBounds( int id = -1 ) const;
     97 
     98 	bool					Evaluate( int timeStepMSec, int endTimeMSec );
     99 	bool					Interpolate( const float fraction );
    100 	void					ResetInterpolationState( const idVec3 & origin, const idMat3 & axis ) {}
    101 	void					UpdateTime( int endTimeMSec );
    102 	int						GetTime() const;
    103 
    104 	void					GetImpactInfo( const int id, const idVec3 &point, impactInfo_t *info ) const;
    105 	void					ApplyImpulse( const int id, const idVec3 &point, const idVec3 &impulse );
    106 	void					AddForce( const int id, const idVec3 &point, const idVec3 &force );
    107 	void					Activate();
    108 	void					PutToRest();
    109 	bool					IsAtRest() const;
    110 	int						GetRestStartTime() const;
    111 	bool					IsPushable() const;
    112 
    113 	void					SaveState();
    114 	void					RestoreState();
    115 
    116 	void					SetOrigin( const idVec3 &newOrigin, int id = -1 );
    117 	void					SetAxis( const idMat3 &newAxis, int id = -1 );
    118 
    119 	void					Translate( const idVec3 &translation, int id = -1 );
    120 	void					Rotate( const idRotation &rotation, int id = -1 );
    121 
    122 	const idVec3 &			GetOrigin( int id = 0 ) const;
    123 	const idMat3 &			GetAxis( int id = 0 ) const;
    124 
    125 	void					SetLinearVelocity( const idVec3 &newLinearVelocity, int id = 0 );
    126 	void					SetAngularVelocity( const idVec3 &newAngularVelocity, int id = 0 );
    127 
    128 	const idVec3 &			GetLinearVelocity( int id = 0 ) const;
    129 	const idVec3 &			GetAngularVelocity( int id = 0 ) const;
    130 
    131 	void					SetGravity( const idVec3 &newGravity );
    132 	const idVec3 &			GetGravity() const;
    133 	const idVec3 &			GetGravityNormal() const;
    134 
    135 	void					ClipTranslation( trace_t &results, const idVec3 &translation, const idClipModel *model ) const;
    136 	void					ClipRotation( trace_t &results, const idRotation &rotation, const idClipModel *model ) const;
    137 	int						ClipContents( const idClipModel *model ) const;
    138 
    139 	void					DisableClip();
    140 	void					EnableClip();
    141 
    142 	void					UnlinkClip();
    143 	void					LinkClip();
    144 
    145 	bool					EvaluateContacts();
    146 	int						GetNumContacts() const;
    147 	const contactInfo_t &	GetContact( int num ) const;
    148 	void					ClearContacts();
    149 	void					AddContactEntity( idEntity *e );
    150 	void					RemoveContactEntity( idEntity *e );
    151 
    152 	bool					HasGroundContacts() const;
    153 	bool					IsGroundEntity( int entityNum ) const;
    154 	bool					IsGroundClipModel( int entityNum, int id ) const;
    155 
    156 	void					SetPushed( int deltaTime );
    157 	const idVec3 &			GetPushedLinearVelocity( const int id = 0 ) const;
    158 	const idVec3 &			GetPushedAngularVelocity( const int id = 0 ) const;
    159 
    160 	void					SetMaster( idEntity *master, const bool orientated = true );
    161 
    162 	const trace_t *			GetBlockingInfo() const;
    163 	idEntity *				GetBlockingEntity() const;
    164 
    165 	int						GetLinearEndTime() const;
    166 	int						GetAngularEndTime() const;
    167 
    168 	void					WriteToSnapshot( idBitMsg &msg ) const;
    169 	void					ReadFromSnapshot( const idBitMsg &msg );
    170 
    171 protected:
    172 	idEntity *				self;					// entity using this physics object
    173 	staticPState_t			current;				// physics state
    174 	idClipModel *			clipModel;				// collision model
    175 	
    176 	// Used for client-side interpolation
    177 	staticInterpolatePState_t	previous;
    178 	staticInterpolatePState_t	next;
    179 
    180 	// master
    181 	bool					hasMaster;
    182 	bool					isOrientated;
    183 };
    184 
    185 staticPState_t InterpolateStaticPState( const staticInterpolatePState_t & previous,
    186 										const staticInterpolatePState_t & next,
    187 										float fraction );
    188 
    189 #endif /* !__PHYSICS_STATIC_H__ */