pathCamera.h

Engine/source/T3D/pathCamera.h

More...

Classes:

Detailed Description

  1
  2//-----------------------------------------------------------------------------
  3// Copyright (c) 2012 GarageGames, LLC
  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
 24#ifndef _PATHCAMERA_H_
 25#define _PATHCAMERA_H_
 26
 27#ifndef _SHAPEBASE_H_
 28#include "T3D/shapeBase.h"
 29#endif
 30
 31#ifndef _CAMERASPLINE_H_
 32#include "T3D/cameraSpline.h"
 33#endif
 34
 35
 36//----------------------------------------------------------------------------
 37struct PathCameraData: public ShapeBaseData {
 38   typedef ShapeBaseData Parent;
 39
 40   //
 41   DECLARE_CONOBJECT(PathCameraData);
 42   static void consoleInit();
 43   static void initPersistFields();
 44   virtual void packData(BitStream* stream);
 45   virtual void unpackData(BitStream* stream);
 46};
 47
 48
 49//----------------------------------------------------------------------------
 50class PathCamera: public ShapeBase
 51{
 52public:
 53   enum State {
 54      Forward,
 55      Backward,
 56      Stop,
 57      StateBits = 3
 58   };
 59
 60private:
 61   typedef ShapeBase Parent;
 62
 63   enum MaskBits {
 64      WindowMask     = Parent::NextFreeMask,
 65      PositionMask   = Parent::NextFreeMask + 1,
 66      TargetMask     = Parent::NextFreeMask + 2,
 67      StateMask      = Parent::NextFreeMask + 3,
 68      NextFreeMask   = Parent::NextFreeMask << 1
 69   };
 70
 71   struct StateDelta {
 72      F32 time;
 73      F32 timeVec;
 74   };
 75   StateDelta delta;
 76
 77   enum Constants {
 78      NodeWindow = 128    // Maximum number of active nodes
 79   };
 80
 81   //
 82   PathCameraData* mDataBlock;
 83   CameraSpline mSpline;
 84   S32 mNodeBase;
 85   S32 mNodeCount;
 86   F32 mPosition;
 87   S32 mState;
 88   F32 mTarget;
 89   bool mTargetSet;
 90
 91   void interpolateMat(F32 pos,MatrixF* mat);
 92   void advancePosition(S32 ms);
 93
 94public:
 95   DECLARE_CONOBJECT(PathCamera);
 96   
 97   DECLARE_CALLBACK( void, onNode, (S32 node));
 98
 99   PathCamera();
100   ~PathCamera();
101   static void initPersistFields();
102   static void consoleInit();
103
104   void onEditorEnable();
105   void onEditorDisable();
106
107   bool onAdd();
108   void onRemove();
109   bool onNewDataBlock( GameBaseData *dptr, bool reload );
110   void onNode(S32 node);
111
112   void processTick(const Move*);
113   void interpolateTick(F32 dt);
114   void getCameraTransform(F32* pos,MatrixF* mat);
115
116   U32  packUpdate(NetConnection *, U32 mask, BitStream *stream);
117   void unpackUpdate(NetConnection *, BitStream *stream);
118
119   void reset(F32 speed = 1);
120   void pushFront(CameraSpline::Knot *knot);
121   void pushBack(CameraSpline::Knot *knot);
122   void popFront();
123
124   void setPosition(F32 pos);
125   void setTarget(F32 pos);
126   void setState(State s);
127};
128
129
130#endif
131