OgreCamera.h
Go to the documentation of this file.
1 /*
2 -----------------------------------------------------------------------------
3 This source file is part of OGRE
4  (Object-oriented Graphics Rendering Engine)
5 For the latest info, see http://www.ogre3d.org
6 
7 Copyright (c) 2000-2013 Torus Knot Software Ltd
8 
9 Permission is hereby granted, free of charge, to any person obtaining a copy
10 of this software and associated documentation files (the "Software"), to deal
11 in the Software without restriction, including without limitation the rights
12 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 copies of the Software, and to permit persons to whom the Software is
14 furnished to do so, subject to the following conditions:
15 
16 The above copyright notice and this permission notice shall be included in
17 all copies or substantial portions of the Software.
18 
19 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 THE SOFTWARE.
26 -----------------------------------------------------------------------------
27 */
28 #ifndef __Camera_H__
29 #define __Camera_H__
30 
31 // Default options
32 #include "OgrePrerequisites.h"
33 
34 #include "OgreString.h"
35 #include "OgreMovableObject.h"
36 
37 // Matrices & Vectors
38 #include "OgreMatrix4.h"
39 #include "OgreVector3.h"
40 #include "OgrePlane.h"
41 #include "OgreQuaternion.h"
42 #include "OgreCommon.h"
43 #include "OgreFrustum.h"
44 #include "OgreRay.h"
45 #include "OgrePlaneBoundedVolume.h"
46 #include "OgreHeaderPrefix.h"
47 
48 
49 namespace Ogre {
50 
86  class _OgreExport Camera : public Frustum
87  {
88  public:
92  {
93  public:
94  Listener() {}
95  virtual ~Listener() {}
96 
98  virtual void cameraPreRenderScene(Camera* cam)
99  { (void)cam; }
100 
102  virtual void cameraPostRenderScene(Camera* cam)
103  { (void)cam; }
104 
106  virtual void cameraDestroyed(Camera* cam)
107  { (void)cam; }
108 
109  };
110  protected:
113 
116 
119 
123 
127 
129  bool mYawFixed;
132 
135 
137  unsigned int mVisFacesLastRender;
138 
140  unsigned int mVisBatchesLastRender;
141 
144 
149 
154 
155 
160  Real mWLeft, mWTop, mWRight, mWBottom;
166  mutable bool mRecalcWindow;
179 
184 
187 
188 
189  // Internal functions for calcs
190  bool isViewOutOfDate(void) const;
192  void invalidateFrustum(void) const;
194  void invalidateView(void) const;
195 
196 
201  virtual void setWindowImpl(void) const;
202 
204  virtual vector<Vector4>::type getRayForwardIntersect(const Vector3& anchor, const Vector3 *dir, Real planeOffset) const;
205 
206  public:
209  Camera( const String& name, SceneManager* sm);
210 
213  virtual ~Camera();
214 
216  virtual void addListener(Listener* l);
218  virtual void removeListener(Listener* l);
219 
223 
232 
236 
239  void setPosition(Real x, Real y, Real z);
240 
243  void setPosition(const Vector3& vec);
244 
247  const Vector3& getPosition(void) const;
248 
251  void move(const Vector3& vec);
252 
255  void moveRelative(const Vector3& vec);
256 
262  void setDirection(Real x, Real y, Real z);
263 
266  void setDirection(const Vector3& vec);
267 
270  Vector3 getDirection(void) const;
271 
274  Vector3 getUp(void) const;
275 
278  Vector3 getRight(void) const;
279 
288  void lookAt( const Vector3& targetPoint );
301  void lookAt(Real x, Real y, Real z);
302 
305  void roll(const Radian& angle);
306 
309  void yaw(const Radian& angle);
310 
313  void pitch(const Radian& angle);
314 
317  void rotate(const Vector3& axis, const Radian& angle);
318 
321  void rotate(const Quaternion& q);
322 
342  void setFixedYawAxis( bool useFixed, const Vector3& fixedAxis = Vector3::UNIT_Y );
343 
344 
347  const Quaternion& getOrientation(void) const;
348 
351  void setOrientation(const Quaternion& q);
352 
357  void _renderScene(Viewport *vp, bool includeOverlays);
358 
361  _OgreExport friend std::ostream& operator<<(std::ostream& o, const Camera& c);
362 
365  void _notifyRenderedFaces(unsigned int numfaces);
366 
369  void _notifyRenderedBatches(unsigned int numbatches);
370 
373  unsigned int _getNumRenderedFaces(void) const;
374 
377  unsigned int _getNumRenderedBatches(void) const;
378 
381  const Quaternion& getDerivedOrientation(void) const;
384  const Vector3& getDerivedPosition(void) const;
390  Vector3 getDerivedUp(void) const;
394 
397  const Quaternion& getRealOrientation(void) const;
400  const Vector3& getRealPosition(void) const;
406  Vector3 getRealUp(void) const;
409  Vector3 getRealRight(void) const;
410 
412  void getWorldTransforms(Matrix4* mat) const;
413 
415  const String& getMovableType(void) const;
416 
436  void setAutoTracking(bool enabled, SceneNode* const target = 0,
437  const Vector3& offset = Vector3::ZERO);
438 
439 
455  void setLodBias(Real factor = 1.0);
456 
461  Real getLodBias(void) const;
462 
475  virtual void setLodCamera(const Camera* lodCam);
476 
483  virtual const Camera* getLodCamera() const;
484 
485 
490  Ray getCameraToViewportRay(Real screenx, Real screeny) const;
496  void getCameraToViewportRay(Real screenx, Real screeny, Ray* outRay) const;
497 
509  Real screenTop, Real screenRight, Real screenBottom, bool includeFarPlane = false);
510 
523  Real screenTop, Real screenRight, Real screenBottom,
524  PlaneBoundedVolume* outVolume, bool includeFarPlane = false);
525 
528 
529 
531  void _autoTrack(void);
532 
533 
543  virtual void setWindow (Real left, Real top, Real right, Real bottom);
545  virtual void resetWindow (void);
547  virtual bool isWindowSet(void) const { return mWindowSet; }
550 
552  Real getBoundingRadius(void) const;
554  SceneNode* getAutoTrackTarget(void) const { return mAutoTrackTarget; }
556  const Vector3& getAutoTrackOffset(void) const { return mAutoTrackOffset; }
557 
563  Viewport* getViewport(void) const {return mLastViewport;}
565  void _notifyViewport(Viewport* viewport) {mLastViewport = viewport;}
566 
574  void setAutoAspectRatio(bool autoratio);
575 
578  bool getAutoAspectRatio(void) const;
579 
591  void setCullingFrustum(Frustum* frustum) { mCullFrustum = frustum; }
593  Frustum* getCullingFrustum(void) const { return mCullFrustum; }
594 
599  virtual void forwardIntersect(const Plane& worldPlane, vector<Vector4>::type* intersect3d) const;
600 
602  bool isVisible(const AxisAlignedBox& bound, FrustumPlane* culledBy = 0) const;
604  bool isVisible(const Sphere& bound, FrustumPlane* culledBy = 0) const;
606  bool isVisible(const Vector3& vert, FrustumPlane* culledBy = 0) const;
608  const Vector3* getWorldSpaceCorners(void) const;
610  const Plane& getFrustumPlane( unsigned short plane ) const;
612  bool projectSphere(const Sphere& sphere,
613  Real* left, Real* top, Real* right, Real* bottom) const;
619  const Matrix4& getViewMatrix(void) const;
628  const Matrix4& getViewMatrix(bool ownFrustumOnly) const;
634  virtual void setUseRenderingDistance(bool use) { mUseRenderingDistance = use; }
638  virtual bool getUseRenderingDistance(void) const { return mUseRenderingDistance; }
639 
646  virtual void synchroniseBaseSettingsWith(const Camera* cam);
647 
649  const Vector3& getPositionForViewUpdate(void) const;
652 
657  void setUseMinPixelSize(bool enable) { mUseMinPixelSize = enable; }
661  bool getUseMinPixelSize() const { return mUseMinPixelSize; }
662 
673  Real getPixelDisplayRatio() const { return mPixelDisplayRatio; }
674 
675  };
679 } // namespace Ogre
680 
681 #include "OgreHeaderSuffix.h"
682 
683 #endif // __Camera_H__
#define _OgreExport
Definition: OgrePlatform.h:257
A 3D box aligned with the x/y/z axes.
Listener interface so you can be notified of Camera events.
Definition: OgreCamera.h:92
virtual void cameraPreRenderScene(Camera *cam)
Called prior to the scene being rendered with this camera.
Definition: OgreCamera.h:98
virtual void cameraDestroyed(Camera *cam)
Called when the camera is being destroyed.
Definition: OgreCamera.h:106
virtual void cameraPostRenderScene(Camera *cam)
Called after the scene has been rendered with this camera.
Definition: OgreCamera.h:102
A viewpoint from which the scene will be rendered.
Definition: OgreCamera.h:87
bool mAutoAspectRatio
Whether aspect ratio will automatically be recalculated when a viewport changes its size.
Definition: OgreCamera.h:172
Real getLodBias(void) const
Returns the level-of-detail bias factor currently applied to this camera.
void invalidateView(void) const
Signal to update view information.
bool mWindowSet
Is viewing window used.
Definition: OgreCamera.h:162
Frustum * mCullFrustum
Custom culling frustum.
Definition: OgreCamera.h:174
bool mUseMinPixelSize
Whether or not the minimum display size of objects should take effect for this camera.
Definition: OgreCamera.h:181
Real getNearClipDistance(void) const
Sets the position of the near clipping plane.
SceneNode * getAutoTrackTarget(void) const
Get the auto tracking target for this camera, if any.
Definition: OgreCamera.h:554
void invalidateFrustum(void) const
Signal to update frustum information.
const Vector3 & getPosition(void) const
Retrieves the camera's position.
Quaternion mDerivedOrientation
Derived orientation/position of the camera, including reflection.
Definition: OgreCamera.h:121
unsigned int mVisBatchesLastRender
Stored number of visible batches in the last render.
Definition: OgreCamera.h:140
void getCameraToViewportRay(Real screenx, Real screeny, Ray *outRay) const
Gets a world space ray as cast from the camera through a viewport position.
Vector3 mDerivedPosition
Definition: OgreCamera.h:122
bool isViewOutOfDate(void) const
SceneManager * getSceneManager(void) const
Returns a pointer to the SceneManager this camera is rendering through.
Vector3 getDerivedUp(void) const
Gets the derived up vector of the camera, including any rotation inherited from a node attachment and...
PlaneBoundedVolume getCameraToViewportBoxVolume(Real screenLeft, Real screenTop, Real screenRight, Real screenBottom, bool includeFarPlane=false)
Gets a world-space list of planes enclosing a volume based on a viewport rectangle.
const Matrix4 & getViewMatrix(bool ownFrustumOnly) const
Specialised version of getViewMatrix allowing caller to differentiate whether the custom culling frus...
Vector3 getRealDirection(void) const
Gets the real world direction vector of the camera, including any rotation inherited from a node atta...
bool mUseRenderingDistance
Whether or not the rendering distance of objects should take effect for this camera.
Definition: OgreCamera.h:176
Vector3 getRight(void) const
Gets the camera's right vector.
virtual void synchroniseBaseSettingsWith(const Camera *cam)
Synchronise core camera settings with another.
const String & getMovableType(void) const
Overridden from MovableObject.
void setDirection(const Vector3 &vec)
Sets the camera's direction vector.
const Matrix4 & getViewMatrix(void) const
Gets the view matrix for this frustum.
const Quaternion & getOrientation(void) const
Returns the camera's current orientation.
void setFixedYawAxis(bool useFixed, const Vector3 &fixedAxis=Vector3::UNIT_Y)
Tells the camera whether to yaw around it's own local Y axis or a fixed axis of choice.
virtual void addListener(Listener *l)
Add a listener to this camera.
void yaw(const Radian &angle)
Rotates the camera anticlockwise around it's local y axis.
bool isVisible(const Sphere &bound, FrustumPlane *culledBy=0) const
Tests whether the given container is visible in the Frustum.
void getWorldTransforms(Matrix4 *mat) const
Overridden from Frustum/Renderable.
Vector3 getRealUp(void) const
Gets the real world up vector of the camera, including any rotation inherited from a node attachment.
vector< Plane >::type mWindowClipPlanes
Windowed viewport clip planes.
Definition: OgreCamera.h:164
virtual void setLodCamera(const Camera *lodCam)
Set a pointer to the camera which should be used to determine LOD settings.
Real getPixelDisplayRatio() const
Returns an estimated ratio between a pixel and the display area it represents.
Definition: OgreCamera.h:673
const Vector3 & getRealPosition(void) const
Gets the real world position of the camera, including any translation inherited from a node attachmen...
const Quaternion & getOrientationForViewUpdate(void) const
Get the derived orientation of this frustum.
void lookAt(Real x, Real y, Real z)
Points the camera at a location in worldspace.
Vector3 mAutoTrackOffset
Tracking offset for fine tuning.
Definition: OgreCamera.h:148
unsigned int _getNumRenderedFaces(void) const
Internal method to retrieve the number of visible faces in the last render.
void moveRelative(const Vector3 &vec)
Moves the camera's position by the vector offset provided along it's own axes (relative to orientatio...
void lookAt(const Vector3 &targetPoint)
Points the camera at a location in worldspace.
const Vector3 & getPositionForViewUpdate(void) const
Get the derived position of this frustum.
void _notifyRenderedBatches(unsigned int numbatches)
Internal method to notify camera of the visible batches in the last render.
bool mYawFixed
Whether to yaw around a fixed axis.
Definition: OgreCamera.h:129
bool getUseMinPixelSize() const
Returns whether to use min display size calculations.
Definition: OgreCamera.h:661
Camera(const String &name, SceneManager *sm)
Standard constructor.
void pitch(const Radian &angle)
Pitches the camera up/down anticlockwise around it's local z axis.
void roll(const Radian &angle)
Rolls the camera anticlockwise, around its local z axis.
Real mSceneLodFactor
Scene LOD factor used to adjust overall LOD.
Definition: OgreCamera.h:151
Vector3 mYawFixedAxis
Fixed axis to yaw around.
Definition: OgreCamera.h:131
void setUseMinPixelSize(bool enable)
Sets whether to use min display size calculations.
Definition: OgreCamera.h:657
void setPosition(Real x, Real y, Real z)
Sets the camera's position.
const Camera * mLodCamera
Camera to use for LOD calculation.
Definition: OgreCamera.h:178
SceneManager * mSceneMgr
Scene manager responsible for the scene.
Definition: OgreCamera.h:112
Viewport * getViewport(void) const
Get the last viewport which was attached to this camera.
Definition: OgreCamera.h:563
const Vector3 * getWorldSpaceCorners(void) const
Gets the world space corners of the frustum.
Frustum * getCullingFrustum(void) const
Returns the custom culling frustum in use.
Definition: OgreCamera.h:593
Real _getLodBiasInverse(void) const
Internal method for OGRE to use for LOD calculations.
virtual bool isWindowSet(void) const
Returns if a viewport window is being used.
Definition: OgreCamera.h:547
void setCullingFrustum(Frustum *frustum)
Tells the camera to use a separate Frustum instance to perform culling.
Definition: OgreCamera.h:591
Real mPixelDisplayRatio
Definition: OgreCamera.h:183
Vector3 getDerivedDirection(void) const
Gets the derived direction vector of the camera, including any rotation inherited from a node attachm...
bool isVisible(const AxisAlignedBox &bound, FrustumPlane *culledBy=0) const
Tests whether the given container is visible in the Frustum.
PolygonMode getPolygonMode(void) const
Retrieves the level of detail that the camera will render.
Ray getCameraToViewportRay(Real screenx, Real screeny) const
Gets a world space ray as cast from the camera through a viewport position.
void move(const Vector3 &vec)
Moves the camera's position by the vector offset provided along world axes.
void setLodBias(Real factor=1.0)
Sets the level-of-detail factor for this Camera.
Real getFarClipDistance(void) const
Retrieves the distance from the frustum to the far clipping plane.
virtual bool getUseRenderingDistance(void) const
Get whether this camera should use the 'rendering distance' on objects to exclude distant objects fro...
Definition: OgreCamera.h:638
void _notifyRenderedFaces(unsigned int numfaces)
Internal method to notify camera of the visible faces in the last render.
Real mSceneLodFactorInv
Inverted scene LOD factor, can be used by Renderables to adjust their LOD.
Definition: OgreCamera.h:153
void _autoTrack(void)
Internal method used by OGRE to update auto-tracking cameras.
void setPolygonMode(PolygonMode sd)
Sets the level of rendering detail required from this camera.
Vector3 getDirection(void) const
Gets the camera's direction.
Quaternion mOrientation
Camera orientation, quaternion style.
Definition: OgreCamera.h:115
bool isVisible(const Vector3 &vert, FrustumPlane *culledBy=0) const
Tests whether the given vertex is visible in the Frustum.
virtual void setWindow(Real left, Real top, Real right, Real bottom)
Sets the viewing window inside of viewport.
Vector3 mPosition
Camera position - default (0,0,0)
Definition: OgreCamera.h:118
void rotate(const Quaternion &q)
Rotate the camera around an arbitrary axis using a Quaternion.
ListenerList mListeners
Definition: OgreCamera.h:186
virtual void forwardIntersect(const Plane &worldPlane, vector< Vector4 >::type *intersect3d) const
Forward projects frustum rays to find forward intersection with plane.
bool getAutoAspectRatio(void) const
Retrieves if AutoAspectRatio is currently set or not.
Vector3 mRealPosition
Definition: OgreCamera.h:126
virtual ~Camera()
Standard destructor.
vector< Listener * >::type ListenerList
Definition: OgreCamera.h:185
Vector3 getUp(void) const
Gets the camera's up vector.
bool mRecalcWindow
Was viewing window changed.
Definition: OgreCamera.h:166
SceneNode * mAutoTrackTarget
SceneNode which this Camera will automatically track.
Definition: OgreCamera.h:146
virtual const Camera * getLodCamera() const
Get a pointer to the camera which should be used to determine LOD settings.
Vector3 getRealRight(void) const
Gets the real world right vector of the camera, including any rotation inherited from a node attachme...
_OgreExport friend std::ostream & operator<<(std::ostream &o, const Camera &c)
Function for outputting to a stream.
void setAutoAspectRatio(bool autoratio)
If set to true a viewport that owns this frustum will be able to recalculate the aspect ratio wheneve...
Real getBoundingRadius(void) const
Overridden from MovableObject.
static String msMovableType
Shared class-level name for Movable type.
Definition: OgreCamera.h:143
void setOrientation(const Quaternion &q)
Sets the camera's orientation.
virtual void setWindowImpl(void) const
Do actual window setting, using parameters set in SetWindow call.
PolygonMode mSceneDetail
Rendering type.
Definition: OgreCamera.h:134
void setPosition(const Vector3 &vec)
Sets the camera's position.
Quaternion mRealOrientation
Real world orientation/position of the camera.
Definition: OgreCamera.h:125
void rotate(const Vector3 &axis, const Radian &angle)
Rotate the camera around an arbitrary axis.
const Vector3 & getDerivedPosition(void) const
Gets the derived position of the camera, including any translation inherited from a node attachment a...
void _notifyViewport(Viewport *viewport)
Notifies this camera that a viewport is using it.
Definition: OgreCamera.h:565
virtual void removeListener(Listener *l)
Remove a listener to this camera.
const Quaternion & getRealOrientation(void) const
Gets the real world orientation of the camera, including any rotation inherited from a node attachmen...
const Quaternion & getDerivedOrientation(void) const
Gets the derived orientation of the camera, including any rotation inherited from a node attachment a...
virtual vector< Vector4 >::type getRayForwardIntersect(const Vector3 &anchor, const Vector3 *dir, Real planeOffset) const
Helper function for forwardIntersect that intersects rays with canonical plane.
Vector3 getDerivedRight(void) const
Gets the derived right vector of the camera, including any rotation inherited from a node attachment ...
const Vector3 & getAutoTrackOffset(void) const
Get the auto tracking offset for this camera, if it is auto tracking.
Definition: OgreCamera.h:556
unsigned int mVisFacesLastRender
Stored number of visible faces in the last render.
Definition: OgreCamera.h:137
unsigned int _getNumRenderedBatches(void) const
Internal method to retrieve the number of visible batches in the last render.
void setAutoTracking(bool enabled, SceneNode *const target=0, const Vector3 &offset=Vector3::ZERO)
Enables / disables automatic tracking of a SceneNode.
const vector< Plane >::type & getWindowPlanes(void) const
Gets the window clip planes, only applicable if isWindowSet == true.
Viewport * mLastViewport
The last viewport to be added using this camera.
Definition: OgreCamera.h:168
const Plane & getFrustumPlane(unsigned short plane) const
Retrieves a specified plane of the frustum (world space).
void _renderScene(Viewport *vp, bool includeOverlays)
Tells the Camera to contact the SceneManager to render from it's viewpoint.
virtual void setUseRenderingDistance(bool use)
Set whether this camera should use the 'rendering distance' on objects to exclude distant objects fro...
Definition: OgreCamera.h:634
void getCameraToViewportBoxVolume(Real screenLeft, Real screenTop, Real screenRight, Real screenBottom, PlaneBoundedVolume *outVolume, bool includeFarPlane=false)
Gets a world-space list of planes enclosing a volume based on a viewport rectangle.
bool projectSphere(const Sphere &sphere, Real *left, Real *top, Real *right, Real *bottom) const
Project a sphere onto the near plane and get the bounding rectangle.
void setDirection(Real x, Real y, Real z)
Sets the camera's direction vector.
virtual void resetWindow(void)
Cancel view window.
A frustum represents a pyramid, capped at the near and far end which is used to represent either a vi...
Definition: OgreFrustum.h:86
Class encapsulating a standard 4x4 homogeneous matrix.
Definition: OgreMatrix4.h:79
Represents a convex volume bounded by planes.
Defines a plane in 3D space.
Definition: OgrePlane.h:62
Implementation of a Quaternion, i.e.
Wrapper class which indicates a given angle value is in Radians.
Definition: OgreMath.h:48
Representation of a ray in space, i.e.
Definition: OgreRay.h:47
Manages the organisation and rendering of a 'scene' i.e.
Class representing a node in the scene graph.
Definition: OgreSceneNode.h:59
A sphere primitive, mostly used for bounds checking.
Definition: OgreSphere.h:52
Standard 3-dimensional vector.
Definition: OgreVector3.h:52
static const Vector3 ZERO
Definition: OgreVector3.h:800
static const Vector3 UNIT_Y
Definition: OgreVector3.h:802
An abstraction of a viewport, i.e.
Definition: OgreViewport.h:58
PolygonMode
The polygon mode to use when rasterising.
Definition: OgreCommon.h:180
FrustumPlane
Worldspace clipping planes.
Definition: OgreFrustum.h:72
float Real
Software floating point type.
_StringBase String

Copyright © 2012 Torus Knot Software Ltd
Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.