Spinning Topp Logo BlackTopp Studios
inc
cameracontroller.h
1 // © Copyright 2010 - 2016 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  ///////////////////////////////////////////////////////////////////////////////
54  /// @struct AngleLimits
55  /// @brief Boundaries for rotation on one axis.
56  ///////////////////////////////////////
57  struct AngleLimits
58  {
59  /// @brief The upper limit for rotation, in radians.
61  /// @brief The lower limit for rotation, in radians.
63 
64  /// @brief Class constructor.
66  Upper(0),
67  Lower(0)
68  { }
69  };//AngleLimits
70 
71  ///////////////////////////////////////////////////////////////////////////////
72  /// @class CameraController
73  /// @brief This is a simplified controller class for use with cameras.
74  /// @details This class is useful for manipulating cameras to move around in simple ways,
75  /// such as flying through a scene.
76  ///////////////////////////////////////
78  {
79  public:
80  /// @brief Possible options for determining how the camera should move relative to the world.
82  {
83  CCM_Fly, ///< CCM_Fly: This is the default option for every Camera Controller. Allows the camera unrestrained movement throughout the scene.
84  CCM_Walk ///< CCM_Walk: This forces the camera to be only a certain distance above the terrain.
85  };
86  protected:
87  /// @internal
88  /// @brief A ray casting tool used to determine surrounding geometry to limit movement.
90  /// @internal
91  /// @brief A pointer to the Camera being controlled.
93  /// @internal
94  /// @brief A pointer to the angle limits for rotations on the Y axis.
96  /// @internal
97  /// @brief A pointer to the angle limits for rotations on the X axis.
99  /// @internal
100  /// @brief A pointer to the angle limits for rotations on the Z axis.
102  /// @internal
103  /// @brief The height at which the camera is to remain above the terrain.
105  /// @internal
106  /// @brief The current rotation of the camera on the Y axis.
108  /// @internal
109  /// @brief The current rotation of the camera on the X axis.
111  /// @internal
112  /// @brief The current rotation of the camera on the Z axis.
114  /// @internal
115  /// @brief The mode with which the camera should move around the scene.
117 
118  /// @internal
119  /// @brief Wraps an angle value if it goes outside the range of [-pi,+pi].
120  /// @param Angle The angle to be checked.
121  void CheckAngleRollover(Real Angle);
122  /// @internal
123  /// @brief Clamps all current rotation values to their set limits.
124  void CheckAngleLimits();
125  /// @internal
126  /// @brief Calls CheckAngleLimits() and CheckAngleRollover(Real).
127  void CheckAllAngles();
128  /// @internal
129  /// @brief Ensures the camera position is at the desired height above any world terrain.
130  void CheckHeight();
131  /// @internal
132  /// @brief Performs a raycast to get the distance to any terrain beneath the camera.
133  /// @return Returns the distance from the camera to terrain in world units.
134  Real FindDistanceToGround();
135  public:
136  /// @brief Blank constructor.
138  /// @brief Camera constructor.
139  /// @param ToBeControlled The camera this controller is controlling.
140  CameraController(Graphics::CameraProxy* ToBeControlled);
141  /// @brief Class destructor.
142  ~CameraController();
143 
144  ///////////////////////////////////////////////////////////////////////////////
145  // Utility
146 
147  /// @brief Sets the camera being controlled by this controller.
148  /// @param ToBeControlled The camera this controller is controlling.
149  void SetControlledCamera(Graphics::CameraProxy* ToBeControlled);
150  /// @brief Gets the camera this controller is controlling.
151  /// @return Returns a camera pointer for the camera this controller is applied to.
152  Graphics::CameraProxy* GetControlledCamera() const;
153 
154  ///////////////////////////////////////////////////////////////////////////////
155  // CameraController Properties
156 
157  /// @brief Sets the movement mode for this camera/controller.
158  /// @param MoveMode The MovementMode value for which mode you want applied. See MovementMode enum for more info.
159  void SetMovementMode(const MovementMode& MoveMode);
160  /// @brief Gets the currently set movement mode.
161  /// @return Returns an enum value representing the current movement mode. See MovementMode enum for more info.
162  MovementMode GetMovementMode() const;
163  /// @brief Sets the hover distance for the camera while it's moving.
164  /// @details Hover is only applied in CCM_Walk mode. Default: 1.0.
165  /// @param Hover The distance above the ground to hover, in world units.
166  void SetHoverHeight(const Real& Hover);
167  /// @brief Gets the distance the camera hovers over terrain while in CCM_Walk mode.
168  /// @return Returns a Real represening the distance above terrain the camera is to hover, in world units.
169  Real GetHoverHeight() const;
170  /// @brief Sets rotational limits on the Y axis.
171  /// @details The rotation range is from -Pi to Pi.
172  /// @param UpperLimit The allowed upper rotation limit in radians.
173  /// @param LowerLimit The allowed lower rotation limit in radians.
174  void SetYawLimits(const Real& UpperLimit, const Real& LowerLimit);
175  /// @brief Clears any set limits on yaw(Y axis) rotation.
176  void RemoveYawLimits();
177  /// @brief Sets rotational limits on the X axis.
178  /// @details The rotation range is from -Pi to Pi.
179  /// @param UpperLimit The allowed upper rotation limit in radians.
180  /// @param LowerLimit The allowed upper rotation limit in radians.
181  void SetPitchLimits(const Real& UpperLimit, const Real& LowerLimit);
182  /// @brief Clears any set limits on pitch(X axis) rotation.
183  void RemovePitchLimits();
184  /// @brief Sets rotational limits on the Z axis.
185  /// @details The rotation range is from -Pi to Pi.
186  /// @param UpperLimit The allowed upper rotation limit in radians.
187  /// @param LowerLimit The allowed upper rotation limit in radians.
188  void SetRollLimits(const Real& UpperLimit, const Real& LowerLimit);
189  /// @brief Clears any set limits on roll(Z axis) rotation.
190  void RemoveRollLimits();
191 
192  ///////////////////////////////////////////////////////////////////////////////
193  // Transform Methods
194 
195  /// @brief Moves the camera forward.
196  /// @param Units The distance to be moved in world units.
197  void MoveForward(Real Units);
198  /// @brief Moves the camera backward.
199  /// @param Units The distance to be moved in world units.
200  void MoveBackward(Real Units);
201  /// @brief Moves the camera to the left.
202  /// @param Units The distance to be moved in world units.
203  void StrafeLeft(Real Units);
204  /// @brief Moves the camera to the right.
205  /// @param Units The distance to be moved in world units.
206  void StrafeRight(Real Units);
207  /// @brief Rotates the camera.
208  /// @details This is a safer rotation method that applies all the checks and can lock behaviors
209  /// such as roll if configured to do so.
210  /// @param Yaw The amount to rotate the camera on it's local Y axis in Radians.
211  /// @param Pitch The amount to rotate the camera on it's local X axis in Radians.
212  /// @param Roll The amount to rotate the camera on it's local Z axis in Radians.
213  void Rotate(Real Yaw, Real Pitch, Real Roll);
214  /// @brief Rotates the camera.
215  /// @details This is a freeform rotation method that will apply the rotation desired to the
216  /// camera without any checks. This is ideal for spacecraft style controls.
217  /// @param Yaw The amount to rotate the camera on it's local Y axis in Radians.
218  /// @param Pitch The amount to rotate the camera on it's local X axis in Radians.
219  /// @param Roll The amount to rotate the camera on it's local Z axis in Radians.
220  void Rotate6DOF(Real Yaw, Real Pitch, Real Roll);
221  };// Cameracontroller
222 }//Mezzanine
223 
224 #endif
Real Lower
The lower limit for rotation, in radians.
Real HoverHeight
The height at which the camera is to remain above the terrain.
MovementMode
Possible options for determining how the camera should move relative to the world.
AngleLimits * RollLimits
A pointer to the angle limits for rotations on the Z axis.
Real YawRad
The current rotation of the camera on the Y axis.
CCM_Fly: This is the default option for every Camera Controller. Allows the camera unrestrained movem...
All the definitions for datatypes as well as some basic conversion functions are defined here...
AngleLimits()
Class constructor.
Real RollRad
The current rotation of the camera on the Z axis.
float Real
A Datatype used to represent a real floating point number.
Definition: datatypes.h:141
Real Upper
The upper limit for rotation, in radians.
MovementMode CurrentMMode
The mode with which the camera should move around the scene.
AngleLimits * YawLimits
A pointer to the angle limits for rotations on the Y axis.
This is the proxy class for placing and manipulating a camera in the scene.
Definition: cameraproxy.h:65
This is a simplified controller class for use with cameras.
#define MEZZ_LIB
Some platforms require special decorations to denote what is exported/imported in a share library...
The bulk of the engine components go in this namspace.
Definition: actor.cpp:56
Real PitchRad
The current rotation of the camera on the X axis.
This provides a number of optional tools for working with a Mezzanine::World.
Definition: rayquerytool.h:67
RayQueryTool RayCaster
A ray casting tool used to determine surrounding geometry to limit movement.
AngleLimits * PitchLimits
A pointer to the angle limits for rotations on the X axis.
Boundaries for rotation on one axis.
Graphics::CameraProxy * Controlled
A pointer to the Camera being controlled.