Push.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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 __PUSH_H__
  21. #define __PUSH_H__
  22. /*
  23. ===============================================================================
  24. Allows physics objects to be pushed geometrically.
  25. ===============================================================================
  26. */
  27. #define PUSHFL_ONLYMOVEABLE 1 // only push moveable entities
  28. #define PUSHFL_NOGROUNDENTITIES 2 // don't push entities the clip model rests upon
  29. #define PUSHFL_CLIP 4 // also clip against all non-moveable entities
  30. #define PUSHFL_CRUSH 8 // kill blocking entities
  31. #define PUSHFL_APPLYIMPULSE 16 // apply impulse to pushed entities
  32. //#define NEW_PUSH
  33. class idPush {
  34. public:
  35. // Try to push other entities by moving the given entity.
  36. // If results.fraction < 1.0 the move was blocked by results.c.entityNum
  37. // Returns total mass of all pushed entities.
  38. float ClipTranslationalPush( trace_t &results, idEntity *pusher, const int flags,
  39. const idVec3 &newOrigin, const idVec3 &move );
  40. float ClipRotationalPush( trace_t &results, idEntity *pusher, const int flags,
  41. const idMat3 &newAxis, const idRotation &rotation );
  42. float ClipPush( trace_t &results, idEntity *pusher, const int flags,
  43. const idVec3 &oldOrigin, const idMat3 &oldAxis,
  44. idVec3 &newOrigin, idMat3 &newAxis );
  45. // initialize saving the positions of entities being pushed
  46. void InitSavingPushedEntityPositions( void );
  47. // move all pushed entities back to their previous position
  48. void RestorePushedEntityPositions( void );
  49. // returns the number of pushed entities
  50. int GetNumPushedEntities( void ) const { return numPushed; }
  51. // get the ith pushed entity
  52. idEntity * GetPushedEntity( int i ) const { assert( i >= 0 && i < numPushed ); return pushed[i].ent; }
  53. private:
  54. struct pushed_s {
  55. idEntity * ent; // pushed entity
  56. idAngles deltaViewAngles; // actor delta view angles
  57. } pushed[MAX_GENTITIES]; // pushed entities
  58. int numPushed; // number of pushed entities
  59. struct pushedGroup_s {
  60. idEntity * ent;
  61. float fraction;
  62. bool groundContact;
  63. bool test;
  64. } pushedGroup[MAX_GENTITIES];
  65. int pushedGroupSize;
  66. private:
  67. void SaveEntityPosition( idEntity *ent );
  68. bool RotateEntityToAxial( idEntity *ent, idVec3 rotationPoint );
  69. #ifdef NEW_PUSH
  70. bool CanPushEntity( idEntity *ent, idEntity *pusher, idEntity *initialPusher, const int flags );
  71. void AddEntityToPushedGroup( idEntity *ent, float fraction, bool groundContact );
  72. bool IsFullyPushed( idEntity *ent );
  73. bool ClipTranslationAgainstPusher( trace_t &results, idEntity *ent, idEntity *pusher, const idVec3 &translation );
  74. int GetPushableEntitiesForTranslation( idEntity *pusher, idEntity *initialPusher, const int flags,
  75. const idVec3 &translation, idEntity *entityList[], int maxEntities );
  76. bool ClipRotationAgainstPusher( trace_t &results, idEntity *ent, idEntity *pusher, const idRotation &rotation );
  77. int GetPushableEntitiesForRotation( idEntity *pusher, idEntity *initialPusher, const int flags,
  78. const idRotation &rotation, idEntity *entityList[], int maxEntities );
  79. #else
  80. void ClipEntityRotation( trace_t &trace, const idEntity *ent, const idClipModel *clipModel,
  81. idClipModel *skip, const idRotation &rotation );
  82. void ClipEntityTranslation( trace_t &trace, const idEntity *ent, const idClipModel *clipModel,
  83. idClipModel *skip, const idVec3 &translation );
  84. int TryTranslatePushEntity( trace_t &results, idEntity *check, idClipModel *clipModel, const int flags,
  85. const idVec3 &newOrigin, const idVec3 &move );
  86. int TryRotatePushEntity( trace_t &results, idEntity *check, idClipModel *clipModel, const int flags,
  87. const idMat3 &newAxis, const idRotation &rotation );
  88. int DiscardEntities( idEntity *entityList[], int numEntities, int flags, idEntity *pusher );
  89. #endif
  90. };
  91. #endif /* !__PUSH_H__ */