VActorPhysicsController.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. //-----------------------------------------------------------------------------
  2. // Verve
  3. // Copyright (C) 2014 - Violent Tulip
  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. #ifndef _VT_VACTORPHYSICSCONTROLLER_H_
  24. #define _VT_VACTORPHYSICSCONTROLLER_H_
  25. #ifndef _VT_TYPES_H_
  26. #include "Types/VTypes.h"
  27. #endif
  28. #ifndef _VT_VACTORSTATETABLE_H_
  29. #include "VActorStateTable.h"
  30. #endif
  31. #ifndef _VT_VACTOR_H_
  32. #include "VActor.h"
  33. #endif
  34. #ifndef _VT_VINTERPCONTROLLER_H_
  35. #include "VInterpController.h"
  36. #endif
  37. #ifndef _BOXCONVEX_H_
  38. #include "collision/boxConvex.h"
  39. #endif
  40. //-----------------------------------------------------------------------------
  41. class VPath;
  42. //-----------------------------------------------------------------------------
  43. class VActorPhysicsController
  44. {
  45. protected:
  46. SimObjectPtr<VActor> mObject;
  47. SimObjectPtr<VPath> mMountedPath;
  48. VActorStateTable mPhysicsStateTable;
  49. VInterpController mInterpController;
  50. U32 mPhysicsState;
  51. U32 mControlState;
  52. U32 mMoveState;
  53. OrthoBoxConvex mConvex;
  54. VectorF mGravity;
  55. VectorF mVelocity;
  56. bool mOnGround;
  57. SimObjectPtr<SceneObject> mGroundObject;
  58. VectorF mGroundNormal;
  59. public:
  60. VActorPhysicsController( void );
  61. virtual ~VActorPhysicsController( void );
  62. // Initialisation Methods.
  63. bool initPhysicsController( VActor *pObject );
  64. bool initPhysicsTable( void );
  65. // Accessor Methods.
  66. bool isValidObject( void );
  67. VActor *getObject( void );
  68. VActorData *getObjectDataBlock( void );
  69. void clearObject( void );
  70. virtual const U32 getControlState( void );
  71. virtual void clearControlState( const U32 &pControlState );
  72. virtual void setControlState( const U32 &pControlState );
  73. virtual const bool isMoving( void );
  74. virtual const bool isMoving( const U32 &pMoveState );
  75. virtual const U32 getMoveState( void );
  76. virtual void clearMoveState( const U32 &pMoveState );
  77. virtual void setMoveState( const U32 &pMoveState );
  78. virtual const bool isPathing( void );
  79. virtual VPath *getPathObject( void );
  80. virtual const bool isInWater( void );
  81. virtual WaterObject *getWaterObject( void );
  82. virtual const bool isOnGround( void );
  83. virtual const bool isInAir( void );
  84. inline SceneObject *getGroundObject( void ) { return mGroundObject; };
  85. inline const VectorF &getGroundNormal( void ) { return mGroundNormal; };
  86. inline const U32 &getPhysicsState( void ) { return mPhysicsState; };
  87. inline void setPhysicsState( const U32 &pState ) { mPhysicsState = pState; };
  88. virtual MatrixF getTransform( void );
  89. virtual void setTransform( const MatrixF &pTransform );
  90. virtual Point3F getPosition( void );
  91. virtual void setPosition( const Point3F &pPosition );
  92. inline VectorF getGravity( void ) { return mGravity; };
  93. inline void setGravity( VectorF &pGravity ) { mGravity = pGravity; };
  94. virtual void applyGravity( const F32 &pElapsedTime );
  95. virtual VectorF getVelocity( void );
  96. virtual void setVelocity( const VectorF &pVelocity );
  97. // Physics Methods.
  98. void update( const F32 &pDelta, const Move *pMove );
  99. virtual void preTickUpdate( const F32 &pDelta );
  100. virtual void integrateTickUpdate( const F32 &pDelta, const Move *pMove );
  101. virtual void postTickUpdate( const F32 &pDelta );
  102. void interpolateTick( const F32 &pDelta );
  103. void updateWorkingCollisionSet( void );
  104. void updateMoveState( void );
  105. void clearGroundStatus( void );
  106. void updateGroundStatus( void );
  107. bool findGroundContact( SceneObject *&pContactObject, Point3F &pContactPoint, VectorF &pContactNormal );
  108. void processCollisions( void );
  109. bool findCollision( Collision *&pCollision );
  110. void solveCollision( Collision *pCollision );
  111. // Updates Methods.
  112. void onActorEvent( const VActor::eEventType &pEvent );
  113. U32 packUpdate( NetConnection *pConnection, U32 pMask, BitStream *pStream );
  114. void unpackUpdate( NetConnection *pConnection, BitStream *pStream );
  115. };
  116. #endif // _VT_VACTORANIMATIONCONTROLLER_H_