00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #ifndef __SGL_POLYTOPE_HPP
00028 #define __SGL_POLYTOPE_HPP
00029
00030 #include <sgl.h>
00031 #include <sglPlane.hpp>
00032
00033 #define SGL_MAX_PLANE_PER_POLYTOPE 6
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045 template <class T> class sglPolytope;
00046
00047 typedef sglPolytope<float> sglPolytopef;
00048 typedef sglPolytope<double> sglPolytoped;
00049
00050
00051
00052 template <class T>
00053 class sglPolytope
00054 {
00055 public:
00056 sglPolytope() : m_num_planes(0) {};
00057
00058 template <class S>
00059 sglPolytope(const sglPolytope<S> &rhs)
00060 {
00061 m_num_planes = rhs.getNumPlanes();
00062 for (unsigned int i=0; i<m_num_planes; i++)
00063 m_plane[i] = rhs.getPlane(i);
00064 }
00065
00066 virtual ~sglPolytope() {};
00067
00068 template <class S>
00069 sglPolytope &operator=(const sglPolytope<S> &rhs)
00070 {
00071 if (this != (sglPolytope<T>*)&rhs)
00072 {
00073 m_num_planes = rhs.getNumPlanes();
00074 for (unsigned int i=0; i<m_num_planes; i++)
00075 m_plane[i] = rhs.getPlane(i);
00076 }
00077 return *this;
00078 }
00079
00080 inline unsigned int getNumPlanes(void) const
00081 {
00082 return m_num_planes;
00083 }
00084 inline const sglPlane<T> &getPlane(unsigned int i) const
00085 {
00086 return m_plane[i];
00087 }
00088 void addPlane(sglPlane<T> &plane)
00089 {
00090 if (m_num_planes < SGL_MAX_PLANE_PER_POLYTOPE)
00091 m_plane[m_num_planes++] = plane;
00092 }
00093
00094
00095 template <class S>
00096 inline void mul(const sglPolytope<T>& p, const sglMat3<S>& m)
00097 {
00098 for (unsigned int i=0; i<p.getNumPlanes(); i++)
00099 m_plane[i].mul(p.getPlane(i),m);
00100
00101 m_num_planes = p.getNumPlanes();
00102 }
00103
00104
00105 template <class S>
00106 inline void mul(const sglPolytope<T>& p, const sglMat4<S>& m)
00107 {
00108 for (unsigned int i=0; i< p.getNumPlanes(); i++)
00109 m_plane[i].mul(p.getPlane(i),m);
00110
00111 m_num_planes = p.getNumPlanes();
00112 }
00113
00114
00115 inline void translate(const sglPolytope<T>& p, T x, T y, T z)
00116 {
00117 for (unsigned int i=0; i<p.getNumPlanes(); i++)
00118 m_plane[i].translate(p.getPlane(i), x, y, z);
00119
00120 m_num_planes = p.getNumPlanes();
00121 }
00122
00123
00124 inline void scale(const sglPolytope<T>& p, T scale)
00125 {
00126 for (unsigned int i=0; i<p.getNumPlanes(); i++)
00127 m_plane[i].scale(p.getPlane(i), scale);
00128
00129 m_num_planes = p.getNumPlanes();
00130 }
00131
00132
00133 template <class S>
00134 inline void rotate(const sglPolytope<T>& p, const sglMat4<S>& m)
00135 {
00136 for (unsigned int i=0; i< p.getNumPlanes(); i++)
00137 m_plane[i].rotate(p.getPlane(i),m);
00138
00139 m_num_planes = p.getNumPlanes();
00140 }
00141 template <class S>
00142 inline void rotate(const sglPolytope<T>& p, const sglMat3<S>& m)
00143 {
00144 for (unsigned int i=0; i< p.getNumPlanes(); i++)
00145 m_plane[i].rotate(p.getPlane(i),m);
00146
00147 m_num_planes = p.getNumPlanes();
00148 }
00149
00150 friend ostream& operator<<(ostream& ostrm, const sglPolytope<T>& p)
00151 {
00152 ostrm << "[" << p.getNumPlanes() << " planes, ";
00153
00154 for (unsigned int i=0; i<p.getNumPlanes(); ++i)
00155 {
00156 ostrm << " plane " << i << ": " << p.getPlane(i) << ",";
00157 }
00158 return ostrm;
00159 }
00160
00161 protected:
00162
00163 unsigned int m_num_planes;
00164 sglPlane<T> m_plane[SGL_MAX_PLANE_PER_POLYTOPE];
00165 };
00166
00167 #endif