Sirikata
|
00001 // Copyright (c) 2012 Sirikata Authors. All rights reserved. 00002 // Use of this source code is governed by a BSD-style license that can 00003 // be found in the LICENSE file. 00004 00005 #ifndef _SIRIKATA_LIBCORE_AGGREGATE_BOUNDING_INFO_HPP_ 00006 #define _SIRIKATA_LIBCORE_AGGREGATE_BOUNDING_INFO_HPP_ 00007 00008 #include <sirikata/core/util/Vector3.hpp> 00009 #include <sirikata/core/util/BoundingSphere.hpp> 00010 00011 namespace Sirikata { 00012 00036 class AggregateBoundingInfo { 00037 public: 00038 Vector3f centerOffset; 00039 float32 centerBoundsRadius; 00040 float32 maxObjectRadius; 00041 00044 AggregateBoundingInfo() 00045 : centerOffset(0, 0, 0), 00046 centerBoundsRadius(-1), 00047 maxObjectRadius(0) 00048 {} 00049 00051 AggregateBoundingInfo(Vector3f off, float32 obj_size) 00052 : centerOffset(off), 00053 centerBoundsRadius(0), 00054 maxObjectRadius(obj_size) 00055 {} 00056 00058 explicit AggregateBoundingInfo(const BoundingSphere3f& obj_bounds) 00059 : centerOffset(obj_bounds.center()), 00060 centerBoundsRadius(0), 00061 maxObjectRadius(obj_bounds.radius()) 00062 {} 00063 00065 AggregateBoundingInfo(Vector3f off, float32 center_bounds, float32 max_obj_size) 00066 : centerOffset(off), 00067 centerBoundsRadius(center_bounds), 00068 maxObjectRadius(max_obj_size) 00069 {} 00070 00072 BoundingSphere3f centerBounds() const { 00073 return BoundingSphere3f(centerOffset, centerBoundsRadius); 00074 } 00075 00077 float32 fullRadius() const { 00078 return centerBoundsRadius + maxObjectRadius; 00079 } 00080 00082 BoundingSphere3f fullBounds() const { 00083 return BoundingSphere3f(centerOffset, fullRadius()); 00084 } 00085 00088 bool singleObject() const { 00089 return (centerBoundsRadius == 0); 00090 } 00091 00092 bool invalid() const { 00093 return (centerBoundsRadius < 0); 00094 } 00095 00096 AggregateBoundingInfo& mergeIn(const AggregateBoundingInfo& rhs) { 00097 *this = merge(rhs); 00098 return *this; 00099 } 00100 00101 AggregateBoundingInfo merge(const AggregateBoundingInfo& rhs) { 00102 BoundingSphere3f new_cbnds = centerBounds().merge(rhs.centerBounds()); 00103 float32 new_max_rad = std::max(maxObjectRadius, rhs.maxObjectRadius); 00104 return AggregateBoundingInfo(new_cbnds.center(), new_cbnds.radius(), new_max_rad); 00105 } 00106 00107 bool operator==(const AggregateBoundingInfo& rhs) { 00108 return (centerOffset == rhs.centerOffset && centerBoundsRadius == rhs.centerBoundsRadius && maxObjectRadius == rhs.maxObjectRadius); 00109 } 00110 bool operator!=(const AggregateBoundingInfo& rhs) { 00111 return (centerOffset != rhs.centerOffset || centerBoundsRadius != rhs.centerBoundsRadius || maxObjectRadius != rhs.maxObjectRadius); 00112 } 00113 00114 private: 00115 }; 00116 00117 inline std::ostream& operator <<(std::ostream& os, const AggregateBoundingInfo &rhs) { 00118 os << "< offset: " << rhs.centerOffset << ", center bounds radius: " << rhs.centerBoundsRadius << ", max object size: " << rhs.maxObjectRadius << ">"; 00119 return os; 00120 } 00121 00122 } // namespace Sirikata 00123 00124 #endif //_SIRIKATA_LIBCORE_AGGREGATE_BOUNDING_INFO_HPP_