source: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Polyhedron.h @ 3020

Revision 3020, 2.5 KB checked in by mattausch, 16 years ago (diff)

removed most leaks

Line 
1#ifndef _POLYHEDRON_H__
2#define _POLYHEDRON_H__
3
4
5#include "common.h"
6#include "AxisAlignedBox3.h"
7#include "Polygon3.h"
8
9#include <iostream>
10
11
12
13namespace CHCDemoEngine
14{
15
16class Plane3;
17class AxisAlignedBox3;
18class Vector3;
19
20
21/** Class representing a convex polyhedron.
22*/
23class Polyhedron
24{
25public:
26       
27        Polyhedron();
28        /** Copy constructor making a deep copy of the polygons.
29        */
30        Polyhedron(const Polyhedron &rhs);
31        /** Initialises the Polyhedron with the given polygons.
32                @NOTE The polygons are NOT duplicated, only
33                a shallow copy is used.
34        */     
35    Polyhedron(const PolygonContainer &polys);
36
37        ~Polyhedron();
38        /** Computes the intersection of the polyhedron with the given plane
39                and returns it as another polyhedron
40                @returns NULL if the geometry is not split by this plane
41        */
42        Polyhedron *CalcIntersection(const Plane3 &splitPlane) const;
43        /** Adds a polygon to the polyhedron.
44        */
45        //void Add(const Polygon3 &poly);
46       
47        void Add(Polygon3 *poly);
48
49        /** Computes bounding box of the geometry.
50        */
51        AxisAlignedBox3 GetBoundingBox() const;
52        /** Returns
53                1 if geometry in front of the plane
54                0 if plane intersects geometry,
55                -1 if geometry is behind the plane
56        */
57        int Side(const Plane3 &plane) const;
58        /** Returns true if this geometry is well shaped.
59        */
60        bool Valid() const;
61        /** Number of polygons.
62        */
63        int NumPolygons() const;
64        /** Returns the polygons in a container.
65        */
66        const PolygonContainer &GetPolygons() const;
67
68        float GetArea() const;
69
70        float GetVolume() const;
71
72        Vector3 CenterOfMass() const;
73        /** Returns all the vertices of this polyhedron
74        */
75        void CollectVertices(VertexArray &vertices) const;
76        /** Computes polyhedron from a couple of intersecting planes and a bounding box.
77        */
78        static Polyhedron *CreatePolyhedron(const std::vector<Plane3> &planes, const AxisAlignedBox3 &box);
79
80        inline friend std::ostream &operator<<(std::ostream &s, const Polyhedron &a);
81
82
83protected:
84
85        /** Splits the given polygon with the polyhedron
86                Returns the part of the polygon inside of the polyhedron.
87        */
88        Polygon3 *SplitPolygon(Polygon3 *polygon) const;
89
90       
91       
92        ///////////////
93
94        /// the polygons
95        PolygonContainer mPolygons;
96        /// the bounding box
97        AxisAlignedBox3 mBox;
98};
99
100
101std::ostream &operator<<(std::ostream &s, const Polyhedron &a)
102{
103        PolygonContainer::const_iterator it, it_end = a.mPolygons.end();
104
105        for (it = a.mPolygons.begin(); it != it_end; ++ it)
106                s << *(*it) << std::endl;
107        return s << std::endl;
108}
109
110
111}
112
113#endif
Note: See TracBrowser for help on using the repository browser.