BrittleFracture.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. /*
  2. ===========================================================================
  3. Doom 3 BFG Edition GPL Source Code
  4. Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company.
  5. This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").
  6. Doom 3 BFG Edition 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 BFG Edition 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 BFG Edition Source Code. If not, see <http://www.gnu.org/licenses/>.
  16. 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.
  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 *, TAG_PHYSICS_BRITTLE> decals;
  32. idList<bool> edgeHasNeighbour;
  33. idList<struct shard_s *, TAG_PHYSICS_BRITTLE> 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();
  43. virtual ~idBrittleFracture();
  44. void Save( idSaveGame *savefile ) const;
  45. void Restore( idRestoreGame *savefile );
  46. void Spawn();
  47. virtual void Present();
  48. virtual void Think();
  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() const;
  55. enum {
  56. EVENT_PROJECT_DECAL = idEntity::EVENT_MAXEVENTS,
  57. EVENT_SHATTER,
  58. EVENT_MAXEVENTS
  59. };
  60. virtual void ClientThink( const int curTime, const float fraction, const bool predict );
  61. virtual void ClientPredictionThink();
  62. virtual bool ClientReceiveEvent( int event, int time, const idBitMsg &msg );
  63. private:
  64. // setttings
  65. const idMaterial * material;
  66. const idMaterial * decalMaterial;
  67. float decalSize;
  68. float maxShardArea;
  69. float maxShatterRadius;
  70. float minShatterRadius;
  71. float linearVelocityScale;
  72. float angularVelocityScale;
  73. float shardMass;
  74. float density;
  75. float friction;
  76. float bouncyness;
  77. idStr fxFracture;
  78. struct fractureEvent_s {
  79. int eventType;
  80. idVec3 point;
  81. idVec3 vector;
  82. };
  83. idList<fractureEvent_s> storedEvents;
  84. bool processStoredEvents;
  85. idRenderModel * defaultRenderModel;
  86. bool isXraySurface;
  87. // state
  88. idPhysics_StaticMulti physicsObj;
  89. idList<shard_t *, TAG_PHYSICS_BRITTLE> shards;
  90. idBounds bounds;
  91. bool disableFracture;
  92. // for rendering
  93. mutable int lastRenderEntityUpdate;
  94. mutable bool changed;
  95. bool UpdateRenderEntity( renderEntity_s *renderEntity, const renderView_t *renderView ) const;
  96. static bool ModelCallback( renderEntity_s *renderEntity, const renderView_t *renderView );
  97. void AddShard( idClipModel *clipModel, idFixedWinding &w );
  98. void RemoveShard( int index );
  99. void DropShard( shard_t *shard, const idVec3 &point, const idVec3 &dir, const float impulse, const int time );
  100. void Shatter( const idVec3 &point, const idVec3 &impulse, const int time );
  101. void DropFloatingIslands( const idVec3 &point, const idVec3 &impulse, const int time );
  102. void Break();
  103. void Fracture_r( idFixedWinding &w, idRandom2 & random );
  104. void CreateFractures( const idRenderModel *renderModel );
  105. void FindNeighbours();
  106. void Event_Activate( idEntity *activator );
  107. void Event_Touch( idEntity *other, trace_t *trace );
  108. };
  109. #endif /* !__GAME_BRITTLEFRACTURE_H__ */