VPathNode.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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_VPATHNODE_H_
  24. #define _VT_VPATHNODE_H_
  25. #ifndef _GAMEBASE_H_
  26. #include "T3D/gameBase/gameBase.h"
  27. #endif
  28. #ifndef _VNETSTATE_H_
  29. #include "VNetState.h"
  30. #endif
  31. //-----------------------------------------------------------------------------
  32. class VPath;
  33. class VPathNode
  34. {
  35. public:
  36. enum eState
  37. {
  38. k_StateUpdatePosition = BIT( 0 ),
  39. k_StateUpdateRotation = BIT( 1 ),
  40. k_StateUpdateWeight = BIT( 2 ),
  41. k_StateUpdateOrientation = BIT( 3 ),
  42. k_StateCreate = BIT( 4 ),
  43. k_StateDelete = BIT( 5 ),
  44. k_StateUpdate = ( k_StateUpdatePosition | k_StateUpdateRotation | k_StateUpdateWeight | k_StateUpdateOrientation ),
  45. k_StateInit = ( k_StateCreate | k_StateUpdate ),
  46. };
  47. enum eOrientationType
  48. {
  49. k_OrientationFree,
  50. k_OrientationToPoint,
  51. k_OrientationTypeSize,
  52. };
  53. struct sOrientation
  54. {
  55. eOrientationType Type;
  56. // k_OrientationToPoint
  57. Point3F Point;
  58. };
  59. protected:
  60. VPath *mPath;
  61. VNetState mNetState;
  62. sOrientation mOrientationMode;
  63. Point3F mLocalPosition;
  64. QuatF mLocalRotation;
  65. Point3F mWorldPosition;
  66. QuatF mWorldRotation;
  67. F32 mWeight;
  68. F32 mLength;
  69. public:
  70. VPathNode( void );
  71. virtual ~VPathNode( void );
  72. // Serialisation Methods.
  73. virtual U32 packNode( NetConnection *pConnection, BitStream *pStream );
  74. virtual void unpackNode( NetConnection *pConnection, BitStream *pStream );
  75. virtual String toString( void );
  76. virtual bool fromString( const String &pString );
  77. //-------------------------------------------------------------------------
  78. //
  79. // Gets
  80. //
  81. //-------------------------------------------------------------------------
  82. inline VPath *getPath( void ) const { return mPath; };
  83. inline const Point3F &getLocalPosition( void ) const { return mLocalPosition; };
  84. inline const QuatF &getLocalRotation( void ) const { return mLocalRotation; };
  85. virtual Point3F getWorldPosition( void ) const;
  86. virtual QuatF getWorldRotation( void ) const;
  87. virtual MatrixF getWorldTransform( void ) const;
  88. inline const F32 &getWeight( void ) const { return mWeight; };
  89. inline const F32 &getLength( void ) const { return mLength; };
  90. inline const sOrientation &getOrientationMode( void ) const { return mOrientationMode; };
  91. //-------------------------------------------------------------------------
  92. //
  93. // Sets
  94. //
  95. //-------------------------------------------------------------------------
  96. inline void setPath( VPath *pPath ) { mPath = pPath; };
  97. void setLocalPosition( const Point3F &pPosition );
  98. void setLocalRotation( const QuatF &pRotation );
  99. inline void setWorldPosition( const Point3F &pPosition ) { mWorldPosition = pPosition; };
  100. inline void setWorldRotation( const QuatF &pRotation ) { mWorldRotation = pRotation; };
  101. void setWeight( const F32 &pWeight );
  102. inline void setLength( const F32 &pLength ) { mLength = pLength; };
  103. void setOrientationMode( const eOrientationType &pType );
  104. void setOrientationMode( const eOrientationType &pType, const Point3F &pPoint );
  105. void updateWorldData( void );
  106. // Net State Methods.
  107. inline VNetStateInfo *getState( NetConnection *pConnection ) { return mNetState.getState( pConnection ); };
  108. inline void setMaskBits( const U32 &pMask ) { mNetState.setMaskBits( pMask ); };
  109. inline void clearMaskBits( const U32 &pMask ) { mNetState.clearMaskBits( pMask ); };
  110. inline bool isConnection( NetConnection *pConnection ) { return mNetState.isConnection( pConnection ); };
  111. inline void addConnection( NetConnection *pConnection ) { mNetState.addConnection( pConnection ); };
  112. inline void clearConnection( NetConnection *pConnection ) { mNetState.clearConnection( pConnection ); };
  113. // Enum Methods.
  114. static eOrientationType getOrientationTypeEnum( const char *pLabel );
  115. static StringTableEntry getOrientationTypeLabel( const eOrientationType &pType );
  116. };
  117. //-----------------------------------------------------------------------------
  118. // Define Types.
  119. typedef VPathNode::eOrientationType VPathNodeOrientationType;
  120. // Declare Enum Types.
  121. DefineEnumType( VPathNodeOrientationType );
  122. //-----------------------------------------------------------------------------
  123. #endif // _VT_VPATHNODE_H_