afxCamera.h

Engine/source/afx/afxCamera.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//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
 25// Arcane-FX for MIT Licensed Open Source version of Torque 3D from GarageGames
 26// Copyright (C) 2015 Faust Logic, Inc.
 27//
 28// afxCamera implements a modified camera for demonstrating a third person camera style
 29// which is more common to RPG games than the standard FPS style camera. For the most part,
 30// it is a hybrid of the standard TGE camera and the third person mode of the Advanced Camera
 31// resource, authored by Thomas "Man of Ice" Lund. This camera implements the bare minimum
 32// required for demonstrating an RPG style camera and leaves tons of room for improvement. 
 33// It should be replaced with a better camera if possible.
 34//
 35// Advanced Camera Resource by Thomas "Man of Ice" Lund:
 36//   http://www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=5471
 37//
 38//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
 39
 40#ifndef _AFX_CAMERA_H_
 41#define _AFX_CAMERA_H_
 42
 43#ifndef _SHAPEBASE_H_
 44#include "game/shapeBase.h"
 45#endif
 46
 47//----------------------------------------------------------------------------
 48struct afxCameraData: public ShapeBaseData {
 49  typedef ShapeBaseData Parent;
 50
 51  static U32    sCameraCollisionMask;
 52
 53  //
 54  DECLARE_CONOBJECT(afxCameraData);
 55  DECLARE_CATEGORY("AFX");
 56  static void initPersistFields();
 57  virtual void packData(BitStream* stream);
 58  virtual void unpackData(BitStream* stream);
 59};
 60
 61
 62//----------------------------------------------------------------------------
 63// Implements a basic camera object.
 64class afxCamera: public ShapeBase
 65{
 66  typedef ShapeBase Parent;
 67
 68  enum MaskBits {
 69    MoveMask     = Parent::NextFreeMask,
 70    SubjectMask  = Parent::NextFreeMask << 1,
 71    NextFreeMask = Parent::NextFreeMask << 2
 72  };
 73
 74  struct StateDelta {
 75    Point3F pos;
 76    Point3F rot;
 77    VectorF posVec;
 78    VectorF rotVec;
 79  };
 80
 81  enum 
 82  {
 83    ThirdPersonMode = 1,
 84    FlyMode         = 2,
 85    OrbitObjectMode = 3,
 86    OrbitPointMode  = 4,
 87    CameraFirstMode = 0,
 88    CameraLastMode  = 4
 89  };
 90
 91private:
 92  int             mMode;
 93  Point3F         mRot;
 94  StateDelta      mDelta;
 95
 96  SimObjectPtr<GameBase> mOrbitObject;
 97  F32             mMinOrbitDist;
 98  F32             mMaxOrbitDist;
 99  F32             mCurOrbitDist;
100  Point3F         mPosition;
101  bool            mObservingClientObject;
102
103  SceneObject*    mCam_subject;
104  Point3F         mCam_offset;
105  Point3F         mCoi_offset;
106  F32             mCam_distance;
107  F32             mCam_angle;
108  bool            mCam_dirty;
109
110  bool            mFlymode_saved;
111  Point3F         mFlymode_saved_pos;
112  S8              mThird_person_snap_c;
113  S8              mThird_person_snap_s;
114
115  void            set_cam_pos(const Point3F& pos, const Point3F& viewRot);
116  void            cam_update(F32 dt, bool on_server);
117
118public:
119  /*C*/           afxCamera();
120  /*D*/           ~afxCamera();
121
122  Point3F&        getPosition();
123  void            setFlyMode();
124  void            setOrbitMode(GameBase* obj, Point3F& pos, AngAxisF& rot, F32 minDist, F32 maxDist, F32 curDist, bool ownClientObject);
125  void            validateEyePoint(F32 pos, MatrixF *mat);
126
127  GameBase*       getOrbitObject() { return(mOrbitObject); }
128  bool            isObservingClientObject() { return(mObservingClientObject); }
129
130  void            snapToPosition(const Point3F& pos);
131  void            setCameraSubject(SceneObject* subject);
132  void            setThirdPersonOffset(const Point3F& offset);
133  void            setThirdPersonOffset(const Point3F& offset, const Point3F& coi_offset);
134  const Point3F&  getThirdPersonOffset() const { return mCam_offset; }
135  const Point3F&  getThirdPersonCOIOffset() const { return mCoi_offset; }
136  void            setThirdPersonDistance(F32 distance);
137  F32             getThirdPersonDistance();
138  void            setThirdPersonAngle(F32 angle);
139  F32             getThirdPersonAngle();
140  void            setThirdPersonMode();
141  void            setThirdPersonSnap();
142  void            setThirdPersonSnapClient();
143  const char*     getMode();
144
145  bool            isCamera() const { return true; }
146
147  DECLARE_CONOBJECT(afxCamera);
148  DECLARE_CATEGORY("AFX");
149
150private:          // 3POV SECTION
151  void            cam_update_3pov(F32 dt, bool on_server);
152  bool            avoid_blocked_view(const Point3F& start, const Point3F& end, Point3F& newpos);
153  bool            test_blocked_line(const Point3F& start, const Point3F& end);
154
155public:           // STD OVERRIDES SECTION
156  virtual bool    onAdd();
157  virtual void    onRemove();
158  virtual void    onDeleteNotify(SimObject *obj);
159
160  virtual void    advanceTime(F32 dt);
161  virtual void    processTick(const Move* move);
162  virtual void    interpolateTick(F32 delta);
163
164  virtual void    writePacketData(GameConnection *conn, BitStream *stream);
165  virtual void    readPacketData(GameConnection *conn, BitStream *stream);
166  virtual U32     packUpdate(NetConnection *conn, U32 mask, BitStream *stream);
167  virtual void    unpackUpdate(NetConnection *conn, BitStream *stream);
168
169  virtual void    onCameraScopeQuery(NetConnection* cr, CameraScopeQuery*);
170  virtual void    getCameraTransform(F32* pos,MatrixF* mat);
171  virtual void    setTransform(const MatrixF& mat);
172
173  virtual void    onEditorEnable();
174  virtual void    onEditorDisable();
175
176  virtual F32     getCameraFov();
177  virtual F32     getDefaultCameraFov();
178  virtual bool    isValidCameraFov(F32 fov);
179  virtual void    setCameraFov(F32 fov);
180
181  virtual F32     getDamageFlash() const;
182  virtual F32     getWhiteOut() const;
183
184  virtual void setControllingClient( GameConnection* connection );
185};
186
187
188#endif // _AFX_CAMERA_H_
189