physicsDebris.h
Engine/source/T3D/physics/physicsDebris.h
Classes:
Detailed Description
1 2//----------------------------------------------------------------------------- 3// Copyright (c) 2012 GarageGames, LLC 4// 5// Permission is hereby granted, free of charge, to any person obtaining a copy 6// of this software and associated documentation files (the "Software"), to 7// deal in the Software without restriction, including without limitation the 8// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 9// sell copies of the Software, and to permit persons to whom the Software is 10// furnished to do so, subject to the following conditions: 11// 12// The above copyright notice and this permission notice shall be included in 13// all copies or substantial portions of the Software. 14// 15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 21// IN THE SOFTWARE. 22//----------------------------------------------------------------------------- 23 24#ifndef _PHYSICS_DEBRIS_H_ 25#define _PHYSICS_DEBRIS_H_ 26 27#ifndef __RESOURCE_H__ 28#include "core/resource.h" 29#endif 30#ifndef _GAMEBASE_H_ 31#include "T3D/gameBase/gameBase.h" 32#endif 33#ifndef _T3D_PHYSICSCOMMON_H_ 34#include "T3D/physics/physicsCommon.h" 35#endif 36 37 38class TSShapeInstance; 39class TSShape; 40 41//************************************************************************** 42// Debris Data 43//************************************************************************** 44class PhysicsDebrisData : public GameBaseData 45{ 46 typedef GameBaseData Parent; 47 48public: 49 50 51 F32 lifetime; 52 F32 lifetimeVariance; 53 54 /// 55 F32 mass; 56 57 /// 58 F32 dynamicFriction; 59 60 /// 61 F32 staticFriction; 62 63 /// 64 F32 restitution; 65 66 /// 67 F32 linearDamping; 68 69 /// 70 F32 angularDamping; 71 72 /// 73 F32 linearSleepThreshold; 74 75 /// 76 F32 angularSleepThreshold; 77 78 // A scale applied to the normal linear and angular damping 79 // when the object enters a water volume. 80 F32 waterDampingScale; 81 82 // The density of this object used for water buoyancy effects. 83 F32 buoyancyDensity; 84 85 /// Is rendererd during shadow passes. 86 bool castShadows; 87 88 const char* shapeName; 89 Resource<TSShape> shape; 90 91 PhysicsDebrisData(); 92 93 bool onAdd(); 94 bool preload( bool server, String &errorStr ); 95 static void initPersistFields(); 96 void packData( BitStream *stream ); 97 void unpackData( BitStream *stream ); 98 99 DECLARE_CONOBJECT( PhysicsDebrisData ); 100 101}; 102 103 104 105class PhysicsBody; 106class PhysicsWorld; 107 108 109class PhysicsDebris : public GameBase 110{ 111 typedef GameBase Parent; 112 113public: 114 115 /// Helper method which creates debris based on the 116 /// datablock and initial state. 117 /// 118 /// It can return NULL if the system quality settings 119 /// are set to disable the debris. 120 /// 121 static PhysicsDebris* create( PhysicsDebrisData *datablock, 122 const MatrixF &transform, 123 const VectorF &linVel ); 124 125 PhysicsDebris(); 126 virtual ~PhysicsDebris(); 127 128 DECLARE_CONOBJECT(PhysicsDebris); 129 static void initPersistFields(); 130 131 bool onAdd(); 132 void onRemove(); 133 134 void applyImpulse( const Point3F &pos, const VectorF &vec ); 135 void applyRadialImpulse( const Point3F &origin, F32 radius, F32 magnitude ); 136 137protected: 138 139 /// The global object lifetime scalar. 140 static F32 smLifetimeScale; 141 142 void processTick( const Move *move ); 143 void advanceTime( F32 dt ); 144 void interpolateTick( F32 delta ); 145 bool onNewDataBlock( GameBaseData *dptr, bool reload ); 146 147 void prepRenderImage( SceneRenderState *state ); 148 void prepBatchRender( SceneRenderState *state ); 149 150 void _deleteFragments(); 151 void _createFragments(); 152 153 void _updateForces( PhysicsBody *body, const Box3F &bounds ); 154 155 void _findNodes( U32 objId, Vector<U32> &nodeIds ); 156 157 void _onPhysicsReset( PhysicsResetEvent reset ); 158 159protected: 160 161 F32 mLifetime; 162 163 Point3F mInitialLinVel; 164 165 PhysicsDebrisData *mDataBlock; 166 167 TSShapeInstance *mShapeInstance; 168 169 PhysicsWorld *mWorld; 170 171 struct Fragment 172 { 173 Vector<U32> nodeIds; 174 175 PhysicsBody *body; 176 177 // The delta state. 178 Point3F pos; 179 Point3F lastPos; 180 QuatF rot; 181 QuatF lastRot; 182 }; 183 184 typedef Vector<Fragment> FragmentVector; 185 186 FragmentVector mFragments; 187 188}; 189 190 191#endif // _PHYSICS_DEBRIS_H_ 192