OGRE  1.9.0
OgreCamera.h
Go to the documentation of this file.
1/*
2-----------------------------------------------------------------------------
3This source file is part of OGRE
4 (Object-oriented Graphics Rendering Engine)
5For the latest info, see http://www.ogre3d.org
6
7Copyright (c) 2000-2014 Torus Knot Software Ltd
8
9Permission is hereby granted, free of charge, to any person obtaining a copy
10of this software and associated documentation files (the "Software"), to deal
11in the Software without restriction, including without limitation the rights
12to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13copies of the Software, and to permit persons to whom the Software is
14furnished to do so, subject to the following conditions:
15
16The above copyright notice and this permission notice shall be included in
17all copies or substantial portions of the Software.
18
19THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25THE 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"
46#include "OgreHeaderPrefix.h"
47
48
49namespace Ogre {
50
86 class _OgreExport Camera : public Frustum
87 {
88 public:
92 {
93 public:
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
132
135
138
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
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
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
384 const Vector3& getDerivedPosition(void) const;
394
397 const Quaternion& getRealOrientation(void) const;
400 const Vector3& getRealPosition(void) const;
406 Vector3 getRealUp(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
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
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
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.
SceneManager * getSceneManager(void) const
Returns a pointer to the SceneManager this camera is rendering through.
const Vector3 & getRealPosition(void) const
Gets the real world position of the camera, including any translation inherited from a node attachmen...
const Matrix4 & getViewMatrix(void) const
Gets the view matrix for this frustum.
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.
void invalidateFrustum(void) const
Signal to update frustum information.
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
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 Vector3 & getPosition(void) const
Retrieves the camera's position.
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.
void setDirection(const Vector3 &vec)
Sets the camera's direction vector.
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.
Viewport * getViewport(void) const
Get the last viewport which was attached to this camera.
Definition OgreCamera.h:563
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 Quaternion & getDerivedOrientation(void) const
Gets the derived orientation of the camera, including any rotation inherited from a node attachment a...
const Vector3 & getPositionForViewUpdate(void) const
Get the derived position 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.
void _notifyRenderedBatches(unsigned int numbatches)
Internal method to notify camera of the visible batches in the last render.
const vector< Plane >::type & getWindowPlanes(void) const
Gets the window clip planes, only applicable if isWindowSet == true.
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
Frustum * getCullingFrustum(void) const
Returns the custom culling frustum in use.
Definition OgreCamera.h:593
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
const String & getMovableType(void) const
Overridden from MovableObject.
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.
const Matrix4 & getViewMatrix(bool ownFrustumOnly) const
Specialised version of getViewMatrix allowing caller to differentiate whether the custom culling frus...
virtual vector< Vector4 >::type getRayForwardIntersect(const Vector3 &anchor, const Vector3 *dir, Real planeOffset) const
Helper function for forwardIntersect that intersects rays with canonical plane.
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
const Vector3 & getDerivedPosition(void) const
Gets the derived position of the camera, including any translation inherited from a node attachment a...
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
Vector3 getRealRight(void) const
Gets the real world right vector of the camera, including any rotation inherited from a node attachme...
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
const Quaternion & getOrientation(void) const
Returns the camera's current orientation.
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.
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.
_OgreExport friend std::ostream & operator<<(std::ostream &o, const Camera &c)
Function for outputting to a stream.
const Quaternion & getRealOrientation(void) const
Gets the real world orientation of the camera, including any rotation inherited from a node attachmen...
Vector3 getDerivedRight(void) const
Gets the derived right vector of the camera, including any rotation inherited from a node attachment ...
unsigned int mVisFacesLastRender
Stored number of visible faces in the last render.
Definition OgreCamera.h:137
const Vector3 & getAutoTrackOffset(void) const
Get the auto tracking offset for this camera, if it is auto tracking.
Definition OgreCamera.h:556
const Vector3 * getWorldSpaceCorners(void) const
Gets the world space corners of the frustum.
SceneNode * getAutoTrackTarget(void) const
Get the auto tracking target for this camera, if any.
Definition OgreCamera.h:554
virtual const Camera * getLodCamera() const
Get a pointer to the camera which should be used to determine LOD settings.
unsigned int _getNumRenderedBatches(void) const
Internal method to retrieve the number of visible batches in the last render.
const Quaternion & getOrientationForViewUpdate(void) const
Get the derived orientation of this frustum.
void setAutoTracking(bool enabled, SceneNode *const target=0, const Vector3 &offset=Vector3::ZERO)
Enables / disables automatic tracking of a SceneNode.
const Plane & getFrustumPlane(unsigned short plane) const
Retrieves a specified plane of the frustum (world space).
Viewport * mLastViewport
The last viewport to be added using this camera.
Definition OgreCamera.h:168
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.
A sphere primitive, mostly used for bounds checking.
Definition OgreSphere.h:52
Standard 3-dimensional vector.
Definition OgreVector3.h:52
An abstraction of a viewport, i.e.
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
std::vector< T, A > type