BrittleFracture.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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_BRITTLEFRACTURE_H__
  21. #define __GAME_BRITTLEFRACTURE_H__
  22. /*
  23. ===============================================================================
  24. B-rep Brittle Fracture - Static entity using the boundary representation
  25. of the render model which can fracture.
  26. ===============================================================================
  27. */
  28. typedef struct shard_s {
  29. idClipModel * clipModel;
  30. idFixedWinding winding;
  31. idList<idFixedWinding *> decals;
  32. idList<bool> edgeHasNeighbour;
  33. idList<struct shard_s *> neighbours;
  34. idPhysics_RigidBody physicsObj;
  35. int droppedTime;
  36. bool atEdge;
  37. int islandNum;
  38. } shard_t;
  39. class idBrittleFracture : public idEntity {
  40. public:
  41. CLASS_PROTOTYPE( idBrittleFracture );
  42. idBrittleFracture( void );
  43. virtual ~idBrittleFracture( void );
  44. void Save( idSaveGame *savefile ) const;
  45. void Restore( idRestoreGame *savefile );
  46. void Spawn( void );
  47. virtual void Present( void );
  48. virtual void Think( void );
  49. virtual void ApplyImpulse( idEntity *ent, int id, const idVec3 &point, const idVec3 &impulse );
  50. virtual void AddForce( idEntity *ent, int id, const idVec3 &point, const idVec3 &force );
  51. virtual void AddDamageEffect( const trace_t &collision, const idVec3 &velocity, const char *damageDefName );
  52. virtual void Killed( idEntity *inflictor, idEntity *attacker, int damage, const idVec3 &dir, int location );
  53. void ProjectDecal( const idVec3 &point, const idVec3 &dir, const int time, const char *damageDefName );
  54. bool IsBroken( void ) const;
  55. enum {
  56. EVENT_PROJECT_DECAL = idEntity::EVENT_MAXEVENTS,
  57. EVENT_SHATTER,
  58. EVENT_MAXEVENTS
  59. };
  60. virtual void ClientPredictionThink( void );
  61. virtual bool ClientReceiveEvent( int event, int time, const idBitMsg &msg );
  62. private:
  63. // setttings
  64. const idMaterial * material;
  65. const idMaterial * decalMaterial;
  66. float decalSize;
  67. float maxShardArea;
  68. float maxShatterRadius;
  69. float minShatterRadius;
  70. float linearVelocityScale;
  71. float angularVelocityScale;
  72. float shardMass;
  73. float density;
  74. float friction;
  75. float bouncyness;
  76. idStr fxFracture;
  77. #ifdef _D3XP
  78. bool isXraySurface;
  79. #endif
  80. // state
  81. idPhysics_StaticMulti physicsObj;
  82. idList<shard_t *> shards;
  83. idBounds bounds;
  84. bool disableFracture;
  85. // for rendering
  86. mutable int lastRenderEntityUpdate;
  87. mutable bool changed;
  88. bool UpdateRenderEntity( renderEntity_s *renderEntity, const renderView_t *renderView ) const;
  89. static bool ModelCallback( renderEntity_s *renderEntity, const renderView_t *renderView );
  90. void AddShard( idClipModel *clipModel, idFixedWinding &w );
  91. void RemoveShard( int index );
  92. void DropShard( shard_t *shard, const idVec3 &point, const idVec3 &dir, const float impulse, const int time );
  93. void Shatter( const idVec3 &point, const idVec3 &impulse, const int time );
  94. void DropFloatingIslands( const idVec3 &point, const idVec3 &impulse, const int time );
  95. void Break( void );
  96. void Fracture_r( idFixedWinding &w );
  97. void CreateFractures( const idRenderModel *renderModel );
  98. void FindNeighbours( void );
  99. void Event_Activate( idEntity *activator );
  100. void Event_Touch( idEntity *other, trace_t *trace );
  101. };
  102. #endif /* !__GAME_BRITTLEFRACTURE_H__ */