physicsBehavior.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. //-----------------------------------------------------------------------------
  2. // Torque Game Engine
  3. // Copyright (C) GarageGames.com, Inc.
  4. //-----------------------------------------------------------------------------
  5. #ifndef _PHYSICSBEHAVIOR_H_
  6. #define _PHYSICSBEHAVIOR_H_
  7. #include "T3D/components/component.h"
  8. #ifndef __RESOURCE_H__
  9. #include "core/resource.h"
  10. #endif
  11. #ifndef _TSSHAPE_H_
  12. #include "ts/tsShape.h"
  13. #endif
  14. #ifndef _SCENERENDERSTATE_H_
  15. #include "scene/sceneRenderState.h"
  16. #endif
  17. #ifndef _MBOX_H_
  18. #include "math/mBox.h"
  19. #endif
  20. #ifndef _ENTITY_H_
  21. #include "T3D/entity.h"
  22. #endif
  23. #ifndef _CONVEX_H_
  24. #include "collision/convex.h"
  25. #endif
  26. #ifndef _BOXCONVEX_H_
  27. #include "collision/boxConvex.h"
  28. #endif
  29. #ifndef _RIGID_H_
  30. #include "T3D/rigid.h"
  31. #endif
  32. #ifndef _T3D_PHYSICS_PHYSICSBODY_H_
  33. #include "T3D/physics/physicsBody.h"
  34. #endif
  35. #ifndef _RENDER_COMPONENT_INTERFACE_H_
  36. #include "T3D/components/render/renderComponentInterface.h"
  37. #endif
  38. class TSShapeInstance;
  39. class SceneRenderState;
  40. class PhysicsBody;
  41. class PhysicsBehaviorInstance;
  42. //////////////////////////////////////////////////////////////////////////
  43. ///
  44. ///
  45. //////////////////////////////////////////////////////////////////////////
  46. class PhysicsComponent : public Component
  47. {
  48. typedef Component Parent;
  49. protected:
  50. bool mStatic;
  51. bool mAtRest;
  52. S32 mAtRestCounter;
  53. VectorF mGravity;
  54. VectorF mVelocity;
  55. F32 mDrag;
  56. F32 mMass;
  57. F32 mGravityMod;
  58. S32 csmAtRestTimer;
  59. F32 sAtRestVelocity; // Min speed after collisio
  60. public:
  61. enum MaskBits {
  62. PositionMask = Parent::NextFreeMask << 0,
  63. FreezeMask = Parent::NextFreeMask << 1,
  64. ForceMoveMask = Parent::NextFreeMask << 2,
  65. VelocityMask = Parent::NextFreeMask << 3,
  66. NextFreeMask = Parent::NextFreeMask << 4
  67. };
  68. struct StateDelta
  69. {
  70. Move move; ///< Last move from server
  71. F32 dt; ///< Last interpolation time
  72. // Interpolation data
  73. Point3F pos;
  74. Point3F posVec;
  75. QuatF rot[2];
  76. // Warp data
  77. S32 warpTicks; ///< Number of ticks to warp
  78. S32 warpCount; ///< Current pos in warp
  79. Point3F warpOffset;
  80. QuatF warpRot[2];
  81. };
  82. StateDelta mDelta;
  83. S32 mPredictionCount; ///< Number of ticks to predict
  84. public:
  85. PhysicsComponent();
  86. virtual ~PhysicsComponent();
  87. DECLARE_CONOBJECT(PhysicsComponent);
  88. static void initPersistFields();
  89. virtual void interpolateTick(F32 dt);
  90. virtual void updatePos(const U32 /*mask*/, const F32 dt){}
  91. virtual void _updatePhysics();
  92. virtual PhysicsBody *getPhysicsRep();
  93. virtual U32 packUpdate(NetConnection *con, U32 mask, BitStream *stream);
  94. virtual void unpackUpdate(NetConnection *con, BitStream *stream);
  95. virtual void onComponentAdd();
  96. void updateContainer();
  97. virtual void updateVelocity(const F32 dt);
  98. virtual Point3F getVelocity() { return mVelocity; }
  99. virtual void getOriginVector(const Point3F &p, Point3F* r);
  100. virtual void getVelocity(const Point3F& r, Point3F* v);
  101. virtual void setVelocity(const VectorF& vel);
  102. virtual void setTransform(const MatrixF& mat);
  103. virtual void setPosition(const Point3F& pos);
  104. void setRenderPosition(const Point3F& pos, F32 dt);
  105. virtual void applyImpulse(const Point3F&, const VectorF& vec);
  106. virtual F32 getZeroImpulse(const Point3F& r, const Point3F& normal);
  107. virtual void accumulateForce(F32 dt, Point3F force);
  108. //Rigid Body Collision Conveinence Hooks
  109. virtual bool updateCollision(F32 dt, Rigid& ns, CollisionList &cList) { return false; }
  110. virtual bool resolveContacts(Rigid& ns, CollisionList& cList, F32 dt) { return false; }
  111. //virtual bool resolveCollision(Rigid& ns, CollisionList& cList) { return false; }
  112. virtual bool resolveCollision(const Point3F& p, const Point3F &normal) { return false; }
  113. };
  114. #endif // _COMPONENT_H_