OGRE  1.9
Object-Oriented Graphics Rendering Engine
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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-2014 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 
222  SceneManager* getSceneManager(void) const;
223 
231  void setPolygonMode(PolygonMode sd);
232 
235  PolygonMode getPolygonMode(void) const;
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;
387  Vector3 getDerivedDirection(void) const;
390  Vector3 getDerivedUp(void) const;
393  Vector3 getDerivedRight(void) const;
394 
397  const Quaternion& getRealOrientation(void) const;
400  const Vector3& getRealPosition(void) const;
403  Vector3 getRealDirection(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 
508  PlaneBoundedVolume getCameraToViewportBoxVolume(Real screenLeft,
509  Real screenTop, Real screenRight, Real screenBottom, bool includeFarPlane = false);
510 
522  void getCameraToViewportBoxVolume(Real screenLeft,
523  Real screenTop, Real screenRight, Real screenBottom,
524  PlaneBoundedVolume* outVolume, bool includeFarPlane = false);
525 
527  Real _getLodBiasInverse(void) const;
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; }
549  const vector<Plane>::type& getWindowPlanes(void) const;
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;
615  Real getNearClipDistance(void) const;
617  Real getFarClipDistance(void) 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;
651  const Quaternion& getOrientationForViewUpdate(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__
Representation of a ray in space, i.e.
Definition: OgreRay.h:46
A viewpoint from which the scene will be rendered.
Definition: OgreCamera.h:86
Class encapsulating a standard 4x4 homogeneous matrix.
Definition: OgreMatrix4.h:78
float Real
Software floating point type.
#define _OgreExport
Definition: OgrePlatform.h:260
Vector3 mAutoTrackOffset
Tracking offset for fine tuning.
Definition: OgreCamera.h:148
ListenerList mListeners
Definition: OgreCamera.h:186
Defines a plane in 3D space.
Definition: OgrePlane.h:61
Real getPixelDisplayRatio() const
Returns an estimated ratio between a pixel and the display area it represents.
Definition: OgreCamera.h:673
Frustum * getCullingFrustum(void) const
Returns the custom culling frustum in use.
Definition: OgreCamera.h:593
A frustum represents a pyramid, capped at the near and far end which is used to represent either a vi...
Definition: OgreFrustum.h:85
Manages the organisation and rendering of a 'scene' i.e.
static const Vector3 ZERO
Definition: OgreVector3.h:800
Viewport * getViewport(void) const
Get the last viewport which was attached to this camera.
Definition: OgreCamera.h:563
Vector3 mDerivedPosition
Definition: OgreCamera.h:122
A 3D box aligned with the x/y/z axes.
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
Real mPixelDisplayRatio
Definition: OgreCamera.h:183
Class representing a node in the scene graph.
Definition: OgreSceneNode.h:58
bool mYawFixed
Whether to yaw around a fixed axis.
Definition: OgreCamera.h:129
Quaternion mRealOrientation
Real world orientation/position of the camera.
Definition: OgreCamera.h:125
unsigned int mVisBatchesLastRender
Stored number of visible batches in the last render.
Definition: OgreCamera.h:140
Implementation of a Quaternion, i.e.
bool mWindowSet
Is viewing window used.
Definition: OgreCamera.h:162
bool mRecalcWindow
Was viewing window changed.
Definition: OgreCamera.h:166
Vector3 mPosition
Camera position - default (0,0,0)
Definition: OgreCamera.h:118
Quaternion mOrientation
Camera orientation, quaternion style.
Definition: OgreCamera.h:115
Real mSceneLodFactor
Scene LOD factor used to adjust overall LOD.
Definition: OgreCamera.h:151
SceneNode * mAutoTrackTarget
SceneNode which this Camera will automatically track.
Definition: OgreCamera.h:146
virtual void cameraPreRenderScene(Camera *cam)
Called prior to the scene being rendered with this camera.
Definition: OgreCamera.h:98
SceneManager * mSceneMgr
Scene manager responsible for the scene.
Definition: OgreCamera.h:112
A sphere primitive, mostly used for bounds checking.
Definition: OgreSphere.h:51
void _notifyViewport(Viewport *viewport)
Notifies this camera that a viewport is using it.
Definition: OgreCamera.h:565
vector< Listener * >::type ListenerList
Definition: OgreCamera.h:185
bool mAutoAspectRatio
Whether aspect ratio will automatically be recalculated when a viewport changes its size...
Definition: OgreCamera.h:172
Standard 3-dimensional vector.
Definition: OgreVector3.h:51
virtual bool isWindowSet(void) const
Returns if a viewport window is being used.
Definition: OgreCamera.h:547
std::ostream & operator<<(std::ostream &o, const TRect< T > &r)
Definition: OgreCommon.h:636
Represents a convex volume bounded by planes.
const Camera * mLodCamera
Camera to use for LOD calculation.
Definition: OgreCamera.h:178
Vector3 mYawFixedAxis
Fixed axis to yaw around.
Definition: OgreCamera.h:131
virtual void cameraDestroyed(Camera *cam)
Called when the camera is being destroyed.
Definition: OgreCamera.h:106
An abstraction of a viewport, i.e.
Definition: OgreViewport.h:57
bool getUseMinPixelSize() const
Returns whether to use min display size calculations.
Definition: OgreCamera.h:661
Real mSceneLodFactorInv
Inverted scene LOD factor, can be used by Renderables to adjust their LOD.
Definition: OgreCamera.h:153
unsigned int mVisFacesLastRender
Stored number of visible faces in the last render.
Definition: OgreCamera.h:137
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
Wrapper class which indicates a given angle value is in Radians.
Definition: OgreMath.h:47
PolygonMode
The polygon mode to use when rasterising.
Definition: OgreCommon.h:179
Frustum * mCullFrustum
Custom culling frustum.
Definition: OgreCamera.h:174
static String msMovableType
Shared class-level name for Movable type.
Definition: OgreCamera.h:143
static const Vector3 UNIT_Y
Definition: OgreVector3.h:802
SceneNode * getAutoTrackTarget(void) const
Get the auto tracking target for this camera, if any.
Definition: OgreCamera.h:554
FrustumPlane
Worldspace clipping planes.
Definition: OgreFrustum.h:71
_StringBase String
bool mUseMinPixelSize
Whether or not the minimum display size of objects should take effect for this camera.
Definition: OgreCamera.h:181
Vector3 mRealPosition
Definition: OgreCamera.h:126
void setCullingFrustum(Frustum *frustum)
Tells the camera to use a separate Frustum instance to perform culling.
Definition: OgreCamera.h:591
PolygonMode mSceneDetail
Rendering type.
Definition: OgreCamera.h:134
Quaternion mDerivedOrientation
Derived orientation/position of the camera, including reflection.
Definition: OgreCamera.h:121
Listener interface so you can be notified of Camera events.
Definition: OgreCamera.h:91
virtual void cameraPostRenderScene(Camera *cam)
Called after the scene has been rendered with this camera.
Definition: OgreCamera.h:102
const Vector3 & getAutoTrackOffset(void) const
Get the auto tracking offset for this camera, if it is auto tracking.
Definition: OgreCamera.h:556
Viewport * mLastViewport
The last viewport to be added using this camera.
Definition: OgreCamera.h:168
void setUseMinPixelSize(bool enable)
Sets whether to use min display size calculations.
Definition: OgreCamera.h:657
bool mUseRenderingDistance
Whether or not the rendering distance of objects should take effect for this camera.
Definition: OgreCamera.h:176
vector< Plane >::type mWindowClipPlanes
Windowed viewport clip planes.
Definition: OgreCamera.h:164