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-2012 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
    00197         Frustum(const String& name = StringUtil::BLANK);
    00198
    00199         virtual ~Frustum();
    00212         virtual void setFOVy(const Radian& fovy);
    00213
    00216         virtual const Radian& getFOVy(void) const;
    00217
    00229         virtual void setNearClipDistance(Real nearDist);
    00230
    00233         virtual Real getNearClipDistance(void) const;
    00234
    00255         virtual void setFarClipDistance(Real farDist);
    00256
    00259         virtual Real getFarClipDistance(void) const;
    00260
    00269         virtual void setAspectRatio(Real ratio);
    00270
    00273         virtual Real getAspectRatio(void) const;
    00274
    00286         virtual void setFrustumOffset(const Vector2& offset);
    00287
    00301         virtual void setFrustumOffset(Real horizontal = 0.0, Real vertical = 0.0);
    00302
    00305         virtual const Vector2& getFrustumOffset() const;
    00306
    00311         virtual void setFocalLength(Real focalLength = 1.0);
    00312
    00315         virtual Real getFocalLength() const;
    00316
    00321         virtual void setFrustumExtents(Real left, Real right, Real top, Real bottom);
    00323         virtual void resetFrustumExtents();
    00325         virtual void getFrustumExtents(Real& outleft, Real& outright, Real& outtop, Real& outbottom) const;
    00326
    00327
    00337         virtual const Matrix4& getProjectionMatrixRS(void) const;
    00349         virtual const Matrix4& getProjectionMatrixWithRSDepth(void) const;
    00359         virtual const Matrix4& getProjectionMatrix(void) const;
    00360
    00363         virtual const Matrix4& getViewMatrix(void) const;
    00364
    00369         virtual void calcViewMatrixRelative(const Vector3& relPos, Matrix4& matToUpdate) const;
    00370
    00388         virtual void setCustomViewMatrix(bool enable,
    00389             const Matrix4& viewMatrix = Matrix4::IDENTITY);
    00391         virtual bool isCustomViewMatrixEnabled(void) const
    00392         { return mCustomViewMatrix; }
    00393
    00413         virtual void setCustomProjectionMatrix(bool enable,
    00414             const Matrix4& projectionMatrix = Matrix4::IDENTITY);
    00416         virtual bool isCustomProjectionMatrixEnabled(void) const
    00417         { return mCustomProjMatrix; }
    00418
    00423         virtual const Plane* getFrustumPlanes(void) const;
    00424
    00429         virtual const Plane& getFrustumPlane( unsigned short plane ) const;
    00430
    00442         virtual bool isVisible(const AxisAlignedBox& bound, FrustumPlane* culledBy = 0) const;
    00443
    00455         virtual bool isVisible(const Sphere& bound, FrustumPlane* culledBy = 0) const;
    00456
    00468         virtual bool isVisible(const Vector3& vert, FrustumPlane* culledBy = 0) const;
    00469
    00471         uint32 getTypeFlags(void) const;
    00472
    00474         const AxisAlignedBox& getBoundingBox(void) const;
    00475
    00477         Real getBoundingRadius(void) const;
    00478
    00480         void _updateRenderQueue(RenderQueue* queue);
    00481
    00483         const String& getMovableType(void) const;
    00484
    00486         void _notifyCurrentCamera(Camera* cam);
    00487
    00489         const MaterialPtr& getMaterial(void) const;
    00490
    00492         void getRenderOperation(RenderOperation& op);
    00493
    00495         void getWorldTransforms(Matrix4* xform) const;
    00496
    00498         Real getSquaredViewDepth(const Camera* cam) const;
    00499
    00501         const LightList& getLights(void) const;
    00502
    00509         virtual const Vector3* getWorldSpaceCorners(void) const;
    00510
    00513         virtual void setProjectionType(ProjectionType pt);
    00514
    00517         virtual ProjectionType getProjectionType(void) const;
    00518
    00526         virtual void setOrthoWindow(Real w, Real h);
    00531         virtual void setOrthoWindowHeight(Real h);
    00536         virtual void setOrthoWindowWidth(Real w);
    00539         virtual Real getOrthoWindowHeight() const;
    00543         virtual Real getOrthoWindowWidth() const;
    00544
    00550         virtual void enableReflection(const Plane& p);
    00559         virtual void enableReflection(const MovablePlane* p);
    00560
    00562         virtual void disableReflection(void);
    00563
    00565         virtual bool isReflected(void) const { return mReflect; }
    00567         virtual const Matrix4& getReflectionMatrix(void) const { return mReflectMatrix; }
    00569         virtual const Plane& getReflectionPlane(void) const { return mReflectPlane; }
    00570
    00580         virtual bool projectSphere(const Sphere& sphere,
    00581             Real* left, Real* top, Real* right, Real* bottom) const;
    00582
    00583
    00609         virtual void enableCustomNearClipPlane(const MovablePlane* plane);
    00630         virtual void enableCustomNearClipPlane(const Plane& plane);
    00632         virtual void disableCustomNearClipPlane(void);
    00634         virtual bool isCustomNearClipPlaneEnabled(void) const
    00635         { return mObliqueDepthProjection; }
    00636
    00638         void visitRenderables(Renderable::Visitor* visitor,
    00639             bool debugRenderables = false);
    00640
    00642         static const Real INFINITE_FAR_PLANE_ADJUST;
    00643
    00645         virtual const Vector3& getPositionForViewUpdate(void) const;
    00647         virtual const Quaternion& getOrientationForViewUpdate(void) const;
    00648
    00651         PlaneBoundedVolume getPlaneBoundedVolume();
    00657         void setOrientationMode(OrientationMode orientationMode);
    00658
    00664         OrientationMode getOrientationMode() const;
    00665
    00666     };
    00667
    00671 }
    00672
    00673 #endif

Copyright © 2012 Torus Knot Software Ltd
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
Last modified Sun Sep 2 2012 07:27:21