DOOM-3-BFG

DOOM 3 BFG Edition
Log | Files | Refs

AF.h (5331B)


      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 __GAME_AF_H__
     30 #define __GAME_AF_H__
     31 
     32 
     33 /*
     34 ===============================================================================
     35 
     36   Articulated figure controller.
     37 
     38 ===============================================================================
     39 */
     40 
     41 typedef struct jointConversion_s {
     42 	int						bodyId;				// id of the body
     43 	jointHandle_t			jointHandle;		// handle of joint this body modifies
     44 	AFJointModType_t		jointMod;			// modify joint axis, origin or both
     45 	idVec3					jointBodyOrigin;	// origin of body relative to joint
     46 	idMat3					jointBodyAxis;		// axis of body relative to joint
     47 } jointConversion_t;
     48 
     49 typedef struct afTouch_s {
     50 	idEntity *				touchedEnt;
     51 	idClipModel *			touchedClipModel;
     52 	idAFBody *				touchedByBody;
     53 } afTouch_t;
     54 
     55 class idAF {
     56 public:
     57 							idAF();
     58 							~idAF();
     59 
     60 	void					Save( idSaveGame *savefile ) const;
     61 	void					Restore( idRestoreGame *savefile );
     62 
     63 	void					SetAnimator( idAnimator *a ) { animator = a; }
     64 	bool					Load( idEntity *ent, const char *fileName );
     65 	bool					IsLoaded() const { return isLoaded && self != NULL; }
     66 	const char *			GetName() const { return name.c_str(); }
     67 	void					SetupPose( idEntity *ent, int time );
     68 	void					ChangePose( idEntity *ent, int time );
     69 	int						EntitiesTouchingAF( afTouch_t touchList[ MAX_GENTITIES ] ) const;
     70 	void					Start();
     71 	void					StartFromCurrentPose( int inheritVelocityTime );
     72 	void					Stop();
     73 	void					Rest();
     74 	bool					IsActive() const { return isActive; }
     75 	void					SetConstraintPosition( const char *name, const idVec3 &pos );
     76 
     77 	idPhysics_AF *			GetPhysics() { return &physicsObj; }
     78 	const idPhysics_AF *	GetPhysics() const { return &physicsObj; }
     79 	idBounds				GetBounds() const;
     80 	bool					UpdateAnimation();
     81 
     82 	void					GetPhysicsToVisualTransform( idVec3 &origin, idMat3 &axis ) const;
     83 	void					GetImpactInfo( idEntity *ent, int id, const idVec3 &point, impactInfo_t *info );
     84 	void					ApplyImpulse( idEntity *ent, int id, const idVec3 &point, const idVec3 &impulse );
     85 	void					AddForce( idEntity *ent, int id, const idVec3 &point, const idVec3 &force );
     86 	int						BodyForClipModelId( int id ) const;
     87 
     88 	void					SaveState( idDict &args ) const;
     89 	void					LoadState( const idDict &args );
     90 
     91 	void					AddBindConstraints();
     92 	void					RemoveBindConstraints();
     93 
     94 protected:
     95 	idStr					name;				// name of the loaded .af file
     96 	idPhysics_AF			physicsObj;			// articulated figure physics
     97 	idEntity *				self;				// entity using the animated model
     98 	idAnimator *			animator;			// animator on entity
     99 	int						modifiedAnim;		// anim to modify
    100 	idVec3					baseOrigin;			// offset of base body relative to skeletal model origin
    101 	idMat3					baseAxis;			// axis of base body relative to skeletal model origin
    102 	idList<jointConversion_t, TAG_AF>	jointMods;			// list with transforms from skeletal model joints to articulated figure bodies
    103 	idList<int, TAG_AF>		jointBody;			// table to find the nearest articulated figure body for a joint of the skeletal model
    104 	int						poseTime;			// last time the articulated figure was transformed to reflect the current animation pose
    105 	int						restStartTime;		// time the articulated figure came to rest
    106 	bool					isLoaded;			// true when the articulated figure is properly loaded
    107 	bool					isActive;			// true if the articulated figure physics is active
    108 	bool					hasBindConstraints;	// true if the bind constraints have been added
    109 
    110 protected:
    111 	void					SetBase( idAFBody *body, const idJointMat *joints );
    112 	void					AddBody( idAFBody *body, const idJointMat *joints, const char *jointName, const AFJointModType_t mod );
    113 
    114 	bool					LoadBody( const idDeclAF_Body *fb, const idJointMat *joints );
    115 	bool					LoadConstraint( const idDeclAF_Constraint *fc );
    116 
    117 	bool					TestSolid() const;
    118 };
    119 
    120 #endif /* !__GAME_AF_H__ */