Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

aabb3.inl

Go to the documentation of this file.
00001 /*
00002     Sheep - A Rigid Body Dynamics Engine
00003     Copyright (C) 2001-2004 Francois Beaune
00004     Contact: http://toxicengine.sourceforge.net/
00005 
00006     This file is part of Sheep.
00007 
00008     Sheep is free software; you can redistribute it and/or modify
00009     it under the terms of the GNU General Public License as published by
00010     the Free Software Foundation; either version 2 of the License, or
00011     (at your option) any later version.
00012 
00013     Sheep is distributed in the hope that it will be useful,
00014     but WITHOUT ANY WARRANTY; without even the implied warranty of
00015     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016     GNU General Public License for more details.
00017 
00018     You should have received a copy of the GNU General Public License
00019     along with Sheep; if not, write to the Free Software
00020     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00021 */
00022 
00023 inline
00024 AABB3::AABB3() {
00025     Invalidate();
00026 }
00027 
00028 inline
00029 AABB3::AABB3(const AABB3 &aabb) :
00030     m_min(aabb.m_min),
00031     m_max(aabb.m_max) {}
00032 
00033 inline
00034 AABB3::AABB3(const Point3 &min, const Point3 &max) :
00035     m_min(min),
00036     m_max(max) {}
00037 
00038 inline
00039 AABB3 AABB3::Biggest() {
00040     return AABB3(
00041         Point3(-std::numeric_limits<Real>::max()),
00042         Point3(std::numeric_limits<Real>::max())
00043     );
00044 }
00045 
00046 inline
00047 void AABB3::Invalidate() {
00048     m_min = Point3(std::numeric_limits<Real>::max());
00049     m_max = Point3(-std::numeric_limits<Real>::max());
00050 }
00051 
00052 inline
00053 bool AABB3::IsValid() const {
00054     return
00055         m_min.m_x <= m_max.m_x &&
00056         m_min.m_y <= m_max.m_y &&
00057         m_min.m_z <= m_max.m_z;
00058 }
00059 
00060 inline
00061 void AABB3::Include(const Point3 &point) {
00062     if(point.m_x < m_min.m_x) m_min.m_x = point.m_x;
00063     if(point.m_x > m_max.m_x) m_max.m_x = point.m_x;
00064     if(point.m_y < m_min.m_y) m_min.m_y = point.m_y;
00065     if(point.m_y > m_max.m_y) m_max.m_y = point.m_y;
00066     if(point.m_z < m_min.m_z) m_min.m_z = point.m_z;
00067     if(point.m_z > m_max.m_z) m_max.m_z = point.m_z;
00068 }
00069 
00070 inline
00071 void AABB3::Include(const AABB3 &aabb) {
00072     if(aabb.m_min.m_x < m_min.m_x) m_min.m_x = aabb.m_min.m_x;
00073     if(aabb.m_min.m_y < m_min.m_y) m_min.m_y = aabb.m_min.m_y;
00074     if(aabb.m_min.m_z < m_min.m_z) m_min.m_z = aabb.m_min.m_z;
00075     if(aabb.m_max.m_x > m_max.m_x) m_max.m_x = aabb.m_max.m_x;
00076     if(aabb.m_max.m_y > m_max.m_y) m_max.m_y = aabb.m_max.m_y;
00077     if(aabb.m_max.m_z > m_max.m_z) m_max.m_z = aabb.m_max.m_z;
00078 }
00079 
00080 inline
00081 void AABB3::Intersect(const AABB3 &aabb) {
00082     if(aabb.m_min.m_x > m_min.m_x) m_min.m_x = aabb.m_min.m_x;
00083     if(aabb.m_min.m_y > m_min.m_y) m_min.m_y = aabb.m_min.m_y;
00084     if(aabb.m_min.m_z > m_min.m_z) m_min.m_z = aabb.m_min.m_z;
00085     if(aabb.m_max.m_x < m_max.m_x) m_max.m_x = aabb.m_max.m_x;
00086     if(aabb.m_max.m_y < m_max.m_y) m_max.m_y = aabb.m_max.m_y;
00087     if(aabb.m_max.m_z < m_max.m_z) m_max.m_z = aabb.m_max.m_z;
00088 }
00089 
00090 inline
00091 bool AABB3::Overlaps(const AABB3 &aabb) const {
00092     return !(
00093         aabb.m_max.m_x <= m_min.m_x ||
00094         aabb.m_min.m_x >= m_max.m_x ||
00095         aabb.m_max.m_y <= m_min.m_y ||
00096         aabb.m_min.m_y >= m_max.m_y ||
00097         aabb.m_max.m_z <= m_min.m_z ||
00098         aabb.m_min.m_z >= m_max.m_z);
00099 }
00100 
00101 inline
00102 bool AABB3::Contains(const Point3 &point) const {
00103     return
00104         point.m_x >= m_min.m_x &&
00105         point.m_x <= m_max.m_x &&
00106         point.m_y >= m_min.m_y &&
00107         point.m_y <= m_max.m_y &&
00108         point.m_z >= m_min.m_z &&
00109         point.m_z <= m_max.m_z;
00110 }
00111 
00112 inline
00113 Point3 AABB3::GetCenter() const {
00114     return 0.5 * (m_min + m_max);
00115 }
00116 
00117 inline
00118 Vector3 AABB3::GetSize() const {
00119     return m_max - m_min;
00120 }
00121 
00122 inline
00123 void AABB3::Scale(const Vector3 &scale) {
00124     const Point3 center = 0.5 * (m_min + m_max);
00125     const Vector3 delta = m_max - center;
00126 
00127     const Vector3 shift(
00128         scale.m_x * delta.m_x,
00129         scale.m_y * delta.m_y,
00130         scale.m_z * delta.m_z);
00131 
00132     m_min = center - shift;
00133     m_max = center + shift;
00134 }
00135 
00136 inline
00137 void AABB3::Extend(const Vector3 &ext) {
00138     m_min -= ext;
00139     m_max += ext;
00140 }

Generated on Tue May 11 01:31:49 2004 for toxic by doxygen 1.3.6