Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members  

shape.h

00001 // shape.h (A general base class for shapes)
00002 //
00003 //  The WorldForge Project
00004 //  Copyright (C) 2001  The WorldForge Project
00005 //
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 2 of the License, or
00009 //  (at your option) any later version.
00010 //
00011 //  This program is distributed in the hope that it will be useful,
00012 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 //  GNU General Public License for more details.
00015 //
00016 //  You should have received a copy of the GNU General Public License
00017 //  along with this program; if not, write to the Free Software
00018 //  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00019 //
00020 //  For information about WorldForge and its authors, please contact
00021 //  the Worldforge Web Site at http://www.worldforge.org.
00022 //
00023 
00024 // Author: Ron Steinke
00025 
00026 // This class borrows heavily from the base shape class in libCoal,
00027 // plus certain intersection ideas from stage/shepherd/sylvanus
00028 
00029 
00030 #ifndef WFMATH_SHAPE_H
00031 #define WFMATH_SHAPE_H
00032 
00033 #include <wfmath/vector.h>
00034 #include <wfmath/point.h>
00035 #include <wfmath/const.h>
00036 #include <wfmath/rotmatrix.h>
00037 #include <wfmath/axisbox.h>
00038 #include <wfmath/ball.h>
00039 #include <wfmath/intersect_decls.h>
00040 
00041 namespace WFMath {
00042 
00044 
00055 template<const int dim>
00056 class Shape
00057 {
00058  public:
00059   // The first things in the Shape class are the functions required
00060   // by CLASS_LAYOUT for all classes
00061 
00063   Shape() {}
00065   Shape(const Shape<dim>& s) {}
00067   ~Shape() {}
00068 
00070   friend std::ostream& operator<< <dim>(std::ostream& os, const Shape& s);
00072   friend std::istream& operator>> <dim>(std::istream& is, Shape& s);
00073 
00075   Shape& operator=(const Shape& a);
00076 
00078   bool isEqualTo(const Shape& s, double tolerance = WFMATH_EPSILON) const;
00080   bool operator==(const Shape& s) const {return isEqualTo(s);}
00082   bool operator!=(const Shape& s) const {return !isEqualTo(s);}
00083 
00085   bool isValid() const {return m_valid;}
00086 
00088 
00092   bool operator< (const Shape& a) const;
00093 
00094   // Now we begin with the functions in the shape interface
00095 
00096   // Descriptive characteristics
00097 
00099 
00102   int numCorners() const; // The number of corners, returns zero for Ball<>
00104   Point<dim> getCorner(int i) const; // Must have i >= 0 && i < numCorners()
00106   Point<dim> getCenter() const; // Returns the barycenter of the object
00107 
00108   // Movement functions
00109 
00111   Shape& shift(const Vector<dim>& v); // Move the shape a certain distance
00113 
00116   Shape& moveCornerTo(const Point<dim>& p, int corner)
00117         {return shift(p - getCorner(corner));}
00119 
00122   Shape& moveCenterTo(const Point<dim>& p)
00123         {return shift(p - getCenter());}
00124 
00125 
00127 
00130   Shape& rotateCorner(const RotMatrix<dim>& m, int corner)
00131         {return rotatePoint(m, getCorner(corner));}
00133 
00136   Shape& rotateCenter(const RotMatrix<dim>& m)
00137         {return rotatePoint(m, getCenter());}
00139 
00143   Shape& rotatePoint(const RotMatrix<dim>& m, const Point<dim>& p);
00144 
00145   // Intersection functions
00146 
00148   AxisBox<dim> boundingBox() const;
00150   Ball<dim> boundingSphere() const;
00153 
00160   Ball<dim> boundingSphereSloppy() const;
00161 
00163 
00171   friend bool Intersect<dim>(Shape<dim>& s1, Shape<dim>& s2, bool proper);
00173 
00187   friend bool Contains<dim>(Shape<dim>& s1, Shape<dim>& s2, bool proper);
00188 
00189  private:
00190   bool m_valid;
00191 };
00192 
00193 //#include<wfmath/shape_funcs.h>
00194 
00195 } // namespace WFMath
00196 
00197 #endif  // WFMATH_SHAPE_H

Generated on Wed May 28 09:20:32 2003 for WFMath by doxygen1.3-rc3