VPath.h

Engine/source/Verve/VPath/VPath.h

More...

Classes:

class

Public Typedefs

VPathNodeIterator 
VPathNodeVector 
VPathObjectIterator 
VPathObjectVector 
VPathType 

Public Functions

Detailed Description

Public Typedefs

typedef VPathNodeVector::iterator VPathNodeIterator 
typedef Vector< VPathNode * > VPathNodeVector 
typedef VPathObjectVector::iterator VPathObjectIterator 
typedef Vector< VPathObject * > VPathObjectVector 
typedef VPath::ePathType VPathType 

Public Functions

DefineEnumType(VPathType )

  1
  2//-----------------------------------------------------------------------------
  3// Verve
  4// Copyright (C) 2014 - Violent Tulip
  5//
  6// Permission is hereby granted, free of charge, to any person obtaining a copy
  7// of this software and associated documentation files (the "Software"), to
  8// deal in the Software without restriction, including without limitation the
  9// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
 10// sell copies of the Software, and to permit persons to whom the Software is
 11// furnished to do so, subject to the following conditions:
 12//
 13// The above copyright notice and this permission notice shall be included in
 14// all copies or substantial portions of the Software.
 15//
 16// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 17// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 18// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 19// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 20// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 21// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
 22// IN THE SOFTWARE.
 23//-----------------------------------------------------------------------------
 24#ifndef _VT_VPATH_H_
 25#define _VT_VPATH_H_
 26
 27#ifndef _SCENEOBJECT_H_
 28#include "scene/sceneObject.h"
 29#endif
 30
 31#ifndef _VT_PATHNODE_H_
 32#include "VPathNode.h"
 33#endif
 34
 35#ifndef _VT_PATHOBJECT_H_
 36#include "VPathObject.h"
 37#endif
 38
 39//-----------------------------------------------------------------------------
 40
 41typedef Vector<VPathNode*>             VPathNodeVector;
 42typedef VPathNodeVector::iterator      VPathNodeIterator;
 43
 44typedef Vector<VPathObject*>           VPathObjectVector;
 45typedef VPathObjectVector::iterator    VPathObjectIterator;
 46
 47//-----------------------------------------------------------------------------
 48
 49class VPath : public SceneObject
 50{
 51    typedef SceneObject Parent;
 52
 53    friend class VPathEditor;
 54
 55public:
 56
 57    // Static Members.
 58
 59    static SimObjectPtr<SimSet>    gServerSet;
 60
 61    static U32                     gMaxNodeTransmit;
 62    static U32                     gMaxNodeBits;
 63    static U32                     gMaxNodeCount;
 64
 65    static U32                     gMaxObjectTransmit;
 66    static U32                     gMaxObjectBits;
 67    static U32                     gMaxObjectCount;
 68
 69    static Point3F                 gBezierAxis;
 70    static Point3F                 gBezierUp;
 71
 72    enum eMaskBits
 73    {
 74        InitialUpdateMask = Parent::NextFreeMask << 0,
 75        PathUpdateMask    = Parent::NextFreeMask << 1,
 76        NodeUpdateMask    = Parent::NextFreeMask << 2,
 77        ObjectUpdateMask  = Parent::NextFreeMask << 3,
 78        NextFreeMask      = Parent::NextFreeMask << 4,
 79    };
 80
 81    enum ePathType
 82    {
 83       k_PathLinear,
 84       k_PathBezier,
 85
 86       k_PathInvalid,
 87
 88       k_PathTypeSize,
 89    };
 90
 91private:
 92
 93    U32                  mPathType;
 94
 95    VPathNodeVector      mNodeList;
 96
 97    VPathObjectVector    mObjectList;
 98
 99public:
100
101    VPath( void );
102    ~VPath( void );
103
104    bool                onAdd( void );
105    void                onDeleteNotify( SimObject *pObject );
106    void                onRemove( void );
107
108    static void         initPersistFields( void );
109
110    static SimSet      *getServerSet( void );
111
112    // Editor Methods.
113
114    bool                collideBox( const Point3F &pStart, const Point3F &pEnd, RayInfo* pInfo );
115
116    // Update Methods.
117
118    F32                 getUpdatePriority( CameraScopeQuery *pFocusObject, U32 pUpdateMask, S32 pUpdateSkips );
119
120    void                updateContainer( void );
121    void                updateNodeTransforms( void );
122
123    void                setTransform( const MatrixF &pMatrix );
124    void                setScale( const VectorF &pScale );
125
126    void                setPathType( const ePathType &pType );
127    static bool         setPathType( void *pObject, const char *pArray, const char *pData );
128
129    // Mounting Methods.
130
131    U32                 getAvailableMountIndex( void );
132    bool                isMountIndex( const U32 &pIndex );
133
134    void                mountObject( SceneObject *pObject, S32 pIndex, const MatrixF &pTransform = MatrixF::Identity );
135    void                unmountObject( SceneObject *pObject );
136
137    void                getMountTransform( S32 pIndex, const MatrixF &pInTransform, MatrixF *pTransform );
138    void                getRenderMountTransform( F32 pDelta, S32 pIndex, const MatrixF &pInTransform, MatrixF *pTransform );
139
140    VectorF             getMountVelocity( const U32 &pIndex );
141
142    // Persistence Methods.
143
144    void                readFields( void );
145    void                writeFields( Stream &pStream, U32 pTabStop );
146
147    U32                 packUpdate( NetConnection *pConnection, U32 pMask, BitStream *pStream );
148    void                unpackUpdate( NetConnection *pConnection, BitStream *pStream );
149
150    DECLARE_CONOBJECT( VPath );
151
152public:
153
154    // Node Methods.
155
156    static VPathNode   *createNode( void );
157    static void         deleteNode( VPathNode *pNode );
158
159    void                clear( void );
160
161    VPathNode          *getNode( const S32 &pNodeIndex );
162
163    VPathNode          *addNode( const Point3F &pPosition, const QuatF &pRotation, const F32 &pWeight, const S32 &pLocation = -1 );
164    VPathNode          *addNode( VPathNode *pNode, const S32 &pLocation = -1 );
165
166    void                deleteNode( const S32 &pNodeIndex );
167    void                removeNode( const S32 &pNodeIndex );
168
169    S32                 normalizeNodeIndex( S32 &pNodeIndex );
170    S32                 normalizeNodeIndex( const S32 &pNodeIndex );
171    S32                 normalizeNodeIndex( S32 &pNodeIndex, const S32 &pNodeCount );
172
173    // Object Methods.
174
175    bool                isObjectAttached( SceneObject *pObject );
176    VPathObject        *getPathObject( SceneObject *pObject );
177
178    void                attachObject( SceneObject *pObject, const bool &pForward, const F32 &pSpeed, const bool &pRelative, const S32 &pStartNode, const S32 &pEndNode );
179    void                attachObject( SceneObject *pObject, const bool &pForward, const F32 &pSpeed, const bool &pRelative, const S32 &pStartNode, const S32 &pEndNode, const VPathObject::eOrientationType &pOrientationMode );
180    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 );
181    void                attachObject( VPathObject *pPathObject );
182    void                onAttachObject( VPathObject *pPathObject );
183
184    void                detachObject( SceneObject *pObject );
185    void                detachObject( VPathObject *pPathObject );
186    void                onDetachObject( VPathObject *pPathObject );
187
188    void                processTick( const Move *pMove );
189    void                advanceObject( VPathObject *pPathObject, const F32 &pDelta );
190
191    void                updatePosition( VPathObject *pPathObject );
192    void                updateOrientation( VPathObject *pPathObject );
193    void                updateOrientation( VPathObject *pPathObject, const Point3F &pPathOrientation );
194
195    // Path Methods.
196
197    void                calculatePath( void );
198
199    Point3F             getAdvancedPathPosition( VPathObject *pPathObject, const F32 &pTargetDistance, F32 &pInterpDelta );
200    
201    Point3F             getPathPosition( VPathNode *pSourceNode, VPathNode *pDestinationNode, const F32 &pTimeInterp, const bool &pForward );
202    Point3F             getPathPosition( VPathNode *pSourceNode, VPathNode *pDestinationNode, const F32 &pTimeInterp, const bool &pForward, F32 &pPathInterp );
203    VectorF             getPathOrientation( VPathNode *pSourceNode, VPathNode *pDestinationNode, const F32 &pTimeInterp, const bool &pForward );
204
205    //
206    // Linear Path Methods.
207
208    void                calculateLinearPath( VPathNode *pNode, VPathNode *pNextNode );
209
210    Point3F             getAdvancedLinearPathPosition( VPathObject *pPathObject, const F32 &pTargetDistance, F32 &pInterpDelta );
211
212    Point3F             getLinearPathPosition( VPathNode *pSourceNode, VPathNode *pDestinationNode, const F32 &pInterp, const bool &pForward, F32 &pPathInterp );
213    VectorF             getLinearPathOrientation( VPathNode *pSourceNode, VPathNode *pDestinationNode, const F32 &pInterp, const bool &pForward );
214
215    //
216    // Bezier Path Methods.
217
218    void                calculateBezierPath( VPathNode *pNode, VPathNode *pNextNode );
219
220    Point3F             getAdvancedBezierPathPosition( VPathObject *pPathObject, const F32 &pTargetDistance, F32 &pInterpDelta );
221
222    Point3F             getBezierPathPosition( VPathNode *pSourceNode, VPathNode *pDestinationNode, const F32 &pInterp, const bool &pForward, F32 &pPathInterp );
223    Point3F             getBezierPathPosition( VPathNode *pSourceNode, VPathNode *pDestinationNode, const F32 &pInterp, const Point3F &pReferencePosition, const F32 &pTargetDistance, const bool &pForward, const bool &pRelativeToReference, F32 &pPathInterpDelta );
224    VectorF             getBezierPathOrientation( VPathNode *pSourceNode, VPathNode *pDestinationNode, const F32 &pInterp, const bool &pForward );
225
226public:
227
228    // Node Property Methods.
229
230    S32                 getNodeCount( void );
231
232    Point3F             getNodeLocalPosition( const S32 &pNodeIndex );
233    Point3F             getNodeWorldPosition( const S32 &pNodeIndex );
234    QuatF               getNodeLocalRotation( const S32 &pNodeIndex );
235    QuatF               getNodeWorldRotation( const S32 &pNodeIndex );
236    F32                 getNodeWeight( const S32 &pNodeIndex );
237    F32                 getNodeLength( const S32 &pNodeIndex );
238
239    void                setNodePosition( const S32 &pNodeIndex, const Point3F &pPosition );
240    void                setNodeRotation( const S32 &pNodeIndex, const QuatF &pRotation );
241    void                setNodeWeight( const S32 &pNodeIndex, const F32 &pWeight );
242
243    void                setNodeOrientationMode( const S32 &pNodeIndex, const VPathNode::eOrientationType &pType );
244    void                setNodeOrientationMode( const S32 &pNodeIndex, const VPathNode::eOrientationType &pType, const Point3F pPoint );
245
246    // Path Object Property Methods.
247
248    void                setPathObjectActive( SceneObject *pObject, const bool &pActive );
249    void                setPathObjectInterp( SceneObject *pObject, const F32 &pTimeInterp );
250    void                setPathObjectOffset( SceneObject *pObject, const Point3F &pOffset );
251    void                setPathObjectSpeed( SceneObject *pObject, const F32 &pSpeed );
252    void                setPathObjectOrientationMode( SceneObject *pObject, const VPathObject::eOrientationType &pType );
253    void                setPathObjectOrientationMode( SceneObject *pObject, const VPathObject::eOrientationType &pType, SceneObject *pLookAtObject );
254    void                setPathObjectOrientationMode( SceneObject *pObject, const VPathObject::eOrientationType &pType, const Point3F pPoint );
255    void                setPathObjectForward( SceneObject *pObject, const bool &pForward );
256    void                setPathObjectNode( SceneObject *pObject, const S32 &pNodeIndex );
257    void                setPathObjectEndNode( SceneObject *pObject, const S32 &pNodeIndex );
258
259    void                setPathObjectInterp( VPathObject *pPathObject, const F32 &pTimeInterp );
260};
261
262//-----------------------------------------------------------------------------
263
264// Define Types.
265typedef VPath::ePathType VPathType;
266
267// Declare Enum Types.
268DefineEnumType( VPathType );
269
270//-----------------------------------------------------------------------------
271
272#endif // _VT_VPATH_H_
273