VPath.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  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_VPATH_H_
  24. #define _VT_VPATH_H_
  25. #ifndef _SCENEOBJECT_H_
  26. #include "scene/sceneObject.h"
  27. #endif
  28. #ifndef _VT_PATHNODE_H_
  29. #include "VPathNode.h"
  30. #endif
  31. #ifndef _VT_PATHOBJECT_H_
  32. #include "VPathObject.h"
  33. #endif
  34. //-----------------------------------------------------------------------------
  35. typedef Vector<VPathNode*> VPathNodeVector;
  36. typedef VPathNodeVector::iterator VPathNodeIterator;
  37. typedef Vector<VPathObject*> VPathObjectVector;
  38. typedef VPathObjectVector::iterator VPathObjectIterator;
  39. //-----------------------------------------------------------------------------
  40. class VPath : public SceneObject
  41. {
  42. typedef SceneObject Parent;
  43. friend class VPathEditor;
  44. public:
  45. // Static Members.
  46. static SimObjectPtr<SimSet> gServerSet;
  47. static U32 gMaxNodeTransmit;
  48. static U32 gMaxNodeBits;
  49. static U32 gMaxNodeCount;
  50. static U32 gMaxObjectTransmit;
  51. static U32 gMaxObjectBits;
  52. static U32 gMaxObjectCount;
  53. static Point3F gBezierAxis;
  54. static Point3F gBezierUp;
  55. enum eMaskBits
  56. {
  57. InitialUpdateMask = Parent::NextFreeMask << 0,
  58. PathUpdateMask = Parent::NextFreeMask << 1,
  59. NodeUpdateMask = Parent::NextFreeMask << 2,
  60. ObjectUpdateMask = Parent::NextFreeMask << 3,
  61. NextFreeMask = Parent::NextFreeMask << 4,
  62. };
  63. enum ePathType
  64. {
  65. k_PathLinear,
  66. k_PathBezier,
  67. k_PathInvalid,
  68. k_PathTypeSize,
  69. };
  70. private:
  71. U32 mPathType;
  72. VPathNodeVector mNodeList;
  73. VPathObjectVector mObjectList;
  74. public:
  75. VPath( void );
  76. ~VPath( void );
  77. bool onAdd( void );
  78. void onDeleteNotify( SimObject *pObject );
  79. void onRemove( void );
  80. static void initPersistFields();
  81. static SimSet *getServerSet( void );
  82. // Editor Methods.
  83. bool collideBox( const Point3F &pStart, const Point3F &pEnd, RayInfo* pInfo );
  84. // Update Methods.
  85. F32 getUpdatePriority( CameraScopeQuery *pFocusObject, U32 pUpdateMask, S32 pUpdateSkips );
  86. void updateContainer( void );
  87. void updateNodeTransforms( void );
  88. void setTransform( const MatrixF &pMatrix );
  89. void setScale( const VectorF &pScale );
  90. void setPathType( const ePathType &pType );
  91. static bool setPathType( void *pObject, const char *pArray, const char *pData );
  92. // Mounting Methods.
  93. U32 getAvailableMountIndex( void );
  94. bool isMountIndex( const U32 &pIndex );
  95. void mountObject( SceneObject *pObject, S32 pIndex, const MatrixF &pTransform = MatrixF::Identity );
  96. void unmountObject( SceneObject *pObject );
  97. void getMountTransform( S32 pIndex, const MatrixF &pInTransform, MatrixF *pTransform );
  98. void getRenderMountTransform( F32 pDelta, S32 pIndex, const MatrixF &pInTransform, MatrixF *pTransform );
  99. VectorF getMountVelocity( const U32 &pIndex );
  100. // Persistence Methods.
  101. void readFields( void );
  102. void writeFields( Stream &pStream, U32 pTabStop );
  103. U32 packUpdate( NetConnection *pConnection, U32 pMask, BitStream *pStream );
  104. void unpackUpdate( NetConnection *pConnection, BitStream *pStream );
  105. DECLARE_CONOBJECT( VPath );
  106. public:
  107. // Node Methods.
  108. static VPathNode *createNode( void );
  109. static void deleteNode( VPathNode *pNode );
  110. void clear( void );
  111. VPathNode *getNode( const S32 &pNodeIndex );
  112. VPathNode *addNode( const Point3F &pPosition, const QuatF &pRotation, const F32 &pWeight, const S32 &pLocation = -1 );
  113. VPathNode *addNode( VPathNode *pNode, const S32 &pLocation = -1 );
  114. void deleteNode( const S32 &pNodeIndex );
  115. void removeNode( const S32 &pNodeIndex );
  116. S32 normalizeNodeIndex( S32 &pNodeIndex );
  117. S32 normalizeNodeIndex( const S32 &pNodeIndex );
  118. S32 normalizeNodeIndex( S32 &pNodeIndex, const S32 &pNodeCount );
  119. // Object Methods.
  120. bool isObjectAttached( SceneObject *pObject );
  121. VPathObject *getPathObject( SceneObject *pObject );
  122. void attachObject( SceneObject *pObject, const bool &pForward, const F32 &pSpeed, const bool &pRelative, const S32 &pStartNode, const S32 &pEndNode );
  123. void attachObject( SceneObject *pObject, const bool &pForward, const F32 &pSpeed, const bool &pRelative, const S32 &pStartNode, const S32 &pEndNode, const VPathObject::eOrientationType &pOrientationMode );
  124. void attachObject( SceneObject *pObject, const bool &pForward, const F32 &pSpeed, const bool &pRelative, const S32 &pStartNode, const S32 &pEndNode, const VPathObject::eOrientationType &pOrientationMode, void *pOrientationData );
  125. void attachObject( VPathObject *pPathObject );
  126. void onAttachObject( VPathObject *pPathObject );
  127. void detachObject( SceneObject *pObject );
  128. void detachObject( VPathObject *pPathObject );
  129. void onDetachObject( VPathObject *pPathObject );
  130. void processTick( const Move *pMove );
  131. void advanceObject( VPathObject *pPathObject, const F32 &pDelta );
  132. void updatePosition( VPathObject *pPathObject );
  133. void updateOrientation( VPathObject *pPathObject );
  134. void updateOrientation( VPathObject *pPathObject, const Point3F &pPathOrientation );
  135. // Path Methods.
  136. void calculatePath( void );
  137. Point3F getAdvancedPathPosition( VPathObject *pPathObject, const F32 &pTargetDistance, F32 &pInterpDelta );
  138. Point3F getPathPosition( VPathNode *pSourceNode, VPathNode *pDestinationNode, const F32 &pTimeInterp, const bool &pForward );
  139. Point3F getPathPosition( VPathNode *pSourceNode, VPathNode *pDestinationNode, const F32 &pTimeInterp, const bool &pForward, F32 &pPathInterp );
  140. VectorF getPathOrientation( VPathNode *pSourceNode, VPathNode *pDestinationNode, const F32 &pTimeInterp, const bool &pForward );
  141. //
  142. // Linear Path Methods.
  143. void calculateLinearPath( VPathNode *pNode, VPathNode *pNextNode );
  144. Point3F getAdvancedLinearPathPosition( VPathObject *pPathObject, const F32 &pTargetDistance, F32 &pInterpDelta );
  145. Point3F getLinearPathPosition( VPathNode *pSourceNode, VPathNode *pDestinationNode, const F32 &pInterp, const bool &pForward, F32 &pPathInterp );
  146. VectorF getLinearPathOrientation( VPathNode *pSourceNode, VPathNode *pDestinationNode, const F32 &pInterp, const bool &pForward );
  147. //
  148. // Bezier Path Methods.
  149. void calculateBezierPath( VPathNode *pNode, VPathNode *pNextNode );
  150. Point3F getAdvancedBezierPathPosition( VPathObject *pPathObject, const F32 &pTargetDistance, F32 &pInterpDelta );
  151. Point3F getBezierPathPosition( VPathNode *pSourceNode, VPathNode *pDestinationNode, const F32 &pInterp, const bool &pForward, F32 &pPathInterp );
  152. Point3F getBezierPathPosition( VPathNode *pSourceNode, VPathNode *pDestinationNode, const F32 &pInterp, const Point3F &pReferencePosition, const F32 &pTargetDistance, const bool &pForward, const bool &pRelativeToReference, F32 &pPathInterpDelta );
  153. VectorF getBezierPathOrientation( VPathNode *pSourceNode, VPathNode *pDestinationNode, const F32 &pInterp, const bool &pForward );
  154. public:
  155. // Node Property Methods.
  156. S32 getNodeCount( void );
  157. Point3F getNodeLocalPosition( const S32 &pNodeIndex );
  158. Point3F getNodeWorldPosition( const S32 &pNodeIndex );
  159. QuatF getNodeLocalRotation( const S32 &pNodeIndex );
  160. QuatF getNodeWorldRotation( const S32 &pNodeIndex );
  161. F32 getNodeWeight( const S32 &pNodeIndex );
  162. F32 getNodeLength( const S32 &pNodeIndex );
  163. void setNodePosition( const S32 &pNodeIndex, const Point3F &pPosition );
  164. void setNodeRotation( const S32 &pNodeIndex, const QuatF &pRotation );
  165. void setNodeWeight( const S32 &pNodeIndex, const F32 &pWeight );
  166. void setNodeOrientationMode( const S32 &pNodeIndex, const VPathNode::eOrientationType &pType );
  167. void setNodeOrientationMode( const S32 &pNodeIndex, const VPathNode::eOrientationType &pType, const Point3F pPoint );
  168. // Path Object Property Methods.
  169. void setPathObjectActive( SceneObject *pObject, const bool &pActive );
  170. void setPathObjectInterp( SceneObject *pObject, const F32 &pTimeInterp );
  171. void setPathObjectOffset( SceneObject *pObject, const Point3F &pOffset );
  172. void setPathObjectSpeed( SceneObject *pObject, const F32 &pSpeed );
  173. void setPathObjectOrientationMode( SceneObject *pObject, const VPathObject::eOrientationType &pType );
  174. void setPathObjectOrientationMode( SceneObject *pObject, const VPathObject::eOrientationType &pType, SceneObject *pLookAtObject );
  175. void setPathObjectOrientationMode( SceneObject *pObject, const VPathObject::eOrientationType &pType, const Point3F pPoint );
  176. void setPathObjectForward( SceneObject *pObject, const bool &pForward );
  177. void setPathObjectNode( SceneObject *pObject, const S32 &pNodeIndex );
  178. void setPathObjectEndNode( SceneObject *pObject, const S32 &pNodeIndex );
  179. void setPathObjectInterp( VPathObject *pPathObject, const F32 &pTimeInterp );
  180. };
  181. //-----------------------------------------------------------------------------
  182. // Define Types.
  183. typedef VPath::ePathType VPathType;
  184. // Declare Enum Types.
  185. DefineEnumType( VPathType );
  186. //-----------------------------------------------------------------------------
  187. #endif // _VT_VPATH_H_