AF.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /*
  2. ===========================================================================
  3. Doom 3 GPL Source Code
  4. Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
  5. This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
  6. Doom 3 Source Code is free software: you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation, either version 3 of the License, or
  9. (at your option) any later version.
  10. Doom 3 Source Code is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with Doom 3 Source Code. If not, see <http://www.gnu.org/licenses/>.
  16. In addition, the Doom 3 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 Source Code. If not, please request a copy in writing from id Software at the address below.
  17. 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.
  18. ===========================================================================
  19. */
  20. #ifndef __GAME_AF_H__
  21. #define __GAME_AF_H__
  22. /*
  23. ===============================================================================
  24. Articulated figure controller.
  25. ===============================================================================
  26. */
  27. typedef struct jointConversion_s {
  28. int bodyId; // id of the body
  29. jointHandle_t jointHandle; // handle of joint this body modifies
  30. AFJointModType_t jointMod; // modify joint axis, origin or both
  31. idVec3 jointBodyOrigin; // origin of body relative to joint
  32. idMat3 jointBodyAxis; // axis of body relative to joint
  33. } jointConversion_t;
  34. typedef struct afTouch_s {
  35. idEntity * touchedEnt;
  36. idClipModel * touchedClipModel;
  37. idAFBody * touchedByBody;
  38. } afTouch_t;
  39. class idAF {
  40. public:
  41. idAF( void );
  42. ~idAF( void );
  43. void Save( idSaveGame *savefile ) const;
  44. void Restore( idRestoreGame *savefile );
  45. void SetAnimator( idAnimator *a ) { animator = a; }
  46. bool Load( idEntity *ent, const char *fileName );
  47. bool IsLoaded( void ) const { return isLoaded && self != NULL; }
  48. const char * GetName( void ) const { return name.c_str(); }
  49. void SetupPose( idEntity *ent, int time );
  50. void ChangePose( idEntity *ent, int time );
  51. int EntitiesTouchingAF( afTouch_t touchList[ MAX_GENTITIES ] ) const;
  52. void Start( void );
  53. void StartFromCurrentPose( int inheritVelocityTime );
  54. void Stop( void );
  55. void Rest( void );
  56. bool IsActive( void ) const { return isActive; }
  57. void SetConstraintPosition( const char *name, const idVec3 &pos );
  58. idPhysics_AF * GetPhysics( void ) { return &physicsObj; }
  59. const idPhysics_AF * GetPhysics( void ) const { return &physicsObj; }
  60. idBounds GetBounds( void ) const;
  61. bool UpdateAnimation( void );
  62. void GetPhysicsToVisualTransform( idVec3 &origin, idMat3 &axis ) const;
  63. void GetImpactInfo( idEntity *ent, int id, const idVec3 &point, impactInfo_t *info );
  64. void ApplyImpulse( idEntity *ent, int id, const idVec3 &point, const idVec3 &impulse );
  65. void AddForce( idEntity *ent, int id, const idVec3 &point, const idVec3 &force );
  66. int BodyForClipModelId( int id ) const;
  67. void SaveState( idDict &args ) const;
  68. void LoadState( const idDict &args );
  69. void AddBindConstraints( void );
  70. void RemoveBindConstraints( void );
  71. protected:
  72. idStr name; // name of the loaded .af file
  73. idPhysics_AF physicsObj; // articulated figure physics
  74. idEntity * self; // entity using the animated model
  75. idAnimator * animator; // animator on entity
  76. int modifiedAnim; // anim to modify
  77. idVec3 baseOrigin; // offset of base body relative to skeletal model origin
  78. idMat3 baseAxis; // axis of base body relative to skeletal model origin
  79. idList<jointConversion_t>jointMods; // list with transforms from skeletal model joints to articulated figure bodies
  80. idList<int> jointBody; // table to find the nearest articulated figure body for a joint of the skeletal model
  81. int poseTime; // last time the articulated figure was transformed to reflect the current animation pose
  82. int restStartTime; // time the articulated figure came to rest
  83. bool isLoaded; // true when the articulated figure is properly loaded
  84. bool isActive; // true if the articulated figure physics is active
  85. bool hasBindConstraints; // true if the bind constraints have been added
  86. protected:
  87. void SetBase( idAFBody *body, const idJointMat *joints );
  88. void AddBody( idAFBody *body, const idJointMat *joints, const char *jointName, const AFJointModType_t mod );
  89. bool LoadBody( const idDeclAF_Body *fb, const idJointMat *joints );
  90. bool LoadConstraint( const idDeclAF_Constraint *fc );
  91. bool TestSolid( void ) const;
  92. };
  93. #endif /* !__GAME_AF_H__ */