OGRE  2.0
Object-Oriented Graphics Rendering Engine
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
OgreFrustum.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 __Frustum_H__
29 #define __Frustum_H__
30 
31 #include "OgrePrerequisites.h"
32 #include "OgreMovableObject.h"
33 #include "OgreRenderable.h"
34 #include "OgreAxisAlignedBox.h"
35 #include "OgreVertexIndexData.h"
36 #include "OgreHeaderPrefix.h"
37 
38 namespace Ogre
39 {
49  {
54 
58  };
59 
63  {
66  };
67 
71  {
78  };
79 
85  {
86  protected:
89 
104 
106  mutable Plane mFrustumPlanes[6];
107 
111 
121  mutable bool mRecalcFrustum;
123  mutable bool mRecalcView;
125  mutable bool mRecalcFrustumPlanes;
129  mutable bool mRecalcVertexData;
137  mutable Real mLeft, mRight, mTop, mBottom;
140 
141  // Internal functions for calcs
142  virtual void calcProjectionParameters(Real& left, Real& right, Real& bottom, Real& top) const;
144  virtual void updateFrustum(void) const;
146  virtual void updateView(void) const;
148  virtual void updateFrustumImpl(void) const;
150  virtual void updateViewImpl(void) const;
151  virtual void updateFrustumPlanes(void) const;
153  virtual void updateFrustumPlanesImpl(void) const;
154  virtual void updateWorldSpaceCorners(void) const;
156  virtual void updateWorldSpaceCornersImpl(void) const;
157  virtual void updateVertexData(void) const;
158  virtual bool isViewOutOfDate(void) const;
159  virtual bool isFrustumOutOfDate(void) const;
161  virtual void invalidateFrustum(void) const;
163  virtual void invalidateView(void) const;
164 
167 
170 
172  mutable Vector3 mWorldSpaceCorners[8];
173 
175  bool mReflect;
184 
193 
194  public:
195 
197  Frustum( IdType id, ObjectMemoryManager *objectMemoryManager );
198 
199  virtual ~Frustum();
212  virtual void setFOVy(const Radian& fovy);
213 
216  virtual const Radian& getFOVy(void) const;
217 
229  virtual void setNearClipDistance(Real nearDist);
230 
233  virtual Real getNearClipDistance(void) const;
234 
255  virtual void setFarClipDistance(Real farDist);
256 
259  virtual Real getFarClipDistance(void) const;
260 
269  virtual void setAspectRatio(Real ratio);
270 
273  virtual Real getAspectRatio(void) const;
274 
286  virtual void setFrustumOffset(const Vector2& offset);
287 
301  virtual void setFrustumOffset(Real horizontal = 0.0, Real vertical = 0.0);
302 
305  virtual const Vector2& getFrustumOffset() const;
306 
311  virtual void setFocalLength(Real focalLength = 1.0);
312 
315  virtual Real getFocalLength() const;
316 
321  virtual void setFrustumExtents(Real left, Real right, Real top, Real bottom);
323  virtual void resetFrustumExtents();
325  virtual void getFrustumExtents(Real& outleft, Real& outright, Real& outtop, Real& outbottom) const;
326 
327 
336  virtual const Matrix4& getProjectionMatrixRS(void) const;
348  virtual const Matrix4& getProjectionMatrixWithRSDepth(void) const;
358  virtual const Matrix4& getProjectionMatrix(void) const;
359 
362  virtual const Matrix4& getViewMatrix(void) const;
363 
368  virtual void calcViewMatrixRelative(const Vector3& relPos, Matrix4& matToUpdate) const;
369 
387  virtual void setCustomViewMatrix(bool enable,
388  const Matrix4& viewMatrix = Matrix4::IDENTITY);
390  virtual bool isCustomViewMatrixEnabled(void) const
391  { return mCustomViewMatrix; }
392 
414  virtual void setCustomProjectionMatrix(bool enable,
415  const Matrix4& projectionMatrix = Matrix4::IDENTITY);
417  virtual bool isCustomProjectionMatrixEnabled(void) const
418  { return mCustomProjMatrix; }
419 
424  virtual const Plane* getFrustumPlanes(void) const;
425 
427  const Plane* _getCachedFrustumPlanes(void) const { return mFrustumPlanes; }
428 
433  virtual const Plane& getFrustumPlane( unsigned short plane ) const;
434 
446  virtual bool isVisible(const AxisAlignedBox& bound, FrustumPlane* culledBy = 0) const;
447 
459  virtual bool isVisible(const Sphere& bound, FrustumPlane* culledBy = 0) const;
460 
472  virtual bool isVisible(const Vector3& vert, FrustumPlane* culledBy = 0) const;
473 
475  const AxisAlignedBox& getBoundingBox(void) const;
476 
478  void _updateRenderQueue(RenderQueue* queue, Camera *camera, const Camera *lodCamera);
479 
481  const String& getMovableType(void) const;
482 
484  void _notifyCurrentCamera(Camera* cam);
485 
487  const MaterialPtr& getMaterial(void) const;
488 
490  void getRenderOperation(RenderOperation& op);
491 
493  void getWorldTransforms(Matrix4* xform) const;
494 
496  Real getSquaredViewDepth(const Camera* cam) const;
497 
499  const LightList& getLights(void) const;
500 
501  void getCustomWorldSpaceCorners(
502  ArrayVector3 outCorners[(8 + ARRAY_PACKED_REALS - 1) / ARRAY_PACKED_REALS],
503  Real customFarPlane ) const;
504 
511  virtual const Vector3* getWorldSpaceCorners(void) const;
512 
515  virtual void setProjectionType(ProjectionType pt);
516 
519  virtual ProjectionType getProjectionType(void) const;
520 
531  virtual void setOrthoWindow(Real w, Real h);
537  virtual void setOrthoWindowHeight(Real h);
543  virtual void setOrthoWindowWidth(Real w);
546  virtual Real getOrthoWindowHeight() const;
550  virtual Real getOrthoWindowWidth() const;
551 
557  virtual void enableReflection(const Plane& p);
566  virtual void enableReflection(const MovablePlane* p);
567 
569  virtual void disableReflection(void);
570 
572  virtual bool isReflected(void) const { return mReflect; }
574  virtual const Matrix4& getReflectionMatrix(void) const { return mReflectMatrix; }
576  virtual const Plane& getReflectionPlane(void) const { return mReflectPlane; }
577 
595  virtual bool projectSphere(const Sphere& sphere,
596  Real* left, Real* top, Real* right, Real* bottom) const;
597 
598 
625  virtual void enableCustomNearClipPlane(const MovablePlane* plane);
647  virtual void enableCustomNearClipPlane(const Plane& plane);
649  virtual void disableCustomNearClipPlane(void);
651  virtual bool isCustomNearClipPlaneEnabled(void) const
652  { return mObliqueDepthProjection; }
653 
655  void visitRenderables(Renderable::Visitor* visitor,
656  bool debugRenderables = false);
657 
660 
662  virtual const Vector3& getPositionForViewUpdate(void) const;
664  virtual const Quaternion& getOrientationForViewUpdate(void) const;
665 
668  PlaneBoundedVolume getPlaneBoundedVolume();
674  void setOrientationMode(OrientationMode orientationMode);
675 
681  OrientationMode getOrientationMode() const;
682 
683  };
684 
688 } // namespace Ogre
689 
690 #include "OgreHeaderSuffix.h"
691 
692 #endif // __Frustum_H__
const Plane * _getCachedFrustumPlanes(void) const
Returns the frustum planes, doesn't check if dirty.
Definition: OgreFrustum.h:427
virtual bool isCustomViewMatrixEnabled(void) const
Returns whether a custom view matrix is in use.
Definition: OgreFrustum.h:390
A viewpoint from which the scene will be rendered.
Definition: OgreCamera.h:82
virtual const Plane & getReflectionPlane(void) const
Returns the reflection plane of the frustum if appropriate.
Definition: OgreFrustum.h:576
Class encapsulating a standard 4x4 homogeneous matrix.
Definition: OgreMatrix4.h:79
MaterialPtr mMaterial
Definition: OgreFrustum.h:171
Matrix4 mViewMatrix
Pre-calced view matrix.
Definition: OgreFrustum.h:119
AxisAlignedBox mBoundingBox
Definition: OgreFrustum.h:168
float Real
Software floating point type.
const MovablePlane * mLinkedObliqueProjPlane
Pointer to oblique projection plane (automatically updated)
Definition: OgreFrustum.h:190
#define _OgreExport
Definition: OgrePlatform.h:255
Matrix4 mProjMatrixRS
Pre-calced projection matrix for the specific render system.
Definition: OgreFrustum.h:113
OrientationMode mOrientationMode
Frustum orientation mode.
Definition: OgreFrustum.h:139
Defines a plane in 3D space.
Definition: OgrePlane.h:61
Vector2 mFrustumOffset
Off-axis frustum center offset - default (0.0, 0.0)
Definition: OgreFrustum.h:101
Real mFarDist
Far clip distance - default 10000.
Definition: OgreFrustum.h:93
const MovablePlane * mLinkedReflectPlane
Pointer to a reflection plane (automatically updated)
Definition: OgreFrustum.h:181
ProjectionType mProjType
Orthographic or perspective?
Definition: OgreFrustum.h:88
Vector3 mLastParentPosition
Definition: OgreFrustum.h:110
A frustum represents a pyramid, capped at the near and far end which is used to represent either a vi...
Definition: OgreFrustum.h:84
static const Matrix4 IDENTITY
Definition: OgreMatrix4.h:556
Radian mFOVy
y-direction field-of-view (default 45)
Definition: OgreFrustum.h:91
virtual bool isReflected(void) const
Returns whether this frustum is being reflected.
Definition: OgreFrustum.h:572
A 3D box aligned with the x/y/z axes.
Quaternion mLastParentOrientation
Stored versions of parent orientation / position.
Definition: OgreFrustum.h:109
VertexData mVertexData
Definition: OgreFrustum.h:169
bool mCustomProjMatrix
Are we using a custom projection matrix?
Definition: OgreFrustum.h:133
Real mNearDist
Near clip distance - default 100.
Definition: OgreFrustum.h:95
Plane mObliqueProjPlane
Fixed oblique projection plane.
Definition: OgreFrustum.h:188
Wrap-around class that contains multiple ArrayMemoryManager, one per render queue.
Abstract class defining a movable object in a scene.
bool mRecalcWorldSpaceCorners
Something re the world space corners has changed.
Definition: OgreFrustum.h:127
Abstract class defining the interface all renderable objects must implement.
Implementation of a Quaternion, i.e.
virtual const Matrix4 & getReflectionMatrix(void) const
Returns the reflection matrix of the frustum if appropriate.
Definition: OgreFrustum.h:574
bool mRecalcFrustum
Something's changed in the frustum shape?
Definition: OgreFrustum.h:121
static String msMovableType
Shared class-level name for Movable type.
Definition: OgreFrustum.h:166
Cache-friendly array of 3-dimensional represented as a SoA array.
OrientationMode
Specifies orientation mode.
Definition: OgreFrustum.h:48
ProjectionType
Specifies perspective (realistic) or orthographic (architectural) projection.
Definition: OgreFrustum.h:62
Matrix4 mReflectMatrix
Derived reflection matrix.
Definition: OgreFrustum.h:177
Matrix4 mProjMatrixRSDepth
Pre-calced standard projection matrix but with render system depth range.
Definition: OgreFrustum.h:115
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
Real mOrthoHeight
Ortho height size (world units)
Definition: OgreFrustum.h:99
A sphere primitive, mostly used for bounds checking.
Definition: OgreSphere.h:51
Standard 2-dimensional vector.
Definition: OgreVector2.h:51
bool mRecalcVertexData
Something re the vertex data has changed.
Definition: OgreFrustum.h:129
Plane mLastLinkedObliqueProjPlane
Record of the last world-space oblique depth projection plane info used.
Definition: OgreFrustum.h:192
bool mReflect
Is this frustum to act as a reflection of itself?
Definition: OgreFrustum.h:175
Visitor object that can be used to iterate over a collection of Renderable instances abstractly...
Plane mReflectPlane
Fixed reflection plane.
Definition: OgreFrustum.h:179
Definition of a Plane that may be attached to a node, and the derived details of it retrieved simply...
#define ARRAY_PACKED_REALS
Standard 3-dimensional vector.
Definition: OgreVector3.h:50
virtual bool isCustomProjectionMatrixEnabled(void) const
Returns whether a custom projection matrix is in use.
Definition: OgreFrustum.h:417
Represents a convex volume bounded by planes.
Summary class collecting together vertex source information.
bool mRecalcView
Something re the view pos has changed.
Definition: OgreFrustum.h:123
'New' rendering operation using vertex buffers.
Real mAspect
x/y viewport ratio - default 1.3333
Definition: OgreFrustum.h:97
virtual bool isCustomNearClipPlaneEnabled(void) const
Is a custom near clip plane in use?
Definition: OgreFrustum.h:651
Wrapper class which indicates a given angle value is in Radians.
Definition: OgreMath.h:49
static const Real INFINITE_FAR_PLANE_ADJUST
Small constant used to reduce far plane projection to avoid inaccuracies.
Definition: OgreFrustum.h:659
Class to manage the scene object rendering queue.
bool mRecalcFrustumPlanes
Something re the frustum planes has changed.
Definition: OgreFrustum.h:125
FrustumPlane
Worldspace clipping planes.
Definition: OgreFrustum.h:70
_StringBase String
Definition: OgreCommon.h:53
bool mFrustumExtentsManuallySet
Have the frustum extents been manually set?
Definition: OgreFrustum.h:135
Plane mLastLinkedReflectionPlane
Record of the last world-space reflection plane info used.
Definition: OgreFrustum.h:183
bool mObliqueDepthProjection
Is this frustum using an oblique depth projection?
Definition: OgreFrustum.h:186
Real mFocalLength
Focal length of frustum (for stereo rendering, defaults to 1.0)
Definition: OgreFrustum.h:103
Matrix4 mProjMatrix
Pre-calced standard projection matrix.
Definition: OgreFrustum.h:117
bool mCustomViewMatrix
Are we using a custom view matrix?
Definition: OgreFrustum.h:131