MezzanineEngine 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
cameracontroller.h
1 // © Copyright 2010 - 2014 BlackTopp Studios Inc.
2 /* This file is part of The Mezzanine Engine.
3 
4  The Mezzanine Engine is free software: you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation, either version 3 of the License, or
7  (at your option) any later version.
8 
9  The Mezzanine Engine is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with The Mezzanine Engine. If not, see <http://www.gnu.org/licenses/>.
16 */
17 /* The original authors have included a copy of the license specified above in the
18  'Docs' folder. See 'gpl.txt'
19 */
20 /* We welcome the use of the Mezzanine engine to anyone, including companies who wish to
21  Build professional software and charge for their product.
22 
23  However there are some practical restrictions, so if your project involves
24  any of the following you should contact us and we will try to work something
25  out:
26  - DRM or Copy Protection of any kind(except Copyrights)
27  - Software Patents You Do Not Wish to Freely License
28  - Any Kind of Linking to Non-GPL licensed Works
29  - Are Currently In Violation of Another Copyright Holder's GPL License
30  - If You want to change our code and not add a few hundred MB of stuff to
31  your distribution
32 
33  These and other limitations could cause serious legal problems if you ignore
34  them, so it is best to simply contact us or the Free Software Foundation, if
35  you have any questions.
36 
37  Joseph Toppi - toppij@gmail.com
38  John Blackwood - makoenergy02@gmail.com
39 */
40 #ifndef _cameracontroller_h
41 #define _cameracontroller_h
42 
43 #include "datatypes.h"
44 #include "rayquerytool.h"
45 
46 namespace Mezzanine
47 {
48  namespace Graphics
49  {
50  class CameraProxy;
51  }
52 
53  ///@brief Boundaries for rotation on one axis
54  struct AngleLimits
55  {
56  Real Upper;
57  Real Lower;
58  AngleLimits() : Upper(0),Lower(0) {}
59  };
60 
61  ///////////////////////////////////////////////////////////////////////////////
62  /// @class CameraController
63  /// @headerfile cameracontroller.h
64  /// @brief This is a simplified controller class for use with cameras.
65  /// @details This class is useful for manipulating cameras to move around in simple ways,
66  /// such as flying through a scene.
67  ///////////////////////////////////////
69  {
70  public:
71  /// @enum MovementMode
72  /// @brief Possible options for determining how the camera should move relative to the world.
74  {
75  CCM_Fly, ///< CCM_Fly: This is the default option for every Camera Controller. Allows the camera unrestrained movement throughout the scene.
76  CCM_Walk ///< CCM_Walk: This forces the camera to be only a certain distance above the terrain.
77  };
78  protected:
79  RayQueryTool RayCaster;
80 
81  Graphics::CameraProxy* Controlled;
82  MovementMode CurrentMMode;
83  Real HoverHeight;
84 
85  Real YawRad;
86  Real PitchRad;
87  Real RollRad;
88 
89  AngleLimits* YawLimits;
90  AngleLimits* PitchLimits;
91  AngleLimits* RollLimits;
92 
93  void CheckAngleRollover(Real Angle);
94  void CheckAngleLimits();
95  void CheckAllAngles();
96  void CheckHeight();
97  Real FindDistanceToGround();
98  public:
99  /// @brief Class constructor.
100  /// @param ToBeControlled The camera this controller is controlling.
101  CameraController(Graphics::CameraProxy* ToBeControlled);
102  /// @brief Class destructor.
103  ~CameraController();
104 
105  ///////////////////////////////////////////////////////////////////////////////
106  // Utility
107 
108  /// @brief Gets the camera this controller is controlling.
109  /// @return Returns a camera pointer for the camera this controller is applied to.
110  Graphics::CameraProxy* GetControlledCamera() const;
111 
112  ///////////////////////////////////////////////////////////////////////////////
113  // CameraController Properties
114 
115  /// @brief Sets the movement mode for this camera/controller.
116  /// @param MoveMode The MovementMode value for which mode you want applied. See MovementMode enum for more info.
117  void SetMovementMode(const MovementMode& MoveMode);
118  /// @brief Gets the currently set movement mode.
119  /// @return Returns an enum value representing the current movement mode. See MovementMode enum for more info.
120  MovementMode GetMovementMode() const;
121  /// @brief Sets the hover distance for the camera while it's moving.
122  /// @details Hover is only applied in CCM_Walk mode. Default: 1.0.
123  /// @param Hover The distance above the ground to hover, in world units.
124  void SetHoverHeight(const Real& Hover);
125  /// @brief Gets the distance the camera hovers over terrain while in CCM_Walk mode.
126  /// @return Returns a Real represening the distance above terrain the camera is to hover, in world units.
127  Real GetHoverHeight() const;
128  /// @brief Sets rotational limits on the Y axis.
129  /// @details The rotation range is from -Pi to Pi.
130  /// @param UpperLimit The allowed upper rotation limit in radians.
131  /// @param LowerLimit The allowed lower rotation limit in radians.
132  void SetYawLimits(const Real& UpperLimit, const Real& LowerLimit);
133  /// @brief Clears any set limits on yaw(Y axis) rotation.
134  void RemoveYawLimits();
135  /// @brief Sets rotational limits on the X axis.
136  /// @details The rotation range is from -Pi to Pi.
137  /// @param UpperLimit The allowed upper rotation limit in radians.
138  /// @param LowerLimit The allowed upper rotation limit in radians.
139  void SetPitchLimits(const Real& UpperLimit, const Real& LowerLimit);
140  /// @brief Clears any set limits on pitch(X axis) rotation.
141  void RemovePitchLimits();
142  /// @brief Sets rotational limits on the Z axis.
143  /// @details The rotation range is from -Pi to Pi.
144  /// @param UpperLimit The allowed upper rotation limit in radians.
145  /// @param LowerLimit The allowed upper rotation limit in radians.
146  void SetRollLimits(const Real& UpperLimit, const Real& LowerLimit);
147  /// @brief Clears any set limits on roll(Z axis) rotation.
148  void RemoveRollLimits();
149 
150  ///////////////////////////////////////////////////////////////////////////////
151  // Transform Methods
152 
153  /// @brief Moves the camera forward.
154  /// @param Units The distance to be moved in world units.
155  void MoveForward(Real Units);
156  /// @brief Moves the camera backward.
157  /// @param Units The distance to be moved in world units.
158  void MoveBackward(Real Units);
159  /// @brief Moves the camera to the left.
160  /// @param Units The distance to be moved in world units.
161  void StrafeLeft(Real Units);
162  /// @brief Moves the camera to the right.
163  /// @param Units The distance to be moved in world units.
164  void StrafeRight(Real Units);
165  /// @brief Rotates the camera.
166  /// @details This is a safer rotation method that applies all the checks and can lock behaviors
167  /// such as roll if configured to do so.
168  /// @param Yaw The amount to rotate the camera on it's local Y axis in Radians.
169  /// @param Pitch The amount to rotate the camera on it's local X axis in Radians.
170  /// @param Roll The amount to rotate the camera on it's local Z axis in Radians.
171  void Rotate(Real Yaw, Real Pitch, Real Roll);
172  /// @brief Rotates the camera.
173  /// @details This is a freeform rotation method that will apply the rotation desired to the
174  /// camera without any checks. This is ideal for spacecraft style controls.
175  /// @param Yaw The amount to rotate the camera on it's local Y axis in Radians.
176  /// @param Pitch The amount to rotate the camera on it's local X axis in Radians.
177  /// @param Roll The amount to rotate the camera on it's local Z axis in Radians.
178  void Rotate6DOF(Real Yaw, Real Pitch, Real Roll);
179  };// ©ameracontroller
180 }//Mezzanine
181 
182 #endif