00001
00006 #ifndef POLYGON_H
00007 #define POLYGON_H
00008
00009
00010
00011
00012
00013
00014 #include <map>
00015 #include "geom.h"
00016 #include "ray.h"
00017 #include "lang.h"
00018
00019
00020
00021
00022
00023
00024
00025 typedef Vector3Array Vertices;
00026
00027 class Polygon;
00028
00029 typedef std::vector<Polygon *> PolygonArray;
00030
00031
00033
00040 class Polygon {
00041
00042 public:
00044 Polygon (int n);
00045
00047 Polygon(const Polygon &p);
00048
00050 int n_vertices() const;
00051
00053 Vector3 &vertex(int index) const;
00054
00056 void dispose(int index);
00057
00059 virtual void transform(const AffineTransform &t);
00061 virtual void homoxform(const PerspectiveTransform &t);
00062
00064 virtual Vector3 normal() const;
00066 virtual Vector3 centroid();
00067
00068 private :
00069
00071 Vertices *vertices;
00072
00074 void init(int n);
00075
00076 };
00077
00078 inline void
00079 Polygon::init(int n)
00080 {
00081 vertices = new Vertices(n);
00082 }
00083
00084 inline
00085 Polygon::Polygon(int n)
00086 {
00087 init(n);
00088 }
00089
00090 inline
00091 Polygon::Polygon(const Polygon &p)
00092 {
00093 init(n);
00094 int i;
00095 for (i = 0; i < vertices.size(); i++)
00096 vertices(i) = p.vertex(i);
00097 }
00098
00099 inline int
00100 Polygon::n_vertices() const
00101 {
00102 return vertices.size();
00103 }
00104
00105 inline Vector &
00106 Polygon::vertex(int index) const
00107 {
00108 return vertices.at(index);
00109 }
00110
00111 inline void
00112 Polygon::dispose(int index)
00113 {
00114
00115 }
00116
00117 #endif //POLYGON_H