]> icculus.org git repositories - icculus/iodoom3.git/blob - neo/game/BrittleFracture.h
hello world
[icculus/iodoom3.git] / neo / game / BrittleFracture.h
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
33 /*
34 ===============================================================================
35
36 B-rep Brittle Fracture - Static entity using the boundary representation
37 of the render model which can fracture.
38
39 ===============================================================================
40 */
41
42 typedef struct shard_s {
43         idClipModel *                           clipModel;
44         idFixedWinding                          winding;
45         idList<idFixedWinding *>        decals;
46         idList<bool>                            edgeHasNeighbour;
47         idList<struct shard_s *>        neighbours;
48         idPhysics_RigidBody                     physicsObj;
49         int                                                     droppedTime;
50         bool                                            atEdge;
51         int                                                     islandNum;
52 } shard_t;
53
54
55 class idBrittleFracture : public idEntity {
56
57 public:
58         CLASS_PROTOTYPE( idBrittleFracture );
59
60                                                                 idBrittleFracture( void );
61         virtual                                         ~idBrittleFracture( void );
62
63         void                                            Save( idSaveGame *savefile ) const;
64         void                                            Restore( idRestoreGame *savefile );
65
66         void                                            Spawn( void );
67
68         virtual void                            Present( void );
69         virtual void                            Think( void );
70         virtual void                            ApplyImpulse( idEntity *ent, int id, const idVec3 &point, const idVec3 &impulse );
71         virtual void                            AddForce( idEntity *ent, int id, const idVec3 &point, const idVec3 &force );
72         virtual void                            AddDamageEffect( const trace_t &collision, const idVec3 &velocity, const char *damageDefName );
73         virtual void                            Killed( idEntity *inflictor, idEntity *attacker, int damage, const idVec3 &dir, int location );
74
75         void                                            ProjectDecal( const idVec3 &point, const idVec3 &dir, const int time, const char *damageDefName );
76         bool                                            IsBroken( void ) const;
77
78         enum {
79                 EVENT_PROJECT_DECAL = idEntity::EVENT_MAXEVENTS,
80                 EVENT_SHATTER,
81                 EVENT_MAXEVENTS
82         };
83
84         virtual void                            ClientPredictionThink( void );
85         virtual bool                            ClientReceiveEvent( int event, int time, const idBitMsg &msg );
86
87 private:
88         // setttings
89         const idMaterial *                      material;
90         const idMaterial *                      decalMaterial;
91         float                                           decalSize;
92         float                                           maxShardArea;
93         float                                           maxShatterRadius;
94         float                                           minShatterRadius;
95         float                                           linearVelocityScale;
96         float                                           angularVelocityScale;
97         float                                           shardMass;
98         float                                           density;
99         float                                           friction;
100         float                                           bouncyness;
101         idStr                                           fxFracture;
102
103         // state
104         idPhysics_StaticMulti           physicsObj;
105         idList<shard_t *>                       shards;
106         idBounds                                        bounds;
107         bool                                            disableFracture;
108
109         // for rendering
110         mutable int                                     lastRenderEntityUpdate;
111         mutable bool                            changed;
112
113         bool                                            UpdateRenderEntity( renderEntity_s *renderEntity, const renderView_t *renderView ) const;
114         static bool                                     ModelCallback( renderEntity_s *renderEntity, const renderView_t *renderView );
115
116         void                                            AddShard( idClipModel *clipModel, idFixedWinding &w );
117         void                                            RemoveShard( int index );
118         void                                            DropShard( shard_t *shard, const idVec3 &point, const idVec3 &dir, const float impulse, const int time );
119         void                                            Shatter( const idVec3 &point, const idVec3 &impulse, const int time );
120         void                                            DropFloatingIslands( const idVec3 &point, const idVec3 &impulse, const int time );
121         void                                            Break( void );
122         void                                            Fracture_r( idFixedWinding &w );
123         void                                            CreateFractures( const idRenderModel *renderModel );
124         void                                            FindNeighbours( void );
125
126         void                                            Event_Activate( idEntity *activator );
127         void                                            Event_Touch( idEntity *other, trace_t *trace );
128 };
129
130 #endif /* !__GAME_BRITTLEFRACTURE_H__ */