Physics_Parametric.h 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  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 __PHYSICS_PARAMETRIC_H__
  21. #define __PHYSICS_PARAMETRIC_H__
  22. /*
  23. ===================================================================================
  24. Parametric physics
  25. Used for predefined or scripted motion. The motion of an object is completely
  26. parametrized. By adjusting the parameters an object is forced to follow a
  27. predefined path. The parametric physics is typically used for doors, bridges,
  28. rotating fans etc.
  29. ===================================================================================
  30. */
  31. typedef struct parametricPState_s {
  32. int time; // physics time
  33. int atRest; // set when simulation is suspended
  34. idVec3 origin; // world origin
  35. idAngles angles; // world angles
  36. idMat3 axis; // world axis
  37. idVec3 localOrigin; // local origin
  38. idAngles localAngles; // local angles
  39. idExtrapolate<idVec3> linearExtrapolation; // extrapolation based description of the position over time
  40. idExtrapolate<idAngles> angularExtrapolation; // extrapolation based description of the orientation over time
  41. idInterpolateAccelDecelLinear<idVec3> linearInterpolation; // interpolation based description of the position over time
  42. idInterpolateAccelDecelLinear<idAngles> angularInterpolation; // interpolation based description of the orientation over time
  43. idCurve_Spline<idVec3> * spline; // spline based description of the position over time
  44. idInterpolateAccelDecelLinear<float> splineInterpolate; // position along the spline over time
  45. bool useSplineAngles; // set the orientation using the spline
  46. } parametricPState_t;
  47. class idPhysics_Parametric : public idPhysics_Base {
  48. public:
  49. CLASS_PROTOTYPE( idPhysics_Parametric );
  50. idPhysics_Parametric( void );
  51. ~idPhysics_Parametric( void );
  52. void Save( idSaveGame *savefile ) const;
  53. void Restore( idRestoreGame *savefile );
  54. void SetPusher( int flags );
  55. bool IsPusher( void ) const;
  56. void SetLinearExtrapolation( extrapolation_t type, int time, int duration, const idVec3 &base, const idVec3 &speed, const idVec3 &baseSpeed );
  57. void SetAngularExtrapolation( extrapolation_t type, int time, int duration, const idAngles &base, const idAngles &speed, const idAngles &baseSpeed );
  58. extrapolation_t GetLinearExtrapolationType( void ) const;
  59. extrapolation_t GetAngularExtrapolationType( void ) const;
  60. void SetLinearInterpolation( int time, int accelTime, int decelTime, int duration, const idVec3 &startPos, const idVec3 &endPos );
  61. void SetAngularInterpolation( int time, int accelTime, int decelTime, int duration, const idAngles &startAng, const idAngles &endAng );
  62. void SetSpline( idCurve_Spline<idVec3> *spline, int accelTime, int decelTime, bool useSplineAngles );
  63. idCurve_Spline<idVec3> *GetSpline( void ) const;
  64. int GetSplineAcceleration( void ) const;
  65. int GetSplineDeceleration( void ) const;
  66. bool UsingSplineAngles( void ) const;
  67. void GetLocalOrigin( idVec3 &curOrigin ) const;
  68. void GetLocalAngles( idAngles &curAngles ) const;
  69. void GetAngles( idAngles &curAngles ) const;
  70. public: // common physics interface
  71. void SetClipModel( idClipModel *model, float density, int id = 0, bool freeOld = true );
  72. idClipModel * GetClipModel( int id = 0 ) const;
  73. int GetNumClipModels( void ) const;
  74. void SetMass( float mass, int id = -1 );
  75. float GetMass( int id = -1 ) const;
  76. void SetContents( int contents, int id = -1 );
  77. int GetContents( int id = -1 ) const;
  78. const idBounds & GetBounds( int id = -1 ) const;
  79. const idBounds & GetAbsBounds( int id = -1 ) const;
  80. bool Evaluate( int timeStepMSec, int endTimeMSec );
  81. void UpdateTime( int endTimeMSec );
  82. int GetTime( void ) const;
  83. void Activate( void );
  84. bool IsAtRest( void ) const;
  85. int GetRestStartTime( void ) const;
  86. bool IsPushable( void ) const;
  87. void SaveState( void );
  88. void RestoreState( void );
  89. void SetOrigin( const idVec3 &newOrigin, int id = -1 );
  90. void SetAxis( const idMat3 &newAxis, int id = -1 );
  91. void Translate( const idVec3 &translation, int id = -1 );
  92. void Rotate( const idRotation &rotation, int id = -1 );
  93. const idVec3 & GetOrigin( int id = 0 ) const;
  94. const idMat3 & GetAxis( int id = 0 ) const;
  95. void SetLinearVelocity( const idVec3 &newLinearVelocity, int id = 0 );
  96. void SetAngularVelocity( const idVec3 &newAngularVelocity, int id = 0 );
  97. const idVec3 & GetLinearVelocity( int id = 0 ) const;
  98. const idVec3 & GetAngularVelocity( int id = 0 ) const;
  99. void DisableClip( void );
  100. void EnableClip( void );
  101. void UnlinkClip( void );
  102. void LinkClip( void );
  103. void SetMaster( idEntity *master, const bool orientated = true );
  104. const trace_t * GetBlockingInfo( void ) const;
  105. idEntity * GetBlockingEntity( void ) const;
  106. int GetLinearEndTime( void ) const;
  107. int GetAngularEndTime( void ) const;
  108. void WriteToSnapshot( idBitMsgDelta &msg ) const;
  109. void ReadFromSnapshot( const idBitMsgDelta &msg );
  110. private:
  111. // parametric physics state
  112. parametricPState_t current;
  113. parametricPState_t saved;
  114. // pusher
  115. bool isPusher;
  116. idClipModel * clipModel;
  117. int pushFlags;
  118. // results of last evaluate
  119. trace_t pushResults;
  120. bool isBlocked;
  121. // master
  122. bool hasMaster;
  123. bool isOrientated;
  124. private:
  125. bool TestIfAtRest( void ) const;
  126. void Rest( void );
  127. };
  128. #endif /* !__PHYSICS_PARAMETRIC_H__ */