14 #ifndef hifi_CubeProjectedPolygon_h
15 #define hifi_CubeProjectedPolygon_h
17 #include <glm/glm.hpp>
20 const int MAX_PROJECTED_POLYGON_VERTEX_COUNT = 6;
21 const int MAX_CLIPPED_PROJECTED_POLYGON_VERTEX_COUNT = MAX_PROJECTED_POLYGON_VERTEX_COUNT * 2;
22 typedef glm::vec2 ProjectedVertices[MAX_CLIPPED_PROJECTED_POLYGON_VERTEX_COUNT];
24 class BoundingRectangle {
26 enum { BOTTOM_LEFT, BOTTOM_RIGHT, TOP_RIGHT, TOP_LEFT, VERTEX_COUNT };
28 BoundingRectangle(
const glm::vec2 corner,
const glm::vec2 size) : corner(corner), size(size), _set(true) {}
29 BoundingRectangle() : _set(false) {}
32 bool contains(
const BoundingRectangle& box)
const;
33 bool contains(
const glm::vec2& point)
const;
34 bool pointInside(
const glm::vec2& point)
const {
return contains(point); }
36 void explandToInclude(
const BoundingRectangle& box);
38 float area()
const {
return size.x * size.y; }
40 int getVertexCount()
const {
return VERTEX_COUNT; }
41 glm::vec2 getVertex(
int vertexNumber)
const;
43 BoundingRectangle topHalf()
const;
44 BoundingRectangle bottomHalf()
const;
45 BoundingRectangle leftHalf()
const;
46 BoundingRectangle rightHalf()
const;
48 float getMaxX()
const {
return corner.x + size.x; }
49 float getMaxY()
const {
return corner.y + size.y; }
50 float getMinX()
const {
return corner.x; }
51 float getMinY()
const {
return corner.y; }
53 void printDebugDetails(
const char* label=NULL)
const;
58 const int PROJECTION_RIGHT = 1;
59 const int PROJECTION_LEFT = 2;
60 const int PROJECTION_BOTTOM = 4;
61 const int PROJECTION_TOP = 8;
62 const int PROJECTION_NEAR = 16;
63 const int PROJECTION_FAR = 32;
64 const int PROJECTION_CLIPPED = 64;
66 class CubeProjectedPolygon {
69 CubeProjectedPolygon(
const BoundingRectangle& box);
71 CubeProjectedPolygon(
int vertexCount = 0) :
72 _vertexCount(vertexCount),
73 _maxX(-FLT_MAX), _maxY(-FLT_MAX), _minX(FLT_MAX), _minY(FLT_MAX),
77 ~CubeProjectedPolygon() { }
78 const ProjectedVertices& getVertices()
const {
return _vertices; }
79 const glm::vec2& getVertex(
int i)
const {
return _vertices[i]; }
80 void setVertex(
int vertex,
const glm::vec2& point);
82 int getVertexCount()
const {
return _vertexCount; }
83 float getDistance()
const {
return _distance; }
84 bool getAnyInView()
const {
return _anyInView; }
85 bool getAllInView()
const {
return _allInView; }
86 unsigned char getProjectionType()
const {
return _projectionType; }
87 void setVertexCount(
int vertexCount) { _vertexCount = vertexCount; }
88 void setDistance(
float distance) { _distance = distance; }
89 void setAnyInView(
bool anyInView) { _anyInView = anyInView; }
90 void setAllInView(
bool allInView) { _allInView = allInView; }
91 void setProjectionType(
unsigned char type) { _projectionType = type; }
94 bool pointInside(
const glm::vec2& point,
bool* matchesVertex = NULL)
const;
95 bool occludes(
const CubeProjectedPolygon& occludee,
bool checkAllInView =
false)
const;
96 bool occludes(
const BoundingRectangle& occludee)
const;
97 bool intersects(
const CubeProjectedPolygon& testee)
const;
98 bool intersects(
const BoundingRectangle& box)
const;
99 bool matches(
const CubeProjectedPolygon& testee)
const;
100 bool matches(
const BoundingRectangle& testee)
const;
101 bool intersectsOnAxes(
const CubeProjectedPolygon& testee)
const;
103 bool canMerge(
const CubeProjectedPolygon& that)
const;
104 void merge(
const CubeProjectedPolygon& that);
106 float getMaxX()
const {
return _maxX; }
107 float getMaxY()
const {
return _maxY; }
108 float getMinX()
const {
return _minX; }
109 float getMinY()
const {
return _minY; }
111 BoundingRectangle getBoundingBox()
const {
112 return BoundingRectangle(glm::vec2(_minX,_minY), glm::vec2(_maxX - _minX, _maxY - _minY));
115 void printDebugDetails()
const;
117 static long pointInside_calls;
118 static long occludes_calls;
119 static long intersects_calls;
123 ProjectedVertices _vertices;
131 unsigned char _projectionType;