MezzanineEngine 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
cameraproxy.h
Go to the documentation of this file.
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 _graphicscameraproxy_h
41 #define _graphicscameraproxy_h
42 
43 /// @file
44 /// @brief This file contains the declaration for the World proxy wrapping camera functionality.
45 
47 #include "Graphics/graphicsenumerations.h"
48 #include "colourvalue.h"
49 #include "ray.h"
50 
51 namespace Ogre
52 {
53  class Camera;
54 }
55 
56 namespace Mezzanine
57 {
58  namespace Graphics
59  {
60  class Viewport;
61  class CameraManager;
62  ///////////////////////////////////////////////////////////////////////////////
63  /// @brief This is the proxy class for placing and manipulating a camera in the scene.
64  /// @details
65  ///////////////////////////////////////
67  {
68  protected:
69  friend class Viewport;
70 
71  /// @internal
72  /// @brief A string containing the forward facing name of this proxy.
74  /// @internal
75  /// @brief A vector3 representing the fixed axis on which this camera will always Yaw/rotate.
77  /// @internal
78  /// @brief A pointer to the CameraManager that created this camera.
80  /// @internal
81  /// @brief A pointer to the internal Camera this proxy is based on.
82  Ogre::Camera* GraphicsCamera;
83  /// @internal
84  /// @brief This is a pointer to the Viewport this camera is attached to, if any.
86  /// @internal
87  /// @brief A bool storing whether or not the FixedYawAxis is being used.
88  Boolean UseFixedYaw;
89 
90  /// @internal
91  /// @brief Creates an internal Camera to be used by the calling instance.
92  /// @param Name The name to be given to this CameraProxy.
93  virtual void CreateCamera(const String& Name);
94  /// @internal
95  /// @brief Destroys the internal Camera in use by this proxy.
96  virtual void DestroyCamera();
97  /// @internal
98  /// @brief Generates a name for this Camera to placate the internal system.
99  /// @note This will no longer be necessary in after the switch to Ogre 2.0.
100  /// @return Returns a string containing the auto-generated name of this Camera.
101  static String GenerateName();
102  public:
103  /// @brief Class constructor.
104  /// @param Name The name to be given to this CameraProxy.
105  /// @param Creator A pointer to the manager that created this proxy.
106  CameraProxy(const String& Name, CameraManager* Creator);
107  /// @brief XML constructor.
108  /// @param SelfRoot An XML::Node containing the data to populate this class with.
109  /// @param Creator A pointer to the manager that created this proxy.
110  CameraProxy(const XML::Node& SelfRoot, CameraManager* Creator);
111  /// @brief Class destructor.
112  virtual ~CameraProxy();
113 
114  /// @todo Wrap LOD related methods (Camera/Bias).
115  /// @todo Wrap reflection methods?
116 
117  ///////////////////////////////////////////////////////////////////////////////
118  // Utility
119 
120  /// @copydoc WorldProxy::GetProxyType() const
121  virtual Mezzanine::ProxyType GetProxyType() const;
122  /// @copydoc WorldProxy::GetCreator() const
123  virtual WorldManager* GetCreator() const;
124  /// @brief Gets the Viewport this camera is attached to, if any.
125  /// @return Returns a pointer to the Viewport this camera is rendering to, or NULL if not attached.
126  virtual Viewport* GetViewport() const;
127 
128  /// @brief Gets whether this cameras Yaw rotation is based on a fixed axis.
129  /// @return Returns true if a fixed Yaw axis is enabled and in use, false otherwise.
130  virtual Boolean IsFixedYawEnabled() const;
131 
132  /// @brief Sets the direction the camera faces based on a 3D point.
133  /// @param TargetLoc The location in the world to look at.
134  virtual void LookAt(const Vector3& TargetLoc);
135  /// @brief Sets the direction the light will be emitted from this source.
136  /// @note The direction is not used if this is a point light.
137  /// @param Dir A Vector3 representing the direction the light will travel from this source.
138  virtual void SetDirection(const Vector3& Dir);
139  /// @brief Gets the direction the light from this source is being emitted.
140  /// @note The direction is not used if this is a point light.
141  /// @return Returns a Vector3 representing the direction this proxy is emitting light.
142  virtual Vector3 GetDirection() const;
143 
144  /// @brief Gets a Ray from the camera to the viewport.
145  /// @param ScreenX A Real representing the relative location on screen, on the x axis(0.0 - 1.0).
146  /// @param ScreenY A Real representing the relative location on screen, on the y axis(0.0 - 1.0).
147  virtual Ray GetCameraToViewportRay(const Real ScreenX, const Real ScreenY) const;
148 
149  ///////////////////////////////////////////////////////////////////////////////
150  // Camera Properties
151 
152  /// @brief Gets the name of this Camera.
153  /// @return Returns a const reference to a string containing the cameras name.
154  virtual const String& GetName() const;
155 
156  /// @brief Sets the debug rendering mode for this camera.
157  /// @param PolyMode A CameraPolyMode enum value expressing the mode to be set.
158  virtual void SetPolygonMode(const Graphics::CameraPolyMode PolyMode);
159  /// @brief Gets the debug rendering mode for this camera.
160  /// @return Returns a CameraPolyMode enum value representing the current mode of this camera.
161  virtual Graphics::CameraPolyMode GetPolygonMode() const;
162  /// @brief Sets the type of projection to be used with this camera.
163  /// @remarks By default, all cameras are enabled with Perspective projection. This is the standard 3-dimentional
164  /// view anyone would expect in a 3D world. Orthographic projection is useful when displaying 2D worlds, or only
165  /// 2 dimentions of a 3D world. It enables you to see the entire side of an object without regard for camera perspective.
166  /// Perspective can be thought of as a pyramid, with the camera at the top of the cone. Orthographic would instead be a cube.
167  /// @param ProjType A ProjectionType enum value that expresses the type of projection to be used.
168  virtual void SetProjectionType(const Graphics::ProjectionType ProjType);
169  /// @brief Get the type of projection used by the camera.
170  /// @return A ProjectionType enum value that will identify the kind of projection this camera uses.
171  virtual Graphics::ProjectionType GetProjectionType() const;
172  /// @brief Sets the orientation mode of this cameras frustrum.
173  /// @param OriMode An OrientationMode enum value that expresses the type of orientation this cameras frustrum will use.
174  virtual void SetOrientationMode(const Graphics::OrientationMode OriMode);
175  /// @brief Gets the orientation mode of this cameras frustrum.
176  /// @return An OrientationMode enum value that will identify the kind of orientation this cameras frustrum uses.
177  virtual Graphics::OrientationMode GetOrientationMode() const;
178 
179  /// @brief Defines the size of the Orthographic projection window in world units.
180  /// @remarks This function can change the aspect ratio of the screen, determined by the values passed in. To set the
181  /// window size without changing the aspect ratio, call either the SetOrthoWindowHeight, or SetOrthoWindowWidth functions.
182  /// @param Width The new width of the projection window.
183  /// @param Height The new height of the projection window.
184  virtual void SetOrthoWindow(const Real Width, const Real Height);
185  /// @brief Defines the size of the Orthographic projection window in world units.
186  /// @remarks This function will not change the aspect ratio of the screen, unlike SetOrthoWindow. The aspect ratio will be
187  /// preserved and the Height of the screen automatically recalculated based on the Width passed in.
188  /// @param Width The new width of the projection window.
189  virtual void SetOrthoWindowWidth(const Real Width);
190  /// @brief Gets the current width of the Orthographic projection window in world units.
191  /// @return Returns a Real represnting the world unit width of the projection window when Orthographic projection is enabled.
192  virtual Real GetOrthoWindowWidth() const;
193  /// @brief Defines the size of the Orthographic projection window in world units.
194  /// @remarks This function will not change the aspect ratio of the screen, unlike SetOrthoWindow. The aspect ratio will be
195  /// preserved and the Width of the screen automatically recalculated based on the Height passed in.
196  /// @param Height The new height of the projection window.
197  virtual void SetOrthoWindowHeight(const Real Height);
198  /// @brief Gets the current height of the Orthographic projection window in world units.
199  /// @return Returns a Real represnting the world unit height of the projection window when Orthographic projection is enabled.
200  virtual Real GetOrthoWindowHeight() const;
201 
202  /// @brief Sets the distance in world units at which objects are considered too close to render.
203  /// @param NearDist A Real representing the distance.
204  virtual void SetNearClipDistance(const Real NearDist);
205  /// @brief Gets the distance in world units at which objects are considered too close to render.
206  /// @return Returns a Real representing the distance from the camera to the near clipping plane.
207  virtual Real GetNearClipDistance() const;
208  /// @brief Sets the distance in world units at which objects are considered too far to render.
209  /// @param FarDist A Real representing the distance.
210  virtual void SetFarClipDistance(const Real FarDist);
211  /// @brief Gets the distance in world units at which objects are considered too far to render.
212  /// @return Returns a Real representing the distance from the camera to the far clipping plane.
213  virtual Real GetFarClipDistance() const;
214 
215  /// @brief Sets the vertical field of view of the camera frustrum.
216  /// @remarks Higher values (90+ degrees, 1.57079633+ radians) result in wide-angle, fish-eye views. Low values (30- degrees, 0.523598776- radians)
217  /// result in telescopic views. Normal values are between 45 degrees(0.785398163 radians) and 60 degrees(1.04719755 radians).
218  /// @param FOV The field of view in radians.
219  virtual void SetFieldOfViewY(const Real FOV);
220  /// @brief Gets the vertical field of view of the camera frustrum.
221  /// @return Returns a Real representing the current vertical field of view of this camera in radians.
222  virtual Real GetFieldOfViewY() const;
223 
224  /// @brief Sets the aspect ratio of the cameras veiw.
225  /// @param Ratio A Real that represents the camera frustrum viewport aspect ratio, where Ratio = width / height.
226  virtual void SetAspectRatio(const Real Ratio);
227  /// @brief Gets the aspect ratio of the cameras veiw.
228  /// @return Returns a Real representing the aspect ratio for the camera frustrum viewport.
229  virtual Real GetAspectRatio() const;
230 
231  /// @brief Sets whether or not to lock rotation around the Y axis.
232  /// @remarks This function is automatically called on by the camera constructor.
233  /// @param UseFixed Enable or disable the locking of the axis.
234  /// @param Axis The axis to lock, defaults to the Y axis.
235  virtual void SetFixedYawAxis(const Boolean UseFixed, const Vector3& Axis = Vector3::Unit_Y());
236  /// @brief If fixed yaw is enabled, on which axis is yawing disabled.
237  /// @return Returns a Vector3 of 0s if disable, otherwise this return the Fixed Yaw Axis.
238  virtual Vector3 GetFixedYawAxis() const;
239 
240  ///////////////////////////////////////////////////////////////////////////////
241  // Serialization
242 
243  /// @copydoc WorldProxy::ProtoSerializeProperties(XML::Node& SelfRoot) const
244  virtual void ProtoSerializeProperties(XML::Node& SelfRoot) const;
245  /// @copydoc WorldProxy::ProtoDeSerializeProperties(const XML::Node& SelfRoot)
246  virtual void ProtoDeSerializeProperties(const XML::Node& SelfRoot);
247 
248  /// @copydoc WorldProxy::GetDerivedSerializableName() const
249  virtual String GetDerivedSerializableName() const;
250  /// @copydoc WorldProxy::GetSerializableName()
251  static String GetSerializableName();
252 
253  ///////////////////////////////////////////////////////////////////////////////
254  // Internal Methods
255 
256  /// @internal
257  /// @brief Accessor for the internal camera.
258  /// @return Returns a pointer to the internal camera this proxy is based on.
259  virtual Ogre::Camera* _GetGraphicsObject() const;
260  /// @copydoc RenderableProxy::_GetBaseGraphicsObject() const
261  virtual Ogre::MovableObject* _GetBaseGraphicsObject() const;
262  };// ©ameraProxy
263  }//Graphics
264 }//Mezzanine
265 
266 #endif