]> icculus.org git repositories - icculus/iodoom3.git/blob - neo/d3xp/BrittleFracture.h
Various Mac OS X tweaks to get this to build. Probably breaking things.
[icculus/iodoom3.git] / neo / d3xp / 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 #ifdef _D3XP
104         bool                                            isXraySurface;
105 #endif
106
107         // state
108         idPhysics_StaticMulti           physicsObj;
109         idList<shard_t *>                       shards;
110         idBounds                                        bounds;
111         bool                                            disableFracture;
112
113         // for rendering
114         mutable int                                     lastRenderEntityUpdate;
115         mutable bool                            changed;
116
117         bool                                            UpdateRenderEntity( renderEntity_s *renderEntity, const renderView_t *renderView ) const;
118         static bool                                     ModelCallback( renderEntity_s *renderEntity, const renderView_t *renderView );
119
120         void                                            AddShard( idClipModel *clipModel, idFixedWinding &w );
121         void                                            RemoveShard( int index );
122         void                                            DropShard( shard_t *shard, const idVec3 &point, const idVec3 &dir, const float impulse, const int time );
123         void                                            Shatter( const idVec3 &point, const idVec3 &impulse, const int time );
124         void                                            DropFloatingIslands( const idVec3 &point, const idVec3 &impulse, const int time );
125         void                                            Break( void );
126         void                                            Fracture_r( idFixedWinding &w );
127         void                                            CreateFractures( const idRenderModel *renderModel );
128         void                                            FindNeighbours( void );
129
130         void                                            Event_Activate( idEntity *activator );
131         void                                            Event_Touch( idEntity *other, trace_t *trace );
132 };
133
134 #endif /* !__GAME_BRITTLEFRACTURE_H__ */