OgreFrustum.h

Go to the documentation of this file.
00001 /*
00002 -----------------------------------------------------------------------------
00003 This source file is part of OGRE
00004     (Object-oriented Graphics Rendering Engine)
00005 For the latest info, see http://www.ogre3d.org/
00006 
00007 Copyright (c) 2000-2009 Torus Knot Software Ltd
00008 
00009 Permission is hereby granted, free of charge, to any person obtaining a copy
00010 of this software and associated documentation files (the "Software"), to deal
00011 in the Software without restriction, including without limitation the rights
00012 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
00013 copies of the Software, and to permit persons to whom the Software is
00014 furnished to do so, subject to the following conditions:
00015 
00016 The above copyright notice and this permission notice shall be included in
00017 all copies or substantial portions of the Software.
00018 
00019 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00020 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00021 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
00022 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00023 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00024 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
00025 THE SOFTWARE.
00026 -----------------------------------------------------------------------------
00027 */
00028 #ifndef __Frustum_H__
00029 #define __Frustum_H__
00030 
00031 #include "OgrePrerequisites.h"
00032 #include "OgreMovableObject.h"
00033 #include "OgreRenderable.h"
00034 #include "OgreAxisAlignedBox.h"
00035 #include "OgreVertexIndexData.h"
00036 #include "OgreMovablePlane.h"
00037 
00038 namespace Ogre
00039 {
00048     enum OrientationMode
00049     {
00050         OR_DEGREE_0       = 0,
00051         OR_DEGREE_90      = 1,
00052         OR_DEGREE_180     = 2,
00053         OR_DEGREE_270     = 3,
00054 
00055         OR_PORTRAIT       = OR_DEGREE_0,
00056         OR_LANDSCAPERIGHT = OR_DEGREE_90,
00057         OR_LANDSCAPELEFT  = OR_DEGREE_270
00058     };
00059 
00062     enum ProjectionType
00063     {
00064         PT_ORTHOGRAPHIC,
00065         PT_PERSPECTIVE
00066     };
00067 
00070     enum FrustumPlane
00071     {
00072         FRUSTUM_PLANE_NEAR   = 0,
00073         FRUSTUM_PLANE_FAR    = 1,
00074         FRUSTUM_PLANE_LEFT   = 2,
00075         FRUSTUM_PLANE_RIGHT  = 3,
00076         FRUSTUM_PLANE_TOP    = 4,
00077         FRUSTUM_PLANE_BOTTOM = 5
00078     };
00079 
00084     class _OgreExport Frustum : public MovableObject, public Renderable
00085     {
00086     protected:
00088         ProjectionType mProjType;
00089 
00091         Radian mFOVy;
00093         Real mFarDist;
00095         Real mNearDist;
00097         Real mAspect;
00099         Real mOrthoHeight;
00101         Vector2 mFrustumOffset;
00103         Real mFocalLength;
00104 
00106         mutable Plane mFrustumPlanes[6];
00107 
00109         mutable Quaternion mLastParentOrientation;
00110         mutable Vector3 mLastParentPosition;
00111 
00113         mutable Matrix4 mProjMatrixRS;
00115         mutable Matrix4 mProjMatrixRSDepth;
00117         mutable Matrix4 mProjMatrix;
00119         mutable Matrix4 mViewMatrix;
00121         mutable bool mRecalcFrustum;
00123         mutable bool mRecalcView;
00125         mutable bool mRecalcFrustumPlanes;
00127         mutable bool mRecalcWorldSpaceCorners;
00129         mutable bool mRecalcVertexData;
00131         bool mCustomViewMatrix;
00133         bool mCustomProjMatrix;
00135         bool mFrustumExtentsManuallySet;
00137         mutable Real mLeft, mRight, mTop, mBottom;
00139         mutable OrientationMode mOrientationMode;
00140         
00141         // Internal functions for calcs
00142         virtual void calcProjectionParameters(Real& left, Real& right, Real& bottom, Real& top) const;
00144         virtual void updateFrustum(void) const;
00146         virtual void updateView(void) const;
00148         virtual void updateFrustumImpl(void) const;
00150         virtual void updateViewImpl(void) const;
00151         virtual void updateFrustumPlanes(void) const;
00153         virtual void updateFrustumPlanesImpl(void) const;
00154         virtual void updateWorldSpaceCorners(void) const;
00156         virtual void updateWorldSpaceCornersImpl(void) const;
00157         virtual void updateVertexData(void) const;
00158         virtual bool isViewOutOfDate(void) const;
00159         virtual bool isFrustumOutOfDate(void) const;
00161         virtual void invalidateFrustum(void) const;
00163         virtual void invalidateView(void) const;
00164 
00166         static String msMovableType;
00167 
00168         mutable AxisAlignedBox mBoundingBox;
00169         mutable VertexData mVertexData;
00170 
00171         MaterialPtr mMaterial;
00172         mutable Vector3 mWorldSpaceCorners[8];
00173 
00175         bool mReflect;
00177         mutable Matrix4 mReflectMatrix;
00179         mutable Plane mReflectPlane;
00181         const MovablePlane* mLinkedReflectPlane;
00183         mutable Plane mLastLinkedReflectionPlane;
00184         
00186         bool mObliqueDepthProjection;
00188         mutable Plane mObliqueProjPlane;
00190         const MovablePlane* mLinkedObliqueProjPlane;
00192         mutable Plane mLastLinkedObliqueProjPlane;
00193 
00194     public:
00195 
00196         Frustum();
00197         virtual ~Frustum();
00210         virtual void setFOVy(const Radian& fovy);
00211 
00214         virtual const Radian& getFOVy(void) const;
00215 
00227         virtual void setNearClipDistance(Real nearDist);
00228 
00231         virtual Real getNearClipDistance(void) const;
00232 
00253         virtual void setFarClipDistance(Real farDist);
00254 
00257         virtual Real getFarClipDistance(void) const;
00258 
00267         virtual void setAspectRatio(Real ratio);
00268 
00271         virtual Real getAspectRatio(void) const;
00272 
00284         virtual void setFrustumOffset(const Vector2& offset);
00285 
00299         virtual void setFrustumOffset(Real horizontal = 0.0, Real vertical = 0.0);
00300 
00303         virtual const Vector2& getFrustumOffset() const;
00304 
00309         virtual void setFocalLength(Real focalLength = 1.0);
00310 
00313         virtual Real getFocalLength() const;
00314 
00319         virtual void setFrustumExtents(Real left, Real right, Real top, Real bottom);
00321         virtual void resetFrustumExtents(); 
00323         virtual void getFrustumExtents(Real& outleft, Real& outright, Real& outtop, Real& outbottom) const;
00324 
00325 
00335         virtual const Matrix4& getProjectionMatrixRS(void) const;
00347         virtual const Matrix4& getProjectionMatrixWithRSDepth(void) const;
00357         virtual const Matrix4& getProjectionMatrix(void) const;
00358 
00361         virtual const Matrix4& getViewMatrix(void) const;
00362 
00367         virtual void calcViewMatrixRelative(const Vector3& relPos, Matrix4& matToUpdate) const;
00368 
00386         virtual void setCustomViewMatrix(bool enable, 
00387             const Matrix4& viewMatrix = Matrix4::IDENTITY);
00389         virtual bool isCustomViewMatrixEnabled(void) const 
00390         { return mCustomViewMatrix; }
00391         
00411         virtual void setCustomProjectionMatrix(bool enable, 
00412             const Matrix4& projectionMatrix = Matrix4::IDENTITY);
00414         virtual bool isCustomProjectionMatrixEnabled(void) const
00415         { return mCustomProjMatrix; }
00416 
00421         virtual const Plane* getFrustumPlanes(void) const;
00422 
00427         virtual const Plane& getFrustumPlane( unsigned short plane ) const;
00428 
00440         virtual bool isVisible(const AxisAlignedBox& bound, FrustumPlane* culledBy = 0) const;
00441 
00453         virtual bool isVisible(const Sphere& bound, FrustumPlane* culledBy = 0) const;
00454 
00466         virtual bool isVisible(const Vector3& vert, FrustumPlane* culledBy = 0) const;
00467 
00469         uint32 getTypeFlags(void) const;
00470 
00472         const AxisAlignedBox& getBoundingBox(void) const;
00473 
00475         Real getBoundingRadius(void) const;
00476 
00478         void _updateRenderQueue(RenderQueue* queue);
00479 
00481         const String& getMovableType(void) const;
00482 
00484         void _notifyCurrentCamera(Camera* cam);
00485 
00487         const MaterialPtr& getMaterial(void) const;
00488 
00490         void getRenderOperation(RenderOperation& op);
00491 
00493         void getWorldTransforms(Matrix4* xform) const;
00494 
00496         Real getSquaredViewDepth(const Camera* cam) const;
00497 
00499         const LightList& getLights(void) const;
00500 
00507         virtual const Vector3* getWorldSpaceCorners(void) const;
00508 
00511         virtual void setProjectionType(ProjectionType pt);
00512 
00515         virtual ProjectionType getProjectionType(void) const;
00516 
00524         virtual void setOrthoWindow(Real w, Real h);
00529         virtual void setOrthoWindowHeight(Real h);
00534         virtual void setOrthoWindowWidth(Real w);
00537         virtual Real getOrthoWindowHeight() const;
00541         virtual Real getOrthoWindowWidth() const;
00542 
00548         virtual void enableReflection(const Plane& p);
00557         virtual void enableReflection(const MovablePlane* p);
00558 
00560         virtual void disableReflection(void);
00561 
00563         virtual bool isReflected(void) const { return mReflect; }
00565         virtual const Matrix4& getReflectionMatrix(void) const { return mReflectMatrix; }
00567         virtual const Plane& getReflectionPlane(void) const { return mReflectPlane; }
00568 
00578         virtual bool projectSphere(const Sphere& sphere, 
00579             Real* left, Real* top, Real* right, Real* bottom) const;
00580 
00581 
00607         virtual void enableCustomNearClipPlane(const MovablePlane* plane);
00628         virtual void enableCustomNearClipPlane(const Plane& plane);
00630         virtual void disableCustomNearClipPlane(void);
00632         virtual bool isCustomNearClipPlaneEnabled(void) const 
00633         { return mObliqueDepthProjection; }
00634 
00636         void visitRenderables(Renderable::Visitor* visitor, 
00637             bool debugRenderables = false);
00638 
00640         static const Real INFINITE_FAR_PLANE_ADJUST;
00641 
00643         virtual const Vector3& getPositionForViewUpdate(void) const;
00645         virtual const Quaternion& getOrientationForViewUpdate(void) const;
00646 
00649         PlaneBoundedVolume getPlaneBoundedVolume();
00655         void setOrientationMode(OrientationMode orientationMode);
00656 
00662         OrientationMode getOrientationMode() const;
00663 
00664     };
00665 
00669 }
00670 
00671 #endif 

Copyright © 2008 Torus Knot Software Ltd
Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 2.5 License.
Last modified Sun Feb 28 21:10:36 2010