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-2006 Torus Knot Software Ltd
00008 Also see acknowledgements in Readme.html
00009 
00010 This program is free software; you can redistribute it and/or modify it under
00011 the terms of the GNU Lesser General Public License as published by the Free Software
00012 Foundation; either version 2 of the License, or (at your option) any later
00013 version.
00014 
00015 This program is distributed in the hope that it will be useful, but WITHOUT
00016 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00017 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
00018 
00019 You should have received a copy of the GNU Lesser General Public License along with
00020 this program; if not, write to the Free Software Foundation, Inc., 59 Temple
00021 Place - Suite 330, Boston, MA 02111-1307, USA, or go to
00022 http://www.gnu.org/copyleft/lesser.txt.
00023 
00024 You may alternatively use this source under the terms of a specific version of
00025 the OGRE Unrestricted License provided you have obtained such a license from
00026 Torus Knot Software Ltd.
00027 -----------------------------------------------------------------------------
00028 */
00029 #ifndef __Frustum_H__
00030 #define __Frustum_H__
00031 
00032 #include "OgrePrerequisites.h"
00033 #include "OgreMovableObject.h"
00034 #include "OgreRenderable.h"
00035 #include "OgreAxisAlignedBox.h"
00036 #include "OgreVertexIndexData.h"
00037 #include "OgreMovablePlane.h"
00038 
00039 namespace Ogre
00040 {
00043     enum ProjectionType
00044     {
00045         PT_ORTHOGRAPHIC,
00046         PT_PERSPECTIVE
00047     };
00048 
00051     enum FrustumPlane
00052     {
00053         FRUSTUM_PLANE_NEAR   = 0,
00054         FRUSTUM_PLANE_FAR    = 1,
00055         FRUSTUM_PLANE_LEFT   = 2,
00056         FRUSTUM_PLANE_RIGHT  = 3,
00057         FRUSTUM_PLANE_TOP    = 4,
00058         FRUSTUM_PLANE_BOTTOM = 5
00059     };
00060 
00065     class _OgreExport Frustum : public MovableObject, public Renderable
00066     {
00067     protected:
00069         ProjectionType mProjType;
00070 
00072         Radian mFOVy;
00074         Real mFarDist;
00076         Real mNearDist;
00078         Real mAspect;
00080         Real mOrthoHeight;
00082         Vector2 mFrustumOffset;
00084         Real mFocalLength;
00085 
00087         mutable Plane mFrustumPlanes[6];
00088 
00090         mutable Quaternion mLastParentOrientation;
00091         mutable Vector3 mLastParentPosition;
00092 
00094         mutable Matrix4 mProjMatrixRS;
00096         mutable Matrix4 mProjMatrixRSDepth;
00098         mutable Matrix4 mProjMatrix;
00100         mutable Matrix4 mViewMatrix;
00102         mutable bool mRecalcFrustum;
00104         mutable bool mRecalcView;
00106         mutable bool mRecalcFrustumPlanes;
00108         mutable bool mRecalcWorldSpaceCorners;
00110         mutable bool mRecalcVertexData;
00112         bool mCustomViewMatrix;
00114         bool mCustomProjMatrix;
00116         bool mFrustumExtentsManuallySet;
00118         mutable Real mLeft, mRight, mTop, mBottom;
00119 
00120         
00121         // Internal functions for calcs
00122         virtual void calcProjectionParameters(Real& left, Real& right, Real& bottom, Real& top) const;
00124         virtual void updateFrustum(void) const;
00126         virtual void updateView(void) const;
00128         virtual void updateFrustumImpl(void) const;
00130         virtual void updateViewImpl(void) const;
00131         virtual void updateFrustumPlanes(void) const;
00133         virtual void updateFrustumPlanesImpl(void) const;
00134         virtual void updateWorldSpaceCorners(void) const;
00136         virtual void updateWorldSpaceCornersImpl(void) const;
00137         virtual void updateVertexData(void) const;
00138         virtual bool isViewOutOfDate(void) const;
00139         virtual bool isFrustumOutOfDate(void) const;
00141         virtual void invalidateFrustum(void) const;
00143         virtual void invalidateView(void) const;
00144 
00146         static String msMovableType;
00147 
00148         mutable AxisAlignedBox mBoundingBox;
00149         mutable VertexData mVertexData;
00150 
00151         MaterialPtr mMaterial;
00152         mutable Vector3 mWorldSpaceCorners[8];
00153 
00155         bool mReflect;
00157         mutable Matrix4 mReflectMatrix;
00159         mutable Plane mReflectPlane;
00161         const MovablePlane* mLinkedReflectPlane;
00163         mutable Plane mLastLinkedReflectionPlane;
00164         
00166         bool mObliqueDepthProjection;
00168         mutable Plane mObliqueProjPlane;
00170         const MovablePlane* mLinkedObliqueProjPlane;
00172         mutable Plane mLastLinkedObliqueProjPlane;
00173 
00174     public:
00175 
00176         Frustum();
00177         virtual ~Frustum();
00190         virtual void setFOVy(const Radian& fovy);
00191 
00194         virtual const Radian& getFOVy(void) const;
00195 
00207         virtual void setNearClipDistance(Real nearDist);
00208 
00211         virtual Real getNearClipDistance(void) const;
00212 
00233         virtual void setFarClipDistance(Real farDist);
00234 
00237         virtual Real getFarClipDistance(void) const;
00238 
00247         virtual void setAspectRatio(Real ratio);
00248 
00251         virtual Real getAspectRatio(void) const;
00252 
00264         virtual void setFrustumOffset(const Vector2& offset);
00265 
00279         virtual void setFrustumOffset(Real horizontal = 0.0, Real vertical = 0.0);
00280 
00283         virtual const Vector2& getFrustumOffset() const;
00284 
00289         virtual void setFocalLength(Real focalLength = 1.0);
00290 
00293         virtual Real getFocalLength() const;
00294 
00299         virtual void setFrustumExtents(Real left, Real right, Real top, Real bottom);
00301         virtual void resetFrustumExtents(); 
00303         virtual void getFrustumExtents(Real& outleft, Real& outright, Real& outtop, Real& outbottom) const;
00304 
00305 
00315         virtual const Matrix4& getProjectionMatrixRS(void) const;
00327         virtual const Matrix4& getProjectionMatrixWithRSDepth(void) const;
00337         virtual const Matrix4& getProjectionMatrix(void) const;
00338 
00341         virtual const Matrix4& getViewMatrix(void) const;
00342 
00347         virtual void calcViewMatrixRelative(const Vector3& relPos, Matrix4& matToUpdate) const;
00348 
00366         virtual void setCustomViewMatrix(bool enable, 
00367             const Matrix4& viewMatrix = Matrix4::IDENTITY);
00369         virtual bool isCustomViewMatrixEnabled(void) const 
00370         { return mCustomViewMatrix; }
00371         
00391         virtual void setCustomProjectionMatrix(bool enable, 
00392             const Matrix4& projectionMatrix = Matrix4::IDENTITY);
00394         virtual bool isCustomProjectionMatrixEnabled(void) const
00395         { return mCustomProjMatrix; }
00396 
00401         virtual const Plane* getFrustumPlanes(void) const;
00402 
00407         virtual const Plane& getFrustumPlane( unsigned short plane ) const;
00408 
00420         virtual bool isVisible(const AxisAlignedBox& bound, FrustumPlane* culledBy = 0) const;
00421 
00433         virtual bool isVisible(const Sphere& bound, FrustumPlane* culledBy = 0) const;
00434 
00446         virtual bool isVisible(const Vector3& vert, FrustumPlane* culledBy = 0) const;
00447 
00449         uint32 getTypeFlags(void) const;
00450 
00452         const AxisAlignedBox& getBoundingBox(void) const;
00453 
00455         Real getBoundingRadius(void) const;
00456 
00458         void _updateRenderQueue(RenderQueue* queue);
00459 
00461         const String& getMovableType(void) const;
00462 
00464         void _notifyCurrentCamera(Camera* cam);
00465 
00467         const MaterialPtr& getMaterial(void) const;
00468 
00470         void getRenderOperation(RenderOperation& op);
00471 
00473         void getWorldTransforms(Matrix4* xform) const;
00474 
00476         Real getSquaredViewDepth(const Camera* cam) const;
00477 
00479         const LightList& getLights(void) const;
00480 
00487         virtual const Vector3* getWorldSpaceCorners(void) const;
00488 
00491         virtual void setProjectionType(ProjectionType pt);
00492 
00495         virtual ProjectionType getProjectionType(void) const;
00496 
00504         virtual void setOrthoWindow(Real w, Real h);
00509         virtual void setOrthoWindowHeight(Real h);
00514         virtual void setOrthoWindowWidth(Real w);
00517         virtual Real getOrthoWindowHeight() const;
00521         virtual Real getOrthoWindowWidth() const;
00522 
00528         virtual void enableReflection(const Plane& p);
00537         virtual void enableReflection(const MovablePlane* p);
00538 
00540         virtual void disableReflection(void);
00541 
00543         virtual bool isReflected(void) const { return mReflect; }
00545         virtual const Matrix4& getReflectionMatrix(void) const { return mReflectMatrix; }
00547         virtual const Plane& getReflectionPlane(void) const { return mReflectPlane; }
00548 
00558         virtual bool projectSphere(const Sphere& sphere, 
00559             Real* left, Real* top, Real* right, Real* bottom) const;
00560 
00561 
00587         virtual void enableCustomNearClipPlane(const MovablePlane* plane);
00608         virtual void enableCustomNearClipPlane(const Plane& plane);
00610         virtual void disableCustomNearClipPlane(void);
00612         virtual bool isCustomNearClipPlaneEnabled(void) const 
00613         { return mObliqueDepthProjection; }
00614 
00616         void visitRenderables(Renderable::Visitor* visitor, 
00617             bool debugRenderables = false);
00618 
00620         static const Real INFINITE_FAR_PLANE_ADJUST;
00621 
00623         virtual const Vector3& getPositionForViewUpdate(void) const;
00625         virtual const Quaternion& getOrientationForViewUpdate(void) const;
00626     };
00627 
00628 
00629 }
00630 
00631 #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 Sep 27 22:02:23 2009