source: trunk/VUT/GtpVisibilityPreprocessor/src/Polygon3.h @ 256

Revision 256, 1.9 KB checked in by bittner, 19 years ago (diff)
Line 
1#ifndef _Polygon3_h__
2#define _Polygon3_h__
3
4
5//#include <iostream>
6//#include <math.h>
7//#include "common.h"
8#include "Containers.h"
9#include "Mesh.h"
10
11class Polygon3;
12class Plane3;
13class Face;
14
15/** Container storing polygons used during BSP tree construction
16*/
17typedef vector<Polygon3 *> PolygonContainer;
18
19/** Class representing a general planar polygon in 3d.
20*/
21class Polygon3
22{
23public:
24        Polygon3();
25        Polygon3(const VertexContainer &vertices);
26
27        /** Copies all the vertices of the face.
28        */
29        Polygon3(Face *face, Mesh *parent);
30       
31        /** Returns supporting plane of this polygon.
32        */
33        Plane3 GetSupportingPlane() const;
34
35        /** Splits polygon.
36                @param partition the split plane
37                @param front the front polygon
38                @param back the back polygon
39                @param splits number of splits
40        */
41        void Split(Plane3 *partition, Polygon3 *front, Polygon3 *back, int &splits);
42
43        enum {BACK_SIDE, FRONT_SIDE, SPLIT, COINCIDENT};
44
45        /** Classify polygon with respect to the plane.
46            @returns one of BACK_SIDE, FRONT_SIDE, SPLIT, COINCIDENT
47        */
48        int ClassifyPlane(const Plane3 &plane) const;
49
50        /** Side of the polygon with respect to the plane.
51                @returns 1 if on front side, -1 if on back side, 0 else.
52        */
53        int Side(const Plane3 &plane) const;
54
55        /** Scales the polygon about its center
56        */
57        void Scale(const float scale);
58       
59        /** Computes the center of mass of the polygon
60         */
61        Vector3 Center() const;
62
63               
64        /** Deletes all polygons om the queue.
65        */
66        static void DeletePolygons(PolygonContainer *polys);
67
68        /// vertices are connected in counterclockwise order.
69        VertexContainer mVertices;
70
71        /// we can also store materials with polygons
72        Material *mMaterial;
73};
74
75// Overload << operator for C++-style output
76inline ostream&
77operator<< (ostream &s, const Polygon3 &A)
78{
79        VertexContainer::const_iterator it;
80
81        s << "Polygon:\n";
82       
83        for (it = A.mVertices.begin(); it != A.mVertices.end(); ++it)
84                s << *it << endl;
85       
86        return s;
87}
88
89
90#endif
Note: See TracBrowser for help on using the repository browser.