Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

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-2005 The OGRE Team
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 */
00025 #ifndef __Frustum_H__
00026 #define __Frustum_H__
00027 
00028 #include "OgrePrerequisites.h"
00029 #include "OgreMovableObject.h"
00030 #include "OgreRenderable.h"
00031 #include "OgreAxisAlignedBox.h"
00032 #include "OgreVertexIndexData.h"
00033 #include "OgreMovablePlane.h"
00034 
00035 namespace Ogre
00036 {
00039     enum ProjectionType
00040     {
00041         PT_ORTHOGRAPHIC,
00042         PT_PERSPECTIVE
00043     };
00044 
00047     enum FrustumPlane
00048     {
00049         FRUSTUM_PLANE_NEAR   = 0,
00050         FRUSTUM_PLANE_FAR    = 1,
00051         FRUSTUM_PLANE_LEFT   = 2,
00052         FRUSTUM_PLANE_RIGHT  = 3,
00053         FRUSTUM_PLANE_TOP    = 4,
00054         FRUSTUM_PLANE_BOTTOM = 5
00055     };
00056 
00061     class _OgreExport Frustum : public MovableObject, public Renderable
00062     {
00063     protected:
00065         ProjectionType mProjType;
00066 
00068         Radian mFOVy;
00070         Real mFarDist;
00072         Real mNearDist;
00074         Real mAspect;
00076         Vector2 mFrustumOffset;
00078         Real mFocalLength;
00079 
00081         mutable Plane mFrustumPlanes[6];
00082 
00084         mutable Quaternion mLastParentOrientation;
00085         mutable Vector3 mLastParentPosition;
00086 
00088         mutable Matrix4 mProjMatrixRS;
00090         mutable Matrix4 mProjMatrixRSDepth;
00092         mutable Matrix4 mProjMatrix;
00094         mutable Matrix4 mViewMatrix;
00096         mutable bool mRecalcFrustum;
00098         mutable bool mRecalcView;
00100         mutable bool mRecalcFrustumPlanes;
00102         mutable bool mRecalcWorldSpaceCorners;
00104         mutable bool mRecalcVertexData;
00106         bool mCustomViewMatrix;
00108         bool mCustomProjMatrix;
00109 
00110         
00111         // Internal functions for calcs
00112         virtual void calcProjectionParameters(Real& left, Real& right, Real& bottom, Real& top) const;
00114         virtual void updateFrustum(void) const;
00116         virtual void updateView(void) const;
00118         virtual void updateFrustumImpl(void) const;
00120         virtual void updateViewImpl(void) const;
00121         virtual void updateFrustumPlanes(void) const;
00123         virtual void updateFrustumPlanesImpl(void) const;
00124         virtual void updateWorldSpaceCorners(void) const;
00126         virtual void updateWorldSpaceCornersImpl(void) const;
00127         virtual void updateVertexData(void) const;
00128         virtual bool isViewOutOfDate(void) const;
00129         virtual bool isFrustumOutOfDate(void) const;
00131         virtual void invalidateFrustum(void) const;
00133         virtual void invalidateView(void) const;
00134 
00136         static String msMovableType;
00137 
00138         mutable AxisAlignedBox mBoundingBox;
00139         mutable VertexData mVertexData;
00140 
00141         MaterialPtr mMaterial;
00142         mutable Vector3 mWorldSpaceCorners[8];
00143 
00145         bool mReflect;
00147         mutable Matrix4 mReflectMatrix;
00149         mutable Plane mReflectPlane;
00151         const MovablePlane* mLinkedReflectPlane;
00153         mutable Plane mLastLinkedReflectionPlane;
00154         
00156         bool mObliqueDepthProjection;
00158         mutable Plane mObliqueProjPlane;
00160         const MovablePlane* mLinkedObliqueProjPlane;
00162         mutable Plane mLastLinkedObliqueProjPlane;
00163 
00164         
00166         virtual const Vector3& getPositionForViewUpdate(void) const;
00168         virtual const Quaternion& getOrientationForViewUpdate(void) const;
00169 
00170 
00171     public:
00172 
00173         Frustum();
00174         virtual ~Frustum();
00187         virtual void setFOVy(const Radian& fovy);
00188 #ifndef OGRE_FORCE_ANGLE_TYPES
00189         inline void setFOVy(Real fovy) {
00190             setFOVy ( Angle(fovy) );
00191         }
00192 #endif//OGRE_FORCE_ANGLE_TYPES
00193 
00196         virtual const Radian& getFOVy(void) const;
00197 
00209         virtual void setNearClipDistance(Real nearDist);
00210 
00213         virtual Real getNearClipDistance(void) const;
00214 
00235         virtual void setFarClipDistance(Real farDist);
00236 
00239         virtual Real getFarClipDistance(void) const;
00240 
00249         virtual void setAspectRatio(Real ratio);
00250 
00253         virtual Real getAspectRatio(void) const;
00254 
00266         virtual void setFrustumOffset(const Vector2& offset);
00267 
00281         virtual void setFrustumOffset(Real horizontal = 0.0, Real vertical = 0.0);
00282 
00285         virtual const Vector2& getFrustumOffset() const;
00286 
00291         virtual void setFocalLength(Real focalLength = 1.0);
00292 
00295         virtual Real getFocalLength() const;
00296 
00306         virtual const Matrix4& getProjectionMatrixRS(void) const;
00318         virtual const Matrix4& getProjectionMatrixWithRSDepth(void) const;
00328         virtual const Matrix4& getProjectionMatrix(void) const;
00329 
00332         virtual const Matrix4& getViewMatrix(void) const;
00333 
00350         virtual void setCustomViewMatrix(bool enable, 
00351             const Matrix4& viewMatrix = Matrix4::IDENTITY);
00353         virtual bool isCustomViewMatrixEnabled(void) const 
00354         { return mCustomViewMatrix; }
00355         
00375         virtual void setCustomProjectionMatrix(bool enable, 
00376             const Matrix4& projectionMatrix = Matrix4::IDENTITY);
00378         virtual bool isCustomProjectionMatrixEnabled(void) const
00379         { return mCustomProjMatrix; }
00380 
00385         virtual const Plane* getFrustumPlanes(void) const;
00386 
00391         virtual const Plane& getFrustumPlane( unsigned short plane ) const;
00392 
00404         virtual bool isVisible(const AxisAlignedBox& bound, FrustumPlane* culledBy = 0) const;
00405 
00417         virtual bool isVisible(const Sphere& bound, FrustumPlane* culledBy = 0) const;
00418 
00430         virtual bool isVisible(const Vector3& vert, FrustumPlane* culledBy = 0) const;
00431 
00432 
00434         const AxisAlignedBox& getBoundingBox(void) const;
00435 
00437         Real getBoundingRadius(void) const;
00438 
00440         void _updateRenderQueue(RenderQueue* queue);
00441 
00443         const String& getMovableType(void) const;
00444 
00446         void _notifyCurrentCamera(Camera* cam);
00447 
00449         const MaterialPtr& getMaterial(void) const;
00450 
00452         void getRenderOperation(RenderOperation& op);
00453 
00455         void getWorldTransforms(Matrix4* xform) const;
00456 
00458         const Quaternion& getWorldOrientation(void) const;
00459 
00461         const Vector3& getWorldPosition(void) const;
00462 
00464         Real getSquaredViewDepth(const Camera* cam) const;
00465 
00467         const LightList& getLights(void) const;
00468 
00475         virtual const Vector3* getWorldSpaceCorners(void) const;
00476 
00479         virtual void setProjectionType(ProjectionType pt);
00480 
00483         virtual ProjectionType getProjectionType(void) const;
00484 
00490         virtual void enableReflection(const Plane& p);
00499         virtual void enableReflection(const MovablePlane* p);
00500 
00502         virtual void disableReflection(void);
00503 
00505         virtual bool isReflected(void) const { return mReflect; }
00507         virtual const Matrix4& getReflectionMatrix(void) const { return mReflectMatrix; }
00509         virtual const Plane& getReflectionPlane(void) const { return mReflectPlane; }
00510 
00520         virtual bool projectSphere(const Sphere& sphere, 
00521             Real* left, Real* top, Real* right, Real* bottom) const;
00522 
00523 
00549         virtual void enableCustomNearClipPlane(const MovablePlane* plane);
00570         virtual void enableCustomNearClipPlane(const Plane& plane);
00572         virtual void disableCustomNearClipPlane(void);
00574         virtual bool isCustomNearClipPlaneEnabled(void) const 
00575         { return mObliqueDepthProjection; }
00576         
00577 
00579         static const Real INFINITE_FAR_PLANE_ADJUST;
00580     };
00581 
00582 
00583 }
00584 
00585 #endif 

Copyright © 2000-2005 by The OGRE Team
Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 2.5 License.
Last modified Sun Mar 12 14:37:41 2006