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