VPathObject.h
Engine/source/Verve/VPath/VPathObject.h
Classes:
Public Typedefs
VPathObjectOrientationType
Public Functions
Detailed Description
Public Typedefs
typedef VPathObject::eOrientationType VPathObjectOrientationType
Public Functions
DefineEnumType(VPathObjectOrientationType )
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_VPATHOBJECT_H_ 25#define _VT_VPATHOBJECT_H_ 26 27#ifndef _GAMEBASE_H_ 28#include "T3D/gameBase/gameBase.h" 29#endif 30 31#ifndef _VNETSTATE_H_ 32#include "VNetState.h" 33#endif 34 35#ifndef _MOVEMANAGER_H_ 36#include "T3D/gameBase/moveManager.h" 37#endif 38 39//----------------------------------------------------------------------------- 40 41class VPath; 42class NetConnection; 43 44struct VPathObject 45{ 46public: 47 48 enum eState 49 { 50 k_StateUpdateObject = BIT( 0 ), 51 k_StateUpdateMount = BIT( 1 ), 52 k_StateUpdatePosition = BIT( 2 ), 53 k_StateUpdateState = BIT( 3 ), 54 55 k_StateAttach = BIT( 4 ), 56 k_StateDetach = BIT( 5 ), 57 58 k_StateUpdate = ( k_StateUpdateObject | k_StateUpdateMount | k_StateUpdatePosition | k_StateUpdateState ), 59 60 k_StateInit = ( k_StateAttach | k_StateUpdate ), 61 }; 62 63 enum eOrientationType 64 { 65 k_OrientationFree, 66 k_OrientationInterpolate, 67 68 k_OrientationToPath, 69 k_OrientationToObject, 70 k_OrientationToPoint, 71 72 k_OrientationTypeSize, 73 }; 74 75 struct sOrientation 76 { 77 eOrientationType Type; 78 79 // k_OrientationToObject 80 SceneObject *Object; 81 // k_OrientationToPoint 82 Point3F Point; 83 }; 84 85 struct sDelta 86 { 87 Point3F Position[2]; 88 VectorF Orientation[2]; 89 }; 90 91protected: 92 93 bool mActive; 94 95 U32 mLastTime; 96 F32 mLastDelta; 97 98 SceneObject *mObject; 99 100 VNetState mNetState; 101 sDelta mDelta; 102 103 F32 mTimeInterp; 104 F32 mPathInterp; 105 Point3F mPosition; 106 Point3F mOffset; 107 sOrientation mOrientationMode; 108 VectorF mOrientation; 109 bool mForward; 110 F32 mSpeed; 111 112 S32 mSourceNode; 113 S32 mDestinationNode; 114 115 S32 mStartNode; 116 S32 mEndNode; 117 118public: 119 120 VPathObject( void ); 121 ~VPathObject( void ); 122 123 // Network Methods. 124 125 U32 packUpdate( NetConnection *pConnection, BitStream *pStream ); 126 void unpackUpdate( NetConnection *pConnection, BitStream *pStream ); 127 128 //------------------------------------------------------------------------- 129 // 130 // Gets 131 // 132 //------------------------------------------------------------------------- 133 134 inline const bool &isActive( void ) { return mActive; }; 135 136 inline SceneObject *getObject( void ) { return mObject; }; 137 138 inline const F32 &getTimeInterp( void ) { return mTimeInterp; }; 139 inline const F32 &getPathInterp( void ) { return mPathInterp; }; 140 inline const Point3F &getPosition( void ) { return mPosition; }; 141 inline const Point3F &getOffset( void ) { return mOffset; }; 142 inline const VectorF &getOrientation( void ) { return mOrientation; }; 143 inline const sOrientation &getOrientationMode( void ) { return mOrientationMode; }; 144 145 inline const bool &isForward( void ) { return mForward; }; 146 inline const F32 &getSpeed( void ) { return mSpeed; }; 147 148 inline const S32 &getSourceNode( void ) { return mSourceNode; }; 149 inline const S32 &getDestinationNode( void ) { return mDestinationNode; }; 150 inline const S32 &getStartNode( void ) { return mStartNode; }; 151 inline const S32 &getEndNode( void ) { return mEndNode; }; 152 153 Point3F getWorldPosition( void ); 154 Point3F getRenderWorldPosition( const F32 &pDelta ); 155 156 MatrixF getTransform( void ); 157 MatrixF getRenderTransform( const F32 &pDelta ); 158 159 inline F32 getTimeDelta( const bool &pUpdate = true ) 160 { 161 if ( !pUpdate ) 162 { 163 return mLastDelta; 164 } 165 166 // Calculate Delta. 167 const S32 time = Sim::getCurrentTime(); 168 const F32 delta = ( time - mLastTime ) / 1000.f; 169 170 // Store Time. 171 mLastTime = time; 172 mLastDelta = delta; 173 174 // Return Delta. 175 return delta; 176 }; 177 178 inline void resetTime( void ) 179 { 180 mLastTime = Sim::getCurrentTime(); 181 }; 182 183 //------------------------------------------------------------------------- 184 // 185 // Sets 186 // 187 //------------------------------------------------------------------------- 188 189 void setActive( const bool &pActive ); 190 191 void setObject( SceneObject *pObject ); 192 193 void setTimeInterp( const F32 &pInterp ); 194 void setPathInterp( const F32 &pInterp ); 195 void setPosition( const Point3F &pPosition ); 196 void setOffset( const Point3F &pOffset ); 197 void setOrientation( const VectorF &pOrientation ); 198 void setOrientationMode( const eOrientationType &pType ); 199 void setOrientationMode( const eOrientationType &pType, SceneObject *pObject ); 200 void setOrientationMode( const eOrientationType &pType, const Point3F &pPoint ); 201 202 void setForward( const bool &pForward ); 203 void setSpeed( const F32 &pSpeed ); 204 205 void setNode( const S32 &pSourceNodeIndex, const S32 &pDestinationNodeIndex ); 206 void setStartNode( const S32 &pNodeIndex ); 207 void setEndNode( const S32 &pNodeIndex ); 208 209 // Delta Methods. 210 211 void resetDelta( void ); 212 void resetDelta( const Point3F &pPosition, const VectorF &pOrientation ); 213 214 void popDelta( void ); 215 void pushDelta( const Point3F &pPosition, const VectorF &pOrientation ); 216 217 Point3F getPositionDelta( const F32 &pInterp ); 218 VectorF getOrientationDelta( const F32 &pInterp ); 219 220 // Net State Methods. 221 222 inline VNetStateInfo *getState( NetConnection *pConnection ) { return mNetState.getState( pConnection ); }; 223 224 inline void setMaskBits( const U32 &pMask ) { mNetState.setMaskBits( pMask ); }; 225 inline void clearMaskBits( const U32 &pMask ) { mNetState.clearMaskBits( pMask ); }; 226 227 inline bool isConnection( NetConnection *pConnection ) { return mNetState.isConnection( pConnection ); }; 228 inline void addConnection( NetConnection *pConnection ) { mNetState.addConnection( pConnection ); }; 229 inline void clearConnection( NetConnection *pConnection ) { mNetState.clearConnection( pConnection ); }; 230 231 // Enum Methods. 232 233 static eOrientationType getOrientationTypeEnum( const char *pLabel ); 234 static StringTableEntry getOrientationTypeLabel( const eOrientationType &pType ); 235}; 236 237//----------------------------------------------------------------------------- 238 239// Define Types. 240typedef VPathObject::eOrientationType VPathObjectOrientationType; 241 242// Declare Enum Types. 243DefineEnumType( VPathObjectOrientationType ); 244 245//----------------------------------------------------------------------------- 246 247#endif // _VT_VPATHOBJECT_H_ 248