OGRE  1.7
Object-Oriented Graphics Rendering Engine
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator 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-2011 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 
47 
48 namespace Ogre {
49 
85  class _OgreExport Camera : public Frustum
86  {
87  public:
91  {
92  public:
93  Listener() {}
94  virtual ~Listener() {}
95 
97  virtual void cameraPreRenderScene(Camera* cam)
98  { (void)cam; }
99 
101  virtual void cameraPostRenderScene(Camera* cam)
102  { (void)cam; }
103 
105  virtual void cameraDestroyed(Camera* cam)
106  { (void)cam; }
107 
108  };
109  protected:
112 
115 
118 
122 
126 
128  bool mYawFixed;
131 
134 
136  unsigned int mVisFacesLastRender;
137 
139  unsigned int mVisBatchesLastRender;
140 
143 
148 
149  // Scene LOD factor used to adjust overall LOD
153 
154 
159  Real mWLeft, mWTop, mWRight, mWBottom;
164  // Was viewing window changed.
165  mutable bool mRecalcWindow;
178 
181 
182 
183  // Internal functions for calcs
184  bool isViewOutOfDate(void) const;
186  void invalidateFrustum(void) const;
188  void invalidateView(void) const;
189 
190 
195  virtual void setWindowImpl(void) const;
196 
198  virtual vector<Vector4>::type getRayForwardIntersect(const Vector3& anchor, const Vector3 *dir, Real planeOffset) const;
199 
200  public:
203  Camera( const String& name, SceneManager* sm);
204 
207  virtual ~Camera();
208 
210  virtual void addListener(Listener* l);
212  virtual void removeListener(Listener* l);
213 
216  SceneManager* getSceneManager(void) const;
217 
225  void setPolygonMode(PolygonMode sd);
226 
229  PolygonMode getPolygonMode(void) const;
230 
233  void setPosition(Real x, Real y, Real z);
234 
237  void setPosition(const Vector3& vec);
238 
241  const Vector3& getPosition(void) const;
242 
245  void move(const Vector3& vec);
246 
249  void moveRelative(const Vector3& vec);
250 
256  void setDirection(Real x, Real y, Real z);
257 
260  void setDirection(const Vector3& vec);
261 
262  /* Gets the camera's direction.
263  */
264  Vector3 getDirection(void) const;
265 
268  Vector3 getUp(void) const;
269 
272  Vector3 getRight(void) const;
273 
282  void lookAt( const Vector3& targetPoint );
295  void lookAt(Real x, Real y, Real z);
296 
299  void roll(const Radian& angle);
300 
303  void yaw(const Radian& angle);
304 
307  void pitch(const Radian& angle);
308 
311  void rotate(const Vector3& axis, const Radian& angle);
312 
315  void rotate(const Quaternion& q);
316 
336  void setFixedYawAxis( bool useFixed, const Vector3& fixedAxis = Vector3::UNIT_Y );
337 
338 
341  const Quaternion& getOrientation(void) const;
342 
345  void setOrientation(const Quaternion& q);
346 
351  void _renderScene(Viewport *vp, bool includeOverlays);
352 
355  _OgreExport friend std::ostream& operator<<(std::ostream& o, const Camera& c);
356 
359  void _notifyRenderedFaces(unsigned int numfaces);
360 
363  void _notifyRenderedBatches(unsigned int numbatches);
364 
367  unsigned int _getNumRenderedFaces(void) const;
368 
371  unsigned int _getNumRenderedBatches(void) const;
372 
375  const Quaternion& getDerivedOrientation(void) const;
378  const Vector3& getDerivedPosition(void) const;
381  Vector3 getDerivedDirection(void) const;
384  Vector3 getDerivedUp(void) const;
387  Vector3 getDerivedRight(void) const;
388 
391  const Quaternion& getRealOrientation(void) const;
394  const Vector3& getRealPosition(void) const;
397  Vector3 getRealDirection(void) const;
400  Vector3 getRealUp(void) const;
403  Vector3 getRealRight(void) const;
404 
406  const String& getMovableType(void) const;
407 
427  void setAutoTracking(bool enabled, SceneNode* target = 0,
428  const Vector3& offset = Vector3::ZERO);
429 
430 
446  void setLodBias(Real factor = 1.0);
447 
452  Real getLodBias(void) const;
453 
466  virtual void setLodCamera(const Camera* lodCam);
467 
474  virtual const Camera* getLodCamera() const;
475 
476 
481  Ray getCameraToViewportRay(Real screenx, Real screeny) const;
487  void getCameraToViewportRay(Real screenx, Real screeny, Ray* outRay) const;
488 
499  PlaneBoundedVolume getCameraToViewportBoxVolume(Real screenLeft,
500  Real screenTop, Real screenRight, Real screenBottom, bool includeFarPlane = false);
501 
513  void getCameraToViewportBoxVolume(Real screenLeft,
514  Real screenTop, Real screenRight, Real screenBottom,
515  PlaneBoundedVolume* outVolume, bool includeFarPlane = false);
516 
518  Real _getLodBiasInverse(void) const;
519 
520 
522  void _autoTrack(void);
523 
524 
534  virtual void setWindow (Real Left, Real Top, Real Right, Real Bottom);
536  virtual void resetWindow (void);
538  virtual bool isWindowSet(void) const { return mWindowSet; }
540  const vector<Plane>::type& getWindowPlanes(void) const;
541 
543  Real getBoundingRadius(void) const;
545  SceneNode* getAutoTrackTarget(void) const { return mAutoTrackTarget; }
547  const Vector3& getAutoTrackOffset(void) const { return mAutoTrackOffset; }
548 
554  Viewport* getViewport(void) const {return mLastViewport;}
556  void _notifyViewport(Viewport* viewport) {mLastViewport = viewport;}
557 
565  void setAutoAspectRatio(bool autoratio);
566 
569  bool getAutoAspectRatio(void) const;
570 
582  void setCullingFrustum(Frustum* frustum) { mCullFrustum = frustum; }
584  Frustum* getCullingFrustum(void) const { return mCullFrustum; }
585 
590  virtual void forwardIntersect(const Plane& worldPlane, vector<Vector4>::type* intersect3d) const;
591 
593  bool isVisible(const AxisAlignedBox& bound, FrustumPlane* culledBy = 0) const;
595  bool isVisible(const Sphere& bound, FrustumPlane* culledBy = 0) const;
597  bool isVisible(const Vector3& vert, FrustumPlane* culledBy = 0) const;
599  const Vector3* getWorldSpaceCorners(void) const;
601  const Plane& getFrustumPlane( unsigned short plane ) const;
603  bool projectSphere(const Sphere& sphere,
604  Real* left, Real* top, Real* right, Real* bottom) const;
606  Real getNearClipDistance(void) const;
608  Real getFarClipDistance(void) const;
610  const Matrix4& getViewMatrix(void) const;
619  const Matrix4& getViewMatrix(bool ownFrustumOnly) const;
625  virtual void setUseRenderingDistance(bool use) { mUseRenderingDistance = use; }
629  virtual bool getUseRenderingDistance(void) const { return mUseRenderingDistance; }
630 
637  virtual void synchroniseBaseSettingsWith(const Camera* cam);
638 
640  const Vector3& getPositionForViewUpdate(void) const;
642  const Quaternion& getOrientationForViewUpdate(void) const;
643  };
647 } // namespace Ogre
648 #endif
Representation of a ray in space, i.e.
Definition: OgreRay.h:46
A viewpoint from which the scene will be rendered.
Definition: OgreCamera.h:85
Class encapsulating a standard 4x4 homogeneous matrix.
Definition: OgreMatrix4.h:78
float Real
Software floating point type.
#define _OgreExport
Definition: OgrePlatform.h:203
Vector3 mAutoTrackOffset
Tracking offset for fine tuning.
Definition: OgreCamera.h:147
std::vector< T, A > type
ListenerList mListeners
Definition: OgreCamera.h:180
Defines a plane in 3D space.
Definition: OgrePlane.h:61
Frustum * getCullingFrustum(void) const
Returns the custom culling frustum in use.
Definition: OgreCamera.h:584
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:774
Viewport * getViewport(void) const
Get the last viewport which was attached to this camera.
Definition: OgreCamera.h:554
Vector3 mDerivedPosition
Definition: OgreCamera.h:121
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:625
Class representing a node in the scene graph.
Definition: OgreSceneNode.h:57
bool mYawFixed
Whether to yaw around a fixed axis.
Definition: OgreCamera.h:128
Quaternion mRealOrientation
Real world orientation/position of the camera.
Definition: OgreCamera.h:124
unsigned int mVisBatchesLastRender
Stored number of visible faces in the last render.
Definition: OgreCamera.h:139
Implementation of a Quaternion, i.e.
bool mWindowSet
Is viewing window used.
Definition: OgreCamera.h:161
bool mRecalcWindow
Definition: OgreCamera.h:165
Vector3 mPosition
Camera position - default (0,0,0)
Definition: OgreCamera.h:117
Quaternion mOrientation
Camera orientation, quaternion style.
Definition: OgreCamera.h:114
Real mSceneLodFactor
Definition: OgreCamera.h:150
SceneNode * mAutoTrackTarget
SceneNode which this Camera will automatically track.
Definition: OgreCamera.h:145
virtual void cameraPreRenderScene(Camera *cam)
Called prior to the scene being rendered with this camera.
Definition: OgreCamera.h:97
SceneManager * mSceneMgr
Scene manager responsible for the scene.
Definition: OgreCamera.h:111
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:556
vector< Listener * >::type ListenerList
Definition: OgreCamera.h:179
bool mAutoAspectRatio
Whether aspect ratio will automatically be recalculated when a viewport changes its size...
Definition: OgreCamera.h:171
Standard 3-dimensional vector.
Definition: OgreVector3.h:51
virtual bool isWindowSet(void) const
Returns if a viewport window is being used.
Definition: OgreCamera.h:538
std::ostream & operator<<(std::ostream &o, const TRect< T > &r)
Definition: OgreCommon.h:610
Represents a convex volume bounded by planes.
const Camera * mLodCamera
Camera to use for LOD calculation.
Definition: OgreCamera.h:177
Vector3 mYawFixedAxis
Fixed axis to yaw around.
Definition: OgreCamera.h:130
virtual void cameraDestroyed(Camera *cam)
Called when the camera is being destroyed.
Definition: OgreCamera.h:105
An abstraction of a viewport, i.e.
Definition: OgreViewport.h:56
Real mSceneLodFactorInv
Inverted scene LOD factor, can be used by Renderables to adjust their LOD.
Definition: OgreCamera.h:152
unsigned int mVisFacesLastRender
Stored number of visible faces in the last render.
Definition: OgreCamera.h:136
virtual bool getUseRenderingDistance(void) const
Get whether this camera should use the 'rendering distance' on objects to exclude distant objects fro...
Definition: OgreCamera.h:629
Wrapper class which indicates a given angle value is in Radians.
Definition: OgreMath.h:46
PolygonMode
The polygon mode to use when rasterising.
Definition: OgreCommon.h:180
Frustum * mCullFrustum
Custom culling frustum.
Definition: OgreCamera.h:173
static String msMovableType
Shared class-level name for Movable type.
Definition: OgreCamera.h:142
static const Vector3 UNIT_Y
Definition: OgreVector3.h:776
SceneNode * getAutoTrackTarget(void) const
Get the auto tracking target for this camera, if any.
Definition: OgreCamera.h:545
FrustumPlane
Worldspace clipping planes.
Definition: OgreFrustum.h:70
_StringBase String
Vector3 mRealPosition
Definition: OgreCamera.h:125
void setCullingFrustum(Frustum *frustum)
Tells the camera to use a separate Frustum instance to perform culling.
Definition: OgreCamera.h:582
PolygonMode mSceneDetail
Rendering type.
Definition: OgreCamera.h:133
Quaternion mDerivedOrientation
Derived orientation/position of the camera, including reflection.
Definition: OgreCamera.h:120
Listener interface so you can be notified of Camera events.
Definition: OgreCamera.h:90
virtual void cameraPostRenderScene(Camera *cam)
Called after the scene has been rendered with this camera.
Definition: OgreCamera.h:101
const Vector3 & getAutoTrackOffset(void) const
Get the auto tracking offset for this camera, if it is auto tracking.
Definition: OgreCamera.h:547
Viewport * mLastViewport
The last viewport to be added using this camera.
Definition: OgreCamera.h:167
bool mUseRenderingDistance
Whether or not the rendering distance of objects should take effect for this camera.
Definition: OgreCamera.h:175
vector< Plane >::type mWindowClipPlanes
Windowed viewport clip planes.
Definition: OgreCamera.h:163