camera.h

Engine/source/T3D/camera.h

More...

Classes:

class

Implements a basic camera object.

Public Typedefs

CameraMotionMode 

Public Functions

Detailed Description

Public Typedefs

typedef Camera::CameraMotionMode CameraMotionMode 

Public Functions

DefineEnumType(CameraMotionMode )

  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 _CAMERA_H_
 25#define _CAMERA_H_
 26
 27#ifndef _SHAPEBASE_H_
 28#include "T3D/shapeBase.h"
 29#endif
 30
 31#ifndef _DYNAMIC_CONSOLETYPES_H_
 32#include "console/dynamicTypes.h"
 33#endif
 34
 35
 36class CameraData: public ShapeBaseData 
 37{
 38   public:
 39
 40      typedef ShapeBaseData Parent;
 41
 42      // ShapeBaseData.
 43      DECLARE_CONOBJECT( CameraData );
 44      DECLARE_CATEGORY( "Game" );
 45      DECLARE_DESCRIPTION( "A datablock that describes a camera." );
 46
 47      static void initPersistFields();
 48      virtual void packData(BitStream* stream);
 49      virtual void unpackData(BitStream* stream);
 50};
 51
 52
 53/// Implements a basic camera object.
 54class Camera: public ShapeBase
 55{
 56   public:
 57
 58      typedef ShapeBase Parent;
 59
 60      /// Movement behavior type for camera.
 61      enum CameraMotionMode
 62      {
 63         StationaryMode  = 0,
 64
 65         FreeRotateMode,
 66         FlyMode,
 67         OrbitObjectMode,
 68         OrbitPointMode,
 69         TrackObjectMode,
 70         OverheadMode,
 71         EditOrbitMode,       ///< Used by the World Editor
 72
 73         CameraFirstMode = 0,
 74         CameraLastMode  = EditOrbitMode
 75      };
 76
 77      /// The ExtendedMove position/rotation index used for camera movements
 78      static S32 smExtendedMovePosRotIndex;
 79
 80   protected:
 81
 82      enum MaskBits
 83      {
 84         MoveMask          = Parent::NextFreeMask,
 85         UpdateMask        = Parent::NextFreeMask << 1,
 86         NewtonCameraMask  = Parent::NextFreeMask << 2,
 87         EditOrbitMask     = Parent::NextFreeMask << 3,
 88         NextFreeMask      = Parent::NextFreeMask << 4
 89      };
 90
 91      struct StateDelta
 92      {
 93         Point3F pos;
 94         Point3F rot;
 95         VectorF posVec;
 96         VectorF rotVec;
 97      };
 98
 99      CameraData* mDataBlock;
100
101      Point3F mRot;
102      StateDelta mDelta;
103
104      Point3F mOffset;
105
106      static F32 smMovementSpeed;
107
108      SimObjectPtr<GameBase> mOrbitObject;
109      F32 mMinOrbitDist;
110      F32 mMaxOrbitDist;
111      F32 mCurOrbitDist;
112      Point3F mPosition;
113      bool mObservingClientObject;
114
115      F32 mLastAbsoluteYaw;            ///< Stores that last absolute yaw value as passed in by ExtendedMove
116      F32 mLastAbsolutePitch;          ///< Stores that last absolute pitch value as passed in by ExtendedMove
117      F32 mLastAbsoluteRoll;           ///< Stores that last absolute roll value as passed in by ExtendedMove
118
119      /// @name NewtonFlyMode
120      /// @{
121
122      VectorF  mAngularVelocity;
123      F32      mAngularForce;
124      F32      mAngularDrag;
125      VectorF  mVelocity;
126      bool     mNewtonMode;
127      bool     mNewtonRotation;
128      F32      mMass;
129      F32      mDrag;
130      F32      mFlyForce;
131      F32      mSpeedMultiplier;
132      F32      mBrakeMultiplier;
133
134      /// @}
135
136      /// @name EditOrbitMode
137      /// @{
138
139      bool     mValidEditOrbitPoint;
140      Point3F  mEditOrbitPoint;
141      F32      mCurrentEditOrbitDist;
142
143      /// @}
144
145      bool mLocked;
146
147      CameraMotionMode  mMode;
148
149      void _setPosition(const Point3F& pos,const Point3F& viewRot);
150      void _setRenderPosition(const Point3F& pos,const Point3F& viewRot);
151      void _validateEyePoint( F32 pos, MatrixF* mat );
152
153      void _calcOrbitPoint( MatrixF* mat, const Point3F& rot );
154      void _calcEditOrbitPoint( MatrixF *mat, const Point3F& rot );
155
156      static bool _setModeField( void *object, const char *index, const char *data );
157      static bool _setNewtonField( void *object, const char *index, const char *data );
158
159      // ShapeBase.
160      virtual F32 getCameraFov();
161      virtual void setCameraFov( F32 fov );
162      virtual F32 getDefaultCameraFov();
163      virtual bool isValidCameraFov( F32 fov );
164      virtual F32 getDamageFlash() const;
165      virtual F32 getWhiteOut() const;
166      virtual void setTransform( const MatrixF& mat );
167      virtual void setRenderTransform( const MatrixF& mat );
168
169   public:
170
171      Camera();
172      ~Camera();
173
174      CameraMotionMode getMode() const { return mMode; }
175
176      Point3F getPosition();
177      Point3F getRotation() { return mRot; };
178      void setRotation( const Point3F& viewRot );
179
180      Point3F getOffset() { return mOffset; };
181      void lookAt( const Point3F& pos);
182      void setOffset( const Point3F& offset) { if( mOffset != offset ) mOffset = offset; setMaskBits( UpdateMask ); }
183      void setFlyMode();
184      void setOrbitMode( GameBase *obj, const Point3F& pos, const Point3F& rot, const Point3F& offset,
185                         F32 minDist, F32 maxDist, F32 curDist, bool ownClientObject, bool locked = false );
186      void setTrackObject( GameBase *obj, const Point3F& offset);
187      void onDeleteNotify( SimObject* obj );
188
189      GameBase* getOrbitObject()      { return(mOrbitObject); }
190      bool isObservingClientObject()   { return(mObservingClientObject); }
191
192      /// @name NewtonFlyMode
193      /// @{
194
195      void setNewtonFlyMode();
196      VectorF getVelocity() const { return mVelocity; }
197      void setVelocity( const VectorF& vel );
198      VectorF getAngularVelocity() const { return mAngularVelocity; }
199      void setAngularVelocity( const VectorF& vel );
200      bool isRotationDamped() {return mNewtonRotation;}
201      void setAngularForce( F32 force ) {mAngularForce = force; setMaskBits(NewtonCameraMask);}
202      void setAngularDrag( F32 drag ) {mAngularDrag = drag; setMaskBits(NewtonCameraMask);}
203      void setMass( F32 mass ) {mMass = mass; setMaskBits(NewtonCameraMask);}
204      void setDrag( F32 drag ) {mDrag = drag; setMaskBits(NewtonCameraMask);}
205      void setFlyForce( F32 force ) {mFlyForce = force; setMaskBits(NewtonCameraMask);}
206      void setSpeedMultiplier( F32 mul ) {mSpeedMultiplier = mul; setMaskBits(NewtonCameraMask);}
207      void setBrakeMultiplier( F32 mul ) {mBrakeMultiplier = mul; setMaskBits(NewtonCameraMask);}
208
209      /// @}
210
211      /// @name EditOrbitMode
212      /// @{
213
214      void setEditOrbitMode();
215      bool isEditOrbitMode() {return mMode == EditOrbitMode;}
216      bool getValidEditOrbitPoint() { return mValidEditOrbitPoint; }
217      void setValidEditOrbitPoint( bool state );
218      Point3F getEditOrbitPoint() const;
219      void setEditOrbitPoint( const Point3F& pnt );
220
221      /// Orient the camera to view the given radius.  Requires that an
222      /// edit orbit point has been set.
223      void autoFitRadius( F32 radius );
224
225      /// @}
226
227      // ShapeBase.
228      static void initPersistFields();
229      static void consoleInit();
230
231      virtual void onEditorEnable();
232      virtual void onEditorDisable();
233
234      virtual bool onAdd();
235      virtual void onRemove();
236      virtual bool onNewDataBlock( GameBaseData *dptr, bool reload );
237      virtual void processTick( const Move* move );
238      virtual void interpolateTick( F32 delta);
239      virtual void getCameraTransform( F32* pos,MatrixF* mat );
240      virtual void getEyeCameraTransform( IDisplayDevice *display, U32 eyeId, MatrixF *outMat );
241      virtual DisplayPose calcCameraDeltaPose(GameConnection *con, const DisplayPose& inPose);
242
243      virtual void writePacketData( GameConnection* conn, BitStream* stream );
244      virtual void readPacketData( GameConnection* conn, BitStream* stream );
245      virtual U32  packUpdate( NetConnection* conn, U32 mask, BitStream* stream );
246      virtual void unpackUpdate( NetConnection* conn, BitStream* stream );
247
248      DECLARE_CONOBJECT( Camera );
249      DECLARE_CATEGORY( "Game" );
250      DECLARE_DESCRIPTION( "Represents a position, direction and field of view to render a scene from." );
251};
252
253typedef Camera::CameraMotionMode CameraMotionMode;
254DefineEnumType( CameraMotionMode );
255
256#endif
257