00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #ifndef __NEPHYSICS_H
00028 #define __NEPHYSICS_H
00029
00030
00037 #include "base.h"
00038 #include "nemath.h"
00039 #include "room.h"
00040 #include "updateentity.h"
00041 #include "rigidbody.h"
00042 #include "contact.h"
00043
00044 #include <vector>
00045
00046
00047 namespace NeoEngine
00048 {
00049
00050
00051 #ifdef WIN32
00052 # ifdef _MSC_VER
00053 # pragma warning( disable : 4231 )
00054 # endif
00055 # ifndef __HAVE_VECTOR_NERIGIDBODY
00056 UDTVectorEXPIMP( RigidBody* );
00057 # define __HAVE_VECTOR_NERIGIDBODY
00058 # endif
00059 # ifndef __HAVE_VECTOR_NECONTACTSET
00060 UDTVectorEXPIMP( ContactSet* );
00061 # define __HAVE_VECTOR_NECONTACTSET
00062 # endif
00063 # ifndef __HAVE_VECTOR_NECONTACTNODE
00064 UDTVectorEXPIMP( class ContactNode* );
00065 # define __HAVE_VECTOR_NECONTACTNODE
00066 # endif
00067 # ifndef __HAVE_VECTOR_NEMATRIX
00068 UDTVectorEXPIMP( Matrix* );
00069 # define __HAVE_VECTOR_NEMATRIX
00070 # endif
00071 #endif
00072
00073
00078 class NEOENGINE_API ContactNode
00079 {
00080 public:
00081
00085 enum CONTACTMODE
00086 {
00088 COLLISION,
00089
00091 CONTACT,
00092
00094 SHOCKPROPAGATION,
00095 };
00096
00097
00099 RigidBody *m_pkBody;
00100
00102 std::vector< ContactNode* > m_vpkParents;
00103
00105 std::vector< ContactSet* > m_vpkContactSets;
00106
00108 std::vector< Matrix* > m_vpkCollisionMatrix;
00109
00111 std::vector< Matrix* > m_vpkInvCollisionMatrix;
00112
00114 std::vector< ContactNode* > m_vpkChildren;
00115
00117 bool m_bVisited;
00118
00120 bool m_bFree;
00121
00122
00126 ContactNode( RigidBody *pkBody );
00127
00130 virtual ~ContactNode();
00131
00138 bool Solve( CONTACTMODE eMode, unsigned int uiPass, unsigned int uiNumPasses );
00139
00143 void ResetVisited();
00144
00150 void AddContact( ContactNode *pkParent, ContactSet *pkSet );
00151
00155 void Clear();
00156 };
00157
00158
00163 class NEOENGINE_API PhysicsManager : public virtual UpdateEntity
00164 {
00165 public:
00166
00170 enum PHYSICSMANAGERDEFS
00171 {
00173 DEFAULTCOLLISIONPASSES = 5,
00174
00176 DEFAULTCONTACTPASSES = 5
00177 };
00178
00179
00180 protected:
00181
00183 unsigned int m_uiCollisionPasses;
00184
00186 unsigned int m_uiContactPasses;
00187
00189 Room *m_pkRoom;
00190
00192 Vector3d m_kGravity;
00193
00195 std::vector< RigidBody* > m_vpkBodies;
00196
00198 std::vector< ContactNode* > m_vpkBodyNodes;
00199
00200
00201 public:
00202
00203
00207 PhysicsManager( Room *pkRoom, unsigned int uiCollisionPasses = DEFAULTCOLLISIONPASSES, unsigned int uiContactPasses = DEFAULTCONTACTPASSES );
00208
00211 virtual ~PhysicsManager();
00212
00217 void SetGravity( const Vector3d &rkGravity );
00218
00223 virtual void Update( float fDeltaTime );
00224
00229 virtual void AddRigidBody( RigidBody *pkBody );
00230
00235 virtual void RemoveRigidBody( RigidBody *pkBody );
00236
00241 const std::vector< RigidBody* > &GetRigidBodies() { return m_vpkBodies; }
00242 };
00243
00244
00245 };
00246
00247
00248 #endif