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 © 2000-2004 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 /*************************************************************************** 00026 octreecamera.cpp - description 00027 ------------------- 00028 begin : Fri Sep 27 2002 00029 copyright : (C) 2002 by Jon Anderson 00030 email : janders@users.sf.net 00031 00032 Enhancements 2003 - 2004 (C) The OGRE Team 00033 00034 ***************************************************************************/ 00035 #include <OgreMath.h> 00036 #include <OgreAxisAlignedBox.h> 00037 #include <OgreRoot.h> 00038 00039 #include <OgreOctreeCamera.h> 00040 00041 namespace Ogre 00042 { 00043 OctreeCamera::OctreeCamera( const String& name, SceneManager* sm ) : Camera( name, sm ) 00044 { 00045 00046 } 00047 00048 OctreeCamera::~OctreeCamera() 00049 { 00050 } 00051 00052 OctreeCamera::Visibility OctreeCamera::getVisibility( const AxisAlignedBox &bound ) 00053 { 00054 00055 // Null boxes always invisible 00056 if ( bound.isNull() ) 00057 return NONE; 00058 00059 // Make any pending updates to the calculated frustum 00060 updateView(); 00061 00062 // Get corners of the box 00063 const Vector3* pCorners = bound.getAllCorners(); 00064 00065 // For each plane, see if all points are on the negative side 00066 // If so, object is not visible. 00067 // If one or more are, it's partial. 00068 // If all aren't, full 00069 00070 int corners[ 8 ] = {0, 4, 3, 5, 2, 6, 1, 7}; 00071 00072 int planes[ 6 ] = {FRUSTUM_PLANE_TOP, FRUSTUM_PLANE_BOTTOM, 00073 FRUSTUM_PLANE_LEFT, FRUSTUM_PLANE_RIGHT, 00074 FRUSTUM_PLANE_FAR, FRUSTUM_PLANE_NEAR }; 00075 00076 bool all_inside = true; 00077 00078 for ( int plane = 0; plane < 6; ++plane ) 00079 { 00080 00081 // Skip far plane if infinite view frustum 00082 if (mFarDist == 0 && planes[ plane ] == FRUSTUM_PLANE_FAR) 00083 continue; 00084 00085 bool all_outside = true; 00086 00087 float distance = 0; 00088 00089 for ( int corner = 0; corner < 8; ++corner ) 00090 { 00091 distance = mFrustumPlanes[ planes[ plane ] ].getDistance( pCorners[ corners[ corner ] ] ); 00092 all_outside = all_outside && ( distance < 0 ); 00093 all_inside = all_inside && ( distance >= 0 ); 00094 00095 if ( !all_outside && !all_inside ) 00096 break; 00097 } 00098 00099 if ( all_outside ) 00100 return NONE; 00101 } 00102 00103 if ( all_inside ) 00104 return FULL; 00105 else 00106 return PARTIAL; 00107 00108 } 00109 00110 } 00111 00112 00113 00114
Copyright © 2002-2003 by The OGRE Team
Last modified Sun Nov 28 19:48:36 2004