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

bs.h

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 #ifndef SHEEP_MATH_BS_H
00024 #define SHEEP_MATH_BS_H
00025 
00026 #include "aabb3.h"
00027 #include "point3.h"
00028 #include "real.h"
00029 #include "vector3.h"
00030 
00031 #include <cmath>
00032 #include <limits>
00033 
00034 namespace sheep {
00035 
00036     class BS {
00037     public:
00038         Point3 m_center;    //!< Center of the bounding sphere.
00039         Real m_radius;      //!< Radius of the bounding sphere.
00040 
00041         //! The value of this member is not computed until the ComputeSquareRadius()
00042         //! method is explicitly called by the user. It is done that way to be both
00043         //! flexible and efficient: if the value is required, it can be computed by
00044         //! calling the ComputeSquareRadius() method. If the value is not required,
00045         //! this member will be left undefined until the ComputeSquareRadius() method
00046         //! is called.
00047         Real m_radius2;     //!< Square of the radius of the bounding sphere.
00048 
00049         //! Invalidates the bounding sphere.
00050         //! Warning: the bounding sphere center is left undefined.
00051         BS();
00052 
00053         //! Warning: this constructor *does not* copy the value of the m_radius2 member,
00054         //! which is thus left undefined until the ComputeSquareRadius() method is called.
00055         BS(const BS &bs);
00056 
00057         //! Constructs a bounding sphere given its center. The new bounding sphere is
00058         //! invalidated (see the Invalidate() method for more details). The value of
00059         //! the m_radius2 member is left undefined until the ComputeSquareRadius()
00060         //! method is called.
00061         BS(const Point3 &center);
00062 
00063         //! Constructs a bounding sphere given its center and its radius. The value of
00064         //! the m_radius2 member is left undefined until the ComputeSquareRadius()
00065         //! method is called.
00066         BS(const Point3 &center, Real radius);
00067 
00068         //! Invalidates the bounding sphere (sets the bounding sphere radius to -1.0).
00069         //! The value of the m_radius2 member is left unchanged.
00070         void Invalidate();
00071 
00072         //! Computes the square radius of the bounding sphere and stores it in the
00073         //! m_radius2 member. This is the only one method that does access the
00074         //! m_radius2 member.
00075         void ComputeSquareRadius();
00076 
00077         //! None of the next methods changes the value or use the value of the
00078         //! m_radius2 member.
00079 
00080         void Include(const Point3 &point);
00081         void Include(const AABB3 &aabb);
00082         void Include(const BS &bs);
00083 
00084         bool Overlaps(const BS &bs) const;
00085         bool Contains(const Point3 &point) const;
00086     };
00087 
00088 #include "bs.inl"
00089 
00090 }
00091 
00092 #endif  // !SHEEP_MATH_BS_H

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