Stellarium 0.14.3
Polyhedron.hpp
1 /*
2  * Stellarium Scenery3d Plug-in
3  *
4  * Copyright (C) 2011 Simon Parzer, Peter Neubauer, Georg Zotti, Andrei Borza
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA.
19  */
20 
24 #ifndef _POLYHEDRON_HPP_
25 #define _POLYHEDRON_HPP_
26 
27 #include "Frustum.hpp"
28 #include "Plane.hpp"
29 #include "SPolygon.hpp"
30 
32 {
33 public:
34  Polyhedron();
35  ~Polyhedron();
36 
38  QVector<SPolygon> polygons;
39 
41  void add(const Frustum& f);
43  void add(const SPolygon& p);
45  void add(const QVector<Vec3f> &verts, const Vec3f &normal);
46 
48  void intersect(const AABB &bb);
50  void intersect(const Plane &p);
52  void extrude(const Vec3f &dir, const AABB &bb);
54  void clear();
56  int getVertCount() const;
58  const QVector<Vec3f> &getVerts() const;
60  void makeUniqueVerts();
61 
62  void render() const;
63 
67 private:
69  QVector<Vec3f> uniqueVerts;
71  void addUniqueVert(const Vec3f &v);
73  void intersect(const Line &l, const Vec3f &min, const Vec3f &max, QVector<Vec3f> &vertices);
75  bool clip(float p, float q, float &u1, float &u2) const;
76 };
77 
78 #endif
void clear()
Clear up.
void makeUniqueVerts()
Makes the unique vertices vector.
QVector< SPolygon > polygons
Vector holding all polygons of this polyhedron.
Definition: Polyhedron.hpp:38
Definition: Line.hpp:26
This implementation is based on Stingl's Robust Hard Shadows.
Definition: Polyhedron.hpp:31
Definition: Plane.hpp:27
const QVector< Vec3f > & getVerts() const
Returns the unique vertices.
int getVertCount() const
Returns the unique vertices count.
void add(const Frustum &f)
Adds a frustum to this polyhedron.
An axis-aligned bounding-box class.
Definition: AABB.hpp:42
Box debugBox
This is used for debugging of the crop matrix It contains the world-space representation of the ortho...
Definition: Polyhedron.hpp:66
A simple "box" class with 8 arbitrary vertices.
Definition: AABB.hpp:28
void extrude(const Vec3f &dir, const AABB &bb)
Extrude each point of this polyhedron towards direction until we hit the bounding box...
void intersect(const AABB &bb)
Intersect this polyhedron with the specified bounding box.