OGRE  2.0
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 // Matrices & Vectors
35 #include "OgreCommon.h"
36 #include "OgreFrustum.h"
37 #include "OgreHeaderPrefix.h"
38 
39 
40 namespace Ogre {
41 
42  class Matrix4;
43  class Ray;
44 
82  class _OgreExport Camera : public Frustum
83  {
84  public:
88  {
89  public:
90  Listener() {}
91  virtual ~Listener() {}
92 
94  virtual void cameraPreRenderScene(Camera* cam)
95  { (void)cam; }
96 
98  virtual void cameraPostRenderScene(Camera* cam)
99  { (void)cam; }
100 
102  virtual void cameraDestroyed(Camera* cam)
103  { (void)cam; }
104 
105  };
106  protected:
109 
112 
115 
119 
123 
125  bool mYawFixed;
128 
131 
133  unsigned int mVisFacesLastRender;
134 
136  unsigned int mVisBatchesLastRender;
137 
140 
145 
150 
155  Real mWLeft, mWTop, mWRight, mWBottom;
161  mutable bool mRecalcWindow;
174 
179 
182 
185 
186 
187  // Internal functions for calcs
188  bool isViewOutOfDate(void) const;
190  void invalidateFrustum(void) const;
192  void invalidateView(void) const;
193 
194 
199  virtual void setWindowImpl(void) const;
200 
202  virtual vector<Vector4>::type getRayForwardIntersect(const Vector3& anchor, const Vector3 *dir, Real planeOffset) const;
203 
204  public:
207  Camera( IdType id, ObjectMemoryManager *objectMemoryManager, SceneManager* sm );
208 
211  virtual ~Camera();
212 
214  virtual void addListener(Listener* l);
216  virtual void removeListener(Listener* l);
217 
220  SceneManager* getSceneManager(void) const;
221 
229  void setPolygonMode(PolygonMode sd);
230 
233  PolygonMode getPolygonMode(void) const;
234 
237  void setPosition(Real x, Real y, Real z);
238 
241  void setPosition(const Vector3& vec);
242 
245  const Vector3& getPosition(void) const;
246 
249  void move(const Vector3& vec);
250 
253  void moveRelative(const Vector3& vec);
254 
260  void setDirection(Real x, Real y, Real z);
261 
264  void setDirection(const Vector3& vec);
265 
268  Vector3 getDirection(void) const;
269 
272  Vector3 getUp(void) const;
273 
276  Vector3 getRight(void) const;
277 
286  void lookAt( const Vector3& targetPoint );
299  void lookAt(Real x, Real y, Real z);
300 
303  void roll(const Radian& angle);
304 
307  void yaw(const Radian& angle);
308 
311  void pitch(const Radian& angle);
312 
315  void rotate(const Vector3& axis, const Radian& angle);
316 
319  void rotate(const Quaternion& q);
320 
340  void setFixedYawAxis( bool useFixed, const Vector3& fixedAxis = Vector3::UNIT_Y );
341 
342 
345  const Quaternion& getOrientation(void) const;
346 
349  void setOrientation(const Quaternion& q);
350 
359  void _cullScenePhase01(const Camera *lodCamera, Viewport *vp, uint8 firstRq, uint8 lastRq );
360 
361  void _renderScenePhase02(const Camera *lodCamera, Viewport *vp, uint8 firstRq, uint8 lastRq,
362  bool includeOverlays);
363 
366  _OgreExport friend std::ostream& operator<<(std::ostream& o, const Camera& c);
367 
370  void _notifyRenderedFaces(unsigned int numfaces);
371 
374  void _notifyRenderedBatches(unsigned int numbatches);
375 
378  unsigned int _getNumRenderedFaces(void) const;
379 
382  unsigned int _getNumRenderedBatches(void) const;
383 
386  const Quaternion& getDerivedOrientation(void) const;
389  const Vector3& getDerivedPosition(void) const;
392  Vector3 getDerivedDirection(void) const;
395  Vector3 getDerivedUp(void) const;
398  Vector3 getDerivedRight(void) const;
399 
401  const Vector3& _getCachedDerivedPosition(void) const { return mDerivedPosition; }
402 
405  const Quaternion& getRealOrientation(void) const;
408  const Vector3& getRealPosition(void) const;
411  Vector3 getRealDirection(void) const;
414  Vector3 getRealUp(void) const;
417  Vector3 getRealRight(void) const;
418 
420  void getWorldTransforms(Matrix4* mat) const;
421 
423  const String& getMovableType(void) const;
424 
444  void setAutoTracking(bool enabled, SceneNode* const target = 0,
445  const Vector3& offset = Vector3::ZERO);
446 
447 
463  void setLodBias(Real factor = 1.0);
464 
469  Real getLodBias(void) const;
470 
483  virtual void setLodCamera(const Camera* lodCam);
484 
491  virtual const Camera* getLodCamera() const;
492 
493 
498  Ray getCameraToViewportRay(Real screenx, Real screeny) const;
504  void getCameraToViewportRay(Real screenx, Real screeny, Ray* outRay) const;
505 
516  PlaneBoundedVolume getCameraToViewportBoxVolume(Real screenLeft,
517  Real screenTop, Real screenRight, Real screenBottom, bool includeFarPlane = false);
518 
530  void getCameraToViewportBoxVolume(Real screenLeft,
531  Real screenTop, Real screenRight, Real screenBottom,
532  PlaneBoundedVolume* outVolume, bool includeFarPlane = false);
533 
535  Real _getLodBiasInverse(void) const;
536 
537 
539  void _autoTrack(void);
540 
541 
551  virtual void setWindow (Real left, Real top, Real right, Real bottom);
553  virtual void resetWindow (void);
555  virtual bool isWindowSet(void) const { return mWindowSet; }
557  const vector<Plane>::type& getWindowPlanes(void) const;
558 
560  SceneNode* getAutoTrackTarget(void) const { return mAutoTrackTarget; }
562  const Vector3& getAutoTrackOffset(void) const { return mAutoTrackOffset; }
563 
569  Viewport* getLastViewport(void) const {return mLastViewport;}
571  void _notifyViewport(Viewport* viewport) {mLastViewport = viewport;}
572 
580  void setAutoAspectRatio(bool autoratio);
581 
584  bool getAutoAspectRatio(void) const;
585 
597  void setCullingFrustum(Frustum* frustum) { mCullFrustum = frustum; }
599  Frustum* getCullingFrustum(void) const { return mCullFrustum; }
600 
605  virtual void forwardIntersect(const Plane& worldPlane, vector<Vector4>::type* intersect3d) const;
606 
608  bool isVisible(const AxisAlignedBox& bound, FrustumPlane* culledBy = 0) const;
610  bool isVisible(const Sphere& bound, FrustumPlane* culledBy = 0) const;
612  bool isVisible(const Vector3& vert, FrustumPlane* culledBy = 0) const;
614  const Vector3* getWorldSpaceCorners(void) const;
616  const Plane& getFrustumPlane( unsigned short plane ) const;
618  bool projectSphere(const Sphere& sphere,
619  Real* left, Real* top, Real* right, Real* bottom) const;
621  Real getNearClipDistance(void) const;
623  Real getFarClipDistance(void) const;
625  const Matrix4& getViewMatrix(void) const;
634  const Matrix4& getViewMatrix(bool ownFrustumOnly) const;
640  virtual void setUseRenderingDistance(bool use) { mUseRenderingDistance = use; }
644  virtual bool getUseRenderingDistance(void) const { return mUseRenderingDistance; }
645 
652  virtual void synchroniseBaseSettingsWith(const Camera* cam);
653 
655  const Vector3& getPositionForViewUpdate(void) const;
657  const Quaternion& getOrientationForViewUpdate(void) const;
658 
663  void setUseMinPixelSize(bool enable) { mUseMinPixelSize = enable; }
667  bool getUseMinPixelSize() const { return mUseMinPixelSize; }
668 
679  Real getPixelDisplayRatio() const { return mPixelDisplayRatio; }
680 
685  void _resetRenderedRqs( size_t numRqs );
686 
697  void _setRenderedRqs( size_t rqStart, size_t rqEnd );
698 
700  bool isRenderedRq( size_t rqId ) const { return mRenderedRqs[rqId]; }
701 
702  };
706 } // namespace Ogre
707 
708 #include "OgreHeaderSuffix.h"
709 
710 #endif // __Camera_H__
Representation of a ray in space, i.e.
Definition: OgreRay.h:45
unsigned char uint8
Definition: OgrePlatform.h:422
A viewpoint from which the scene will be rendered.
Definition: OgreCamera.h:82
Class encapsulating a standard 4x4 homogeneous matrix.
Definition: OgreMatrix4.h:79
bool isRenderedRq(size_t rqId) const
Returns true if the asked render queue has been rendered. False otherwise.
Definition: OgreCamera.h:700
float Real
Software floating point type.
#define _OgreExport
Definition: OgrePlatform.h:255
Vector3 mAutoTrackOffset
Tracking offset for fine tuning.
Definition: OgreCamera.h:144
ListenerList mListeners
Definition: OgreCamera.h:184
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:679
vector< bool >::type mRenderedRqs
Each frame it is set to all false. After rendering each RQ, it is set to true.
Definition: OgreCamera.h:181
Frustum * getCullingFrustum(void) const
Returns the custom culling frustum in use.
Definition: OgreCamera.h:599
A frustum represents a pyramid, capped at the near and far end which is used to represent either a vi...
Definition: OgreFrustum.h:84
Manages the organisation and rendering of a 'scene' i.e.
static const Vector3 ZERO
Definition: OgreVector3.h:807
Viewport * getLastViewport(void) const
Get the last viewport which was attached to this camera.
Definition: OgreCamera.h:569
Vector3 mDerivedPosition
Definition: OgreCamera.h:118
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:640
Real mPixelDisplayRatio
Definition: OgreCamera.h:178
Wrap-around class that contains multiple ArrayMemoryManager, one per render queue.
Class representing a node in the scene graph.
Definition: OgreSceneNode.h:53
bool mYawFixed
Whether to yaw around a fixed axis.
Definition: OgreCamera.h:125
Quaternion mRealOrientation
Real world orientation/position of the camera.
Definition: OgreCamera.h:121
unsigned int mVisBatchesLastRender
Stored number of visible batches in the last render.
Definition: OgreCamera.h:136
Implementation of a Quaternion, i.e.
bool mWindowSet
Is viewing window used.
Definition: OgreCamera.h:157
bool mRecalcWindow
Was viewing window changed.
Definition: OgreCamera.h:161
Vector3 mPosition
Camera position - default (0,0,0)
Definition: OgreCamera.h:114
Quaternion mOrientation
Camera orientation, quaternion style.
Definition: OgreCamera.h:111
Real mSceneLodFactor
Scene LOD factor used to adjust overall LOD.
Definition: OgreCamera.h:147
SceneNode * mAutoTrackTarget
SceneNode which this Camera will automatically track.
Definition: OgreCamera.h:142
const Vector3 & _getCachedDerivedPosition(void) const
Same as getDerivedPosition, but doesn't check if dirty.
Definition: OgreCamera.h:401
virtual void cameraPreRenderScene(Camera *cam)
Called prior to the scene being rendered with this camera.
Definition: OgreCamera.h:94
Ogre::uint32 IdType
Big projects with lots, lots of units for very long periods of time (MMORPGs?) may want to define thi...
Definition: OgreId.h:36
SceneManager * mSceneMgr
Scene manager responsible for the scene.
Definition: OgreCamera.h:108
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:571
vector< Listener * >::type ListenerList
Definition: OgreCamera.h:183
bool mAutoAspectRatio
Whether aspect ratio will automatically be recalculated when a viewport changes its size...
Definition: OgreCamera.h:167
Standard 3-dimensional vector.
Definition: OgreVector3.h:50
virtual bool isWindowSet(void) const
Returns if a viewport window is being used.
Definition: OgreCamera.h:555
std::ostream & operator<<(std::ostream &o, const TRect< T > &r)
Definition: OgreCommon.h:666
Represents a convex volume bounded by planes.
const Camera * mLodCamera
Camera to use for LOD calculation.
Definition: OgreCamera.h:173
Vector3 mYawFixedAxis
Fixed axis to yaw around.
Definition: OgreCamera.h:127
virtual void cameraDestroyed(Camera *cam)
Called when the camera is being destroyed.
Definition: OgreCamera.h:102
An abstraction of a viewport, i.e.
Definition: OgreViewport.h:56
bool getUseMinPixelSize() const
Returns whether to use min display size calculations.
Definition: OgreCamera.h:667
Real mSceneLodFactorInv
Inverted scene LOD factor, can be used by Renderables to adjust their LOD.
Definition: OgreCamera.h:149
unsigned int mVisFacesLastRender
Stored number of visible faces in the last render.
Definition: OgreCamera.h:133
virtual bool getUseRenderingDistance(void) const
Get whether this camera should use the 'rendering distance' on objects to exclude distant objects fro...
Definition: OgreCamera.h:644
Wrapper class which indicates a given angle value is in Radians.
Definition: OgreMath.h:49
PolygonMode
The polygon mode to use when rasterising.
Definition: OgreCommon.h:210
Frustum * mCullFrustum
Custom culling frustum.
Definition: OgreCamera.h:169
static String msMovableType
Shared class-level name for Movable type.
Definition: OgreCamera.h:139
static const Vector3 UNIT_Y
Definition: OgreVector3.h:809
SceneNode * getAutoTrackTarget(void) const
Get the auto tracking target for this camera, if any.
Definition: OgreCamera.h:560
FrustumPlane
Worldspace clipping planes.
Definition: OgreFrustum.h:70
_StringBase String
Definition: OgreCommon.h:53
bool mUseMinPixelSize
Whether or not the minimum display size of objects should take effect for this camera.
Definition: OgreCamera.h:176
Vector3 mRealPosition
Definition: OgreCamera.h:122
void setCullingFrustum(Frustum *frustum)
Tells the camera to use a separate Frustum instance to perform culling.
Definition: OgreCamera.h:597
PolygonMode mSceneDetail
Rendering type.
Definition: OgreCamera.h:130
Quaternion mDerivedOrientation
Derived orientation/position of the camera, including reflection.
Definition: OgreCamera.h:117
Listener interface so you can be notified of Camera events.
Definition: OgreCamera.h:87
virtual void cameraPostRenderScene(Camera *cam)
Called after the scene has been rendered with this camera.
Definition: OgreCamera.h:98
const Vector3 & getAutoTrackOffset(void) const
Get the auto tracking offset for this camera, if it is auto tracking.
Definition: OgreCamera.h:562
Viewport * mLastViewport
The last viewport to be added using this camera.
Definition: OgreCamera.h:163
void setUseMinPixelSize(bool enable)
Sets whether to use min display size calculations.
Definition: OgreCamera.h:663
bool mUseRenderingDistance
Whether or not the rendering distance of objects should take effect for this camera.
Definition: OgreCamera.h:171
vector< Plane >::type mWindowClipPlanes
Windowed viewport clip planes.
Definition: OgreCamera.h:159