00001 /*************************************************************************** 00002 octreecamera.cpp - description 00003 ------------------- 00004 begin : Fri Sep 27 2002 00005 copyright : (C) 2002 by Jon Anderson 00006 email : janders@users.sf.net 00007 ***************************************************************************/ 00008 00009 /*************************************************************************** 00010 * * 00011 * This program is free software; you can redistribute it and/or modify * 00012 * it under the terms of the GNU Lesser General Public License as * 00013 * published by the Free Software Foundation; either version 2 of the * 00014 * License, or (at your option) any later version. * 00015 * * 00016 ***************************************************************************/ 00017 00018 #include <OgreMath.h> 00019 #include <OgreAxisAlignedBox.h> 00020 #include <OgreRoot.h> 00021 00022 #include <OgreOctreeCamera.h> 00023 00024 namespace Ogre 00025 { 00026 OctreeCamera::OctreeCamera( const String& name, SceneManager* sm ) : Camera( name, sm ) 00027 { 00028 00029 } 00030 00031 OctreeCamera::~OctreeCamera() 00032 { 00033 } 00034 00035 OctreeCamera::Visibility OctreeCamera::getVisibility( const AxisAlignedBox &bound ) 00036 { 00037 00038 // Null boxes always invisible 00039 if ( bound.isNull() ) 00040 return NONE; 00041 00042 // Make any pending updates to the calculated frustum 00043 updateView(); 00044 00045 // Get corners of the box 00046 const Vector3* pCorners = bound.getAllCorners(); 00047 00048 // For each plane, see if all points are on the negative side 00049 // If so, object is not visible. 00050 // If one or more are, it's partial. 00051 // If all aren't, full 00052 00053 int corners[ 8 ] = {0, 4, 3, 5, 2, 6, 1, 7}; 00054 00055 int planes[ 6 ] = {FRUSTUM_PLANE_TOP, FRUSTUM_PLANE_BOTTOM, 00056 FRUSTUM_PLANE_LEFT, FRUSTUM_PLANE_RIGHT, 00057 FRUSTUM_PLANE_FAR, FRUSTUM_PLANE_NEAR }; 00058 00059 bool all_inside = true; 00060 00061 for ( int plane = 0; plane < 6; ++plane ) 00062 { 00063 00064 // Skip far plane if infinite view frustum 00065 if (mFarDist == 0 && planes[ plane ] == FRUSTUM_PLANE_FAR) 00066 continue; 00067 00068 bool all_outside = true; 00069 00070 float distance = 0; 00071 00072 for ( int corner = 0; corner < 8; ++corner ) 00073 { 00074 distance = mFrustumPlanes[ planes[ plane ] ].getDistance( pCorners[ corners[ corner ] ] ); 00075 all_outside = all_outside && ( distance < 0 ); 00076 all_inside = all_inside && ( distance >= 0 ); 00077 00078 if ( !all_outside && !all_inside ) 00079 break; 00080 } 00081 00082 if ( all_outside ) 00083 return NONE; 00084 } 00085 00086 if ( all_inside ) 00087 return FULL; 00088 else 00089 return PARTIAL; 00090 00091 } 00092 00093 } 00094 00095 00096 00097
Copyright © 2002-2003 by The OGRE Team
Last modified Fri May 14 23:22:28 2004