1 /* 2 =========================================================================== 3 4 Doom 3 GPL Source Code 5 Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company. 6 7 This file is part of the Doom 3 GPL Source Code ("Doom 3 Source Code"). 8 9 Doom 3 Source Code is free software: you can redistribute it and/or modify 10 it under the terms of the GNU General Public License as published by 11 the Free Software Foundation, either version 3 of the License, or 12 (at your option) any later version. 13 14 Doom 3 Source Code is distributed in the hope that it will be useful, 15 but WITHOUT ANY WARRANTY; without even the implied warranty of 16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 GNU General Public License for more details. 18 19 You should have received a copy of the GNU General Public License 20 along with Doom 3 Source Code. If not, see <http://www.gnu.org/licenses/>. 21 22 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. 23 24 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. 25 26 =========================================================================== 27 */ 28 29 #ifndef __GAME_BRITTLEFRACTURE_H__ 30 #define __GAME_BRITTLEFRACTURE_H__ 31 32 #include "physics/Physics_RigidBody.h" 33 #include "physics/Physics_StaticMulti.h" 34 #include "physics/Clip.h" 35 #include "Entity.h" 36 37 /* 38 =============================================================================== 39 40 B-rep Brittle Fracture - Static entity using the boundary representation 41 of the render model which can fracture. 42 43 =============================================================================== 44 */ 45 46 typedef struct shard_s { 47 idClipModel * clipModel; 48 idFixedWinding winding; 49 idList<idFixedWinding *> decals; 50 idList<bool> edgeHasNeighbour; 51 idList<struct shard_s *> neighbours; 52 idPhysics_RigidBody physicsObj; 53 int droppedTime; 54 bool atEdge; 55 int islandNum; 56 } shard_t; 57 58 59 class idBrittleFracture : public idEntity { 60 61 public: 62 CLASS_PROTOTYPE( idBrittleFracture ); 63 64 idBrittleFracture( void ); 65 virtual ~idBrittleFracture( void ); 66 67 void Save( idSaveGame *savefile ) const; 68 void Restore( idRestoreGame *savefile ); 69 70 void Spawn( void ); 71 72 virtual void Present( void ); 73 virtual void Think( void ); 74 virtual void ApplyImpulse( idEntity *ent, int id, const idVec3 &point, const idVec3 &impulse ); 75 virtual void AddForce( idEntity *ent, int id, const idVec3 &point, const idVec3 &force ); 76 virtual void AddDamageEffect( const trace_t &collision, const idVec3 &velocity, const char *damageDefName ); 77 virtual void Killed( idEntity *inflictor, idEntity *attacker, int damage, const idVec3 &dir, int location ); 78 79 void ProjectDecal( const idVec3 &point, const idVec3 &dir, const int time, const char *damageDefName ); 80 bool IsBroken( void ) const; 81 82 enum { 83 EVENT_PROJECT_DECAL = idEntity::EVENT_MAXEVENTS, 84 EVENT_SHATTER, 85 EVENT_MAXEVENTS 86 }; 87 88 virtual void ClientPredictionThink( void ); 89 virtual bool ClientReceiveEvent( int event, int time, const idBitMsg &msg ); 90 91 private: 92 // setttings 93 const idMaterial * material; 94 const idMaterial * decalMaterial; 95 float decalSize; 96 float maxShardArea; 97 float maxShatterRadius; 98 float minShatterRadius; 99 float linearVelocityScale; 100 float angularVelocityScale; 101 float shardMass; 102 float density; 103 float friction; 104 float bouncyness; 105 idStr fxFracture; 106 107 #ifdef _D3XP 108 bool isXraySurface; 109 #endif 110 111 // state 112 idPhysics_StaticMulti physicsObj; 113 idList<shard_t *> shards; 114 idBounds bounds; 115 bool disableFracture; 116 117 // for rendering 118 mutable int lastRenderEntityUpdate; 119 mutable bool changed; 120 121 bool UpdateRenderEntity( renderEntity_s *renderEntity, const renderView_t *renderView ) const; 122 static bool ModelCallback( renderEntity_s *renderEntity, const renderView_t *renderView ); 123 124 void AddShard( idClipModel *clipModel, idFixedWinding &w ); 125 void RemoveShard( int index ); 126 void DropShard( shard_t *shard, const idVec3 &point, const idVec3 &dir, const float impulse, const int time ); 127 void Shatter( const idVec3 &point, const idVec3 &impulse, const int time ); 128 void DropFloatingIslands( const idVec3 &point, const idVec3 &impulse, const int time ); 129 void Break( void ); 130 void Fracture_r( idFixedWinding &w ); 131 void CreateFractures( const idRenderModel *renderModel ); 132 void FindNeighbours( void ); 133 134 void Event_Activate( idEntity *activator ); 135 void Event_Touch( idEntity *other, trace_t *trace ); 136 }; 137 138 #endif /* !__GAME_BRITTLEFRACTURE_H__ */ 139