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-2013 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 #include "OgreHeaderPrefix.h" 00038 00039 namespace Ogre 00040 { 00049 enum OrientationMode 00050 { 00051 OR_DEGREE_0 = 0, 00052 OR_DEGREE_90 = 1, 00053 OR_DEGREE_180 = 2, 00054 OR_DEGREE_270 = 3, 00055 00056 OR_PORTRAIT = OR_DEGREE_0, 00057 OR_LANDSCAPERIGHT = OR_DEGREE_90, 00058 OR_LANDSCAPELEFT = OR_DEGREE_270 00059 }; 00060 00063 enum ProjectionType 00064 { 00065 PT_ORTHOGRAPHIC, 00066 PT_PERSPECTIVE 00067 }; 00068 00071 enum FrustumPlane 00072 { 00073 FRUSTUM_PLANE_NEAR = 0, 00074 FRUSTUM_PLANE_FAR = 1, 00075 FRUSTUM_PLANE_LEFT = 2, 00076 FRUSTUM_PLANE_RIGHT = 3, 00077 FRUSTUM_PLANE_TOP = 4, 00078 FRUSTUM_PLANE_BOTTOM = 5 00079 }; 00080 00085 class _OgreExport Frustum : public MovableObject, public Renderable 00086 { 00087 protected: 00089 ProjectionType mProjType; 00090 00092 Radian mFOVy; 00094 Real mFarDist; 00096 Real mNearDist; 00098 Real mAspect; 00100 Real mOrthoHeight; 00102 Vector2 mFrustumOffset; 00104 Real mFocalLength; 00105 00107 mutable Plane mFrustumPlanes[6]; 00108 00110 mutable Quaternion mLastParentOrientation; 00111 mutable Vector3 mLastParentPosition; 00112 00114 mutable Matrix4 mProjMatrixRS; 00116 mutable Matrix4 mProjMatrixRSDepth; 00118 mutable Matrix4 mProjMatrix; 00120 mutable Matrix4 mViewMatrix; 00122 mutable bool mRecalcFrustum; 00124 mutable bool mRecalcView; 00126 mutable bool mRecalcFrustumPlanes; 00128 mutable bool mRecalcWorldSpaceCorners; 00130 mutable bool mRecalcVertexData; 00132 bool mCustomViewMatrix; 00134 bool mCustomProjMatrix; 00136 bool mFrustumExtentsManuallySet; 00138 mutable Real mLeft, mRight, mTop, mBottom; 00140 mutable OrientationMode mOrientationMode; 00141 00142 // Internal functions for calcs 00143 virtual void calcProjectionParameters(Real& left, Real& right, Real& bottom, Real& top) const; 00145 virtual void updateFrustum(void) const; 00147 virtual void updateView(void) const; 00149 virtual void updateFrustumImpl(void) const; 00151 virtual void updateViewImpl(void) const; 00152 virtual void updateFrustumPlanes(void) const; 00154 virtual void updateFrustumPlanesImpl(void) const; 00155 virtual void updateWorldSpaceCorners(void) const; 00157 virtual void updateWorldSpaceCornersImpl(void) const; 00158 virtual void updateVertexData(void) const; 00159 virtual bool isViewOutOfDate(void) const; 00160 virtual bool isFrustumOutOfDate(void) const; 00162 virtual void invalidateFrustum(void) const; 00164 virtual void invalidateView(void) const; 00165 00167 static String msMovableType; 00168 00169 mutable AxisAlignedBox mBoundingBox; 00170 mutable VertexData mVertexData; 00171 00172 MaterialPtr mMaterial; 00173 mutable Vector3 mWorldSpaceCorners[8]; 00174 00176 bool mReflect; 00178 mutable Matrix4 mReflectMatrix; 00180 mutable Plane mReflectPlane; 00182 const MovablePlane* mLinkedReflectPlane; 00184 mutable Plane mLastLinkedReflectionPlane; 00185 00187 bool mObliqueDepthProjection; 00189 mutable Plane mObliqueProjPlane; 00191 const MovablePlane* mLinkedObliqueProjPlane; 00193 mutable Plane mLastLinkedObliqueProjPlane; 00194 00195 public: 00196 00198 Frustum(const String& name = StringUtil::BLANK); 00199 00200 virtual ~Frustum(); 00213 virtual void setFOVy(const Radian& fovy); 00214 00217 virtual const Radian& getFOVy(void) const; 00218 00230 virtual void setNearClipDistance(Real nearDist); 00231 00234 virtual Real getNearClipDistance(void) const; 00235 00256 virtual void setFarClipDistance(Real farDist); 00257 00260 virtual Real getFarClipDistance(void) const; 00261 00270 virtual void setAspectRatio(Real ratio); 00271 00274 virtual Real getAspectRatio(void) const; 00275 00287 virtual void setFrustumOffset(const Vector2& offset); 00288 00302 virtual void setFrustumOffset(Real horizontal = 0.0, Real vertical = 0.0); 00303 00306 virtual const Vector2& getFrustumOffset() const; 00307 00312 virtual void setFocalLength(Real focalLength = 1.0); 00313 00316 virtual Real getFocalLength() const; 00317 00322 virtual void setFrustumExtents(Real left, Real right, Real top, Real bottom); 00324 virtual void resetFrustumExtents(); 00326 virtual void getFrustumExtents(Real& outleft, Real& outright, Real& outtop, Real& outbottom) const; 00327 00328 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 00415 virtual void setCustomProjectionMatrix(bool enable, 00416 const Matrix4& projectionMatrix = Matrix4::IDENTITY); 00418 virtual bool isCustomProjectionMatrixEnabled(void) const 00419 { return mCustomProjMatrix; } 00420 00425 virtual const Plane* getFrustumPlanes(void) const; 00426 00431 virtual const Plane& getFrustumPlane( unsigned short plane ) const; 00432 00444 virtual bool isVisible(const AxisAlignedBox& bound, FrustumPlane* culledBy = 0) const; 00445 00457 virtual bool isVisible(const Sphere& bound, FrustumPlane* culledBy = 0) const; 00458 00470 virtual bool isVisible(const Vector3& vert, FrustumPlane* culledBy = 0) const; 00471 00473 uint32 getTypeFlags(void) const; 00474 00476 const AxisAlignedBox& getBoundingBox(void) const; 00477 00479 Real getBoundingRadius(void) const; 00480 00482 void _updateRenderQueue(RenderQueue* queue); 00483 00485 const String& getMovableType(void) const; 00486 00488 void _notifyCurrentCamera(Camera* cam); 00489 00491 const MaterialPtr& getMaterial(void) const; 00492 00494 void getRenderOperation(RenderOperation& op); 00495 00497 void getWorldTransforms(Matrix4* xform) const; 00498 00500 Real getSquaredViewDepth(const Camera* cam) const; 00501 00503 const LightList& getLights(void) const; 00504 00511 virtual const Vector3* getWorldSpaceCorners(void) const; 00512 00515 virtual void setProjectionType(ProjectionType pt); 00516 00519 virtual ProjectionType getProjectionType(void) const; 00520 00531 virtual void setOrthoWindow(Real w, Real h); 00537 virtual void setOrthoWindowHeight(Real h); 00543 virtual void setOrthoWindowWidth(Real w); 00546 virtual Real getOrthoWindowHeight() const; 00550 virtual Real getOrthoWindowWidth() const; 00551 00557 virtual void enableReflection(const Plane& p); 00566 virtual void enableReflection(const MovablePlane* p); 00567 00569 virtual void disableReflection(void); 00570 00572 virtual bool isReflected(void) const { return mReflect; } 00574 virtual const Matrix4& getReflectionMatrix(void) const { return mReflectMatrix; } 00576 virtual const Plane& getReflectionPlane(void) const { return mReflectPlane; } 00577 00595 virtual bool projectSphere(const Sphere& sphere, 00596 Real* left, Real* top, Real* right, Real* bottom) const; 00597 00598 00625 virtual void enableCustomNearClipPlane(const MovablePlane* plane); 00647 virtual void enableCustomNearClipPlane(const Plane& plane); 00649 virtual void disableCustomNearClipPlane(void); 00651 virtual bool isCustomNearClipPlaneEnabled(void) const 00652 { return mObliqueDepthProjection; } 00653 00655 void visitRenderables(Renderable::Visitor* visitor, 00656 bool debugRenderables = false); 00657 00659 static const Real INFINITE_FAR_PLANE_ADJUST; 00660 00662 virtual const Vector3& getPositionForViewUpdate(void) const; 00664 virtual const Quaternion& getOrientationForViewUpdate(void) const; 00665 00668 PlaneBoundedVolume getPlaneBoundedVolume(); 00674 void setOrientationMode(OrientationMode orientationMode); 00675 00681 OrientationMode getOrientationMode() const; 00682 00683 }; 00684 00688 } // namespace Ogre 00689 00690 #include "OgreHeaderSuffix.h" 00691 00692 #endif // __Frustum_H__
Copyright © 2012 Torus Knot Software Ltd

This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
Last modified Mon Jul 27 2020 13:40:42