00001 00005 /* Copyright © 2009, 2010 James Legg. 00006 This program is free software: you can redistribute it and/or modify 00007 it under the terms of the GNU General Public License as published by 00008 the Free Software Foundation, either version 3 of the License, or 00009 (at your option) any later version. 00010 */ 00011 #include "OcclusionTester.h" 00012 00013 namespace Track 00014 { 00015 00016 00017 OcclusionTester::OcclusionTester() 00018 { 00019 } 00020 00021 OcclusionTester::~OcclusionTester() 00022 { 00023 } 00024 00025 OcclusionTester::ViewState OcclusionTester::operator ()(const Track::AxisAlignedBoundingBox & aabb) const 00026 { 00027 /* If all vertices are the wrong side of the same plane, then the aabb is 00028 * outside of the view. If all vertices are inside the viewing area, the 00029 * whole aabb is inside the viewing area. In any other case, we may have 00030 * no overlap or partial overlap. 00031 */ 00032 unsigned passed(0); 00033 btVector3 min = aabb.get_min(); 00034 btVector3 max = aabb.get_max(); 00035 for (unsigned plane_index = 0; plane_index < 5; plane_index++) 00036 { 00037 unsigned passed_this_plane(0); 00038 for (unsigned int i = 0; i < 2; i++) 00039 { 00040 for (unsigned int j = 0; j < 2; j++) 00041 { 00042 for (unsigned int k = 0; k < 2; k++) 00043 { 00044 if (in_half_space(btVector3(i ? min.x() : max.x(), 00045 j ? min.y() : max.y(), 00046 k ? min.z() : max.z() 00047 ), 00048 plane_index)) 00049 { 00050 passed_this_plane++; 00051 } 00052 } 00053 } 00054 } 00055 if (passed_this_plane == 0) 00056 { 00057 // all on one side, so entire volume is outside. 00058 return VS_OUT; 00059 } 00060 passed += passed_this_plane; 00061 } 00062 if (passed == 40) 00063 { 00064 // all points inside all half spaces. aabb is completely inside. 00065 return VS_IN; 00066 } 00070 return VS_PARTIAL; 00071 } 00072 00073 inline bool OcclusionTester::in_half_space(const btVector3 & point, const unsigned plane_index) const 00074 { 00075 return point.dot(plane_vectors[plane_index]) + 00076 plane_distances[plane_index] > 0; 00077 } 00078 00079 }
Generated at Mon Sep 6 00:41:11 2010 by Doxygen version 1.4.7 for Racer version svn335.