Call the correct system rename
[Torque-3d.git] / Engine / source / T3D / camera.h
blob5e760e61f9eb11778446f573c2d4a1ab84975443
1 //-----------------------------------------------------------------------------
2 // Copyright (c) 2012 GarageGames, LLC
3 //
4 // Permission is hereby granted, free of charge, to any person obtaining a copy
5 // of this software and associated documentation files (the "Software"), to
6 // deal in the Software without restriction, including without limitation the
7 // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
8 // sell copies of the Software, and to permit persons to whom the Software is
9 // furnished to do so, subject to the following conditions:
11 // The above copyright notice and this permission notice shall be included in
12 // all copies or substantial portions of the Software.
14 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
20 // IN THE SOFTWARE.
21 //-----------------------------------------------------------------------------
23 #ifndef _CAMERA_H_
24 #define _CAMERA_H_
26 #ifndef _SHAPEBASE_H_
27 #include "T3D/shapeBase.h"
28 #endif
30 #ifndef _DYNAMIC_CONSOLETYPES_H_
31 #include "console/dynamicTypes.h"
32 #endif
35 class CameraData: public ShapeBaseData
37 public:
39 typedef ShapeBaseData Parent;
41 // ShapeBaseData.
42 DECLARE_CONOBJECT( CameraData );
43 DECLARE_CATEGORY( "Game" );
44 DECLARE_DESCRIPTION( "A datablock that describes a camera." );
46 static void initPersistFields();
47 virtual void packData(BitStream* stream);
48 virtual void unpackData(BitStream* stream);
52 /// Implements a basic camera object.
53 class Camera: public ShapeBase
55 public:
57 typedef ShapeBase Parent;
59 /// Movement behavior type for camera.
60 enum CameraMotionMode
62 StationaryMode = 0,
64 FreeRotateMode,
65 FlyMode,
66 OrbitObjectMode,
67 OrbitPointMode,
68 TrackObjectMode,
69 OverheadMode,
70 EditOrbitMode, ///< Used by the World Editor
72 CameraFirstMode = 0,
73 CameraLastMode = EditOrbitMode
76 /// The ExtendedMove position/rotation index used for camera movements
77 static S32 smExtendedMovePosRotIndex;
79 protected:
81 enum MaskBits
83 MoveMask = Parent::NextFreeMask,
84 UpdateMask = Parent::NextFreeMask << 1,
85 NewtonCameraMask = Parent::NextFreeMask << 2,
86 EditOrbitMask = Parent::NextFreeMask << 3,
87 NextFreeMask = Parent::NextFreeMask << 4
90 struct StateDelta
92 Point3F pos;
93 Point3F rot;
94 VectorF posVec;
95 VectorF rotVec;
98 CameraData* mDataBlock;
100 Point3F mRot;
101 StateDelta mDelta;
103 Point3F mOffset;
105 static F32 smMovementSpeed;
107 SimObjectPtr<GameBase> mOrbitObject;
108 F32 mMinOrbitDist;
109 F32 mMaxOrbitDist;
110 F32 mCurOrbitDist;
111 Point3F mPosition;
112 bool mObservingClientObject;
114 F32 mLastAbsoluteYaw; ///< Stores that last absolute yaw value as passed in by ExtendedMove
115 F32 mLastAbsolutePitch; ///< Stores that last absolute pitch value as passed in by ExtendedMove
116 F32 mLastAbsoluteRoll; ///< Stores that last absolute roll value as passed in by ExtendedMove
118 /// @name NewtonFlyMode
119 /// @{
121 VectorF mAngularVelocity;
122 F32 mAngularForce;
123 F32 mAngularDrag;
124 VectorF mVelocity;
125 bool mNewtonMode;
126 bool mNewtonRotation;
127 F32 mMass;
128 F32 mDrag;
129 F32 mFlyForce;
130 F32 mSpeedMultiplier;
131 F32 mBrakeMultiplier;
133 /// @}
135 /// @name EditOrbitMode
136 /// @{
138 bool mValidEditOrbitPoint;
139 Point3F mEditOrbitPoint;
140 F32 mCurrentEditOrbitDist;
142 /// @}
144 bool mLocked;
146 CameraMotionMode mMode;
148 void _setPosition(const Point3F& pos,const Point3F& viewRot);
149 void _setRenderPosition(const Point3F& pos,const Point3F& viewRot);
150 void _validateEyePoint( F32 pos, MatrixF* mat );
152 void _calcOrbitPoint( MatrixF* mat, const Point3F& rot );
153 void _calcEditOrbitPoint( MatrixF *mat, const Point3F& rot );
155 static bool _setModeField( void *object, const char *index, const char *data );
156 static bool _setNewtonField( void *object, const char *index, const char *data );
158 // ShapeBase.
159 virtual F32 getCameraFov();
160 virtual void setCameraFov( F32 fov );
161 virtual F32 getDefaultCameraFov();
162 virtual bool isValidCameraFov( F32 fov );
163 virtual F32 getDamageFlash() const;
164 virtual F32 getWhiteOut() const;
165 virtual void setTransform( const MatrixF& mat );
166 virtual void setRenderTransform( const MatrixF& mat );
168 public:
170 Camera();
171 ~Camera();
173 CameraMotionMode getMode() const { return mMode; }
175 Point3F getPosition();
176 Point3F getRotation() { return mRot; };
177 void setRotation( const Point3F& viewRot );
179 Point3F getOffset() { return mOffset; };
180 void lookAt( const Point3F& pos);
181 void setOffset( const Point3F& offset) { if( mOffset != offset ) mOffset = offset; setMaskBits( UpdateMask ); }
182 void setFlyMode();
183 void setOrbitMode( GameBase *obj, const Point3F& pos, const Point3F& rot, const Point3F& offset,
184 F32 minDist, F32 maxDist, F32 curDist, bool ownClientObject, bool locked = false );
185 void setTrackObject( GameBase *obj, const Point3F& offset);
186 void onDeleteNotify( SimObject* obj );
188 GameBase* getOrbitObject() { return(mOrbitObject); }
189 bool isObservingClientObject() { return(mObservingClientObject); }
191 /// @name NewtonFlyMode
192 /// @{
194 void setNewtonFlyMode();
195 VectorF getVelocity() const { return mVelocity; }
196 void setVelocity( const VectorF& vel );
197 VectorF getAngularVelocity() const { return mAngularVelocity; }
198 void setAngularVelocity( const VectorF& vel );
199 bool isRotationDamped() {return mNewtonRotation;}
200 void setAngularForce( F32 force ) {mAngularForce = force; setMaskBits(NewtonCameraMask);}
201 void setAngularDrag( F32 drag ) {mAngularDrag = drag; setMaskBits(NewtonCameraMask);}
202 void setMass( F32 mass ) {mMass = mass; setMaskBits(NewtonCameraMask);}
203 void setDrag( F32 drag ) {mDrag = drag; setMaskBits(NewtonCameraMask);}
204 void setFlyForce( F32 force ) {mFlyForce = force; setMaskBits(NewtonCameraMask);}
205 void setSpeedMultiplier( F32 mul ) {mSpeedMultiplier = mul; setMaskBits(NewtonCameraMask);}
206 void setBrakeMultiplier( F32 mul ) {mBrakeMultiplier = mul; setMaskBits(NewtonCameraMask);}
208 /// @}
210 /// @name EditOrbitMode
211 /// @{
213 void setEditOrbitMode();
214 bool isEditOrbitMode() {return mMode == EditOrbitMode;}
215 bool getValidEditOrbitPoint() { return mValidEditOrbitPoint; }
216 void setValidEditOrbitPoint( bool state );
217 Point3F getEditOrbitPoint() const;
218 void setEditOrbitPoint( const Point3F& pnt );
220 /// Orient the camera to view the given radius. Requires that an
221 /// edit orbit point has been set.
222 void autoFitRadius( F32 radius );
224 /// @}
226 // ShapeBase.
227 static void initPersistFields();
228 static void consoleInit();
230 virtual void onEditorEnable();
231 virtual void onEditorDisable();
233 virtual bool onAdd();
234 virtual void onRemove();
235 virtual bool onNewDataBlock( GameBaseData *dptr, bool reload );
236 virtual void processTick( const Move* move );
237 virtual void interpolateTick( F32 delta);
238 virtual void getCameraTransform( F32* pos,MatrixF* mat );
239 virtual void getEyeCameraTransform( IDisplayDevice *display, U32 eyeId, MatrixF *outMat );
241 virtual void writePacketData( GameConnection* conn, BitStream* stream );
242 virtual void readPacketData( GameConnection* conn, BitStream* stream );
243 virtual U32 packUpdate( NetConnection* conn, U32 mask, BitStream* stream );
244 virtual void unpackUpdate( NetConnection* conn, BitStream* stream );
246 DECLARE_CONOBJECT( Camera );
247 DECLARE_CATEGORY( "Game" );
248 DECLARE_DESCRIPTION( "Represents a position, direction and field of view to render a scene from." );
251 typedef Camera::CameraMotionMode CameraMotionMode;
252 DefineEnumType( CameraMotionMode );
254 #endif