-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBoundingBox.cpp
More file actions
101 lines (87 loc) · 1.85 KB
/
BoundingBox.cpp
File metadata and controls
101 lines (87 loc) · 1.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
//
// BoundingBox.cpp
// Week 08 - Earshooter
#include <cfloat>
#include "glPlatform.h"
#include "BoundingBox.h"
using namespace earshooter;
ColorIndex BoundingBox::defaultColor_ = ColorIndex::RED;
BoundingBox::BoundingBox(float xmin, float xmax, float ymin, float ymax,
ColorIndex color)
: xmin_(xmin),
xmax_(xmax),
ymin_(ymin),
ymax_(ymax),
color_(color)
{
}
BoundingBox::BoundingBox(const WorldPoint& cornerUL, const WorldPoint& cornerLR,
ColorIndex color)
: xmin_(cornerUL.x),
xmax_(cornerLR.x),
ymin_(cornerUL.y),
ymax_(cornerLR.y),
color_(color)
{
}
BoundingBox::BoundingBox(ColorIndex color)
: xmin_(FLT_MAX),
xmax_(FLT_MAX),
ymin_(FLT_MAX),
ymax_(FLT_MAX),
color_(color)
{
}
void BoundingBox::setDimensions(float xmin, float xmax, float ymin, float ymax)
{
xmin_ = xmin;
xmax_ = xmax;
ymin_ = ymin;
ymax_ = ymax;
}
void BoundingBox::setDimensions(const WorldPoint& cornerUL, const WorldPoint& cornerLR)
{
xmin_ = cornerUL.x;
xmax_ = cornerLR.x;
ymin_ = cornerUL.y;
ymax_ = cornerLR.y;
}
void BoundingBox::draw(void) const
{
// glPushMatrix();
if (color_ != ColorIndex::NO_COLOR)
{
glColor4fv(COLOR[static_cast<int>(color_)]);
}
else
{
glColor4fv(COLOR[static_cast<int>(defaultColor_)]);
}
// const GLfloat worldToPixel = World::getWorldToPixel();
// glScalef(worldToPixel, worldToPixel, worldToPixel);
glBegin(GL_LINE_LOOP);
glVertex2f(xmin_, ymin_);
glVertex2f(xmax_, ymin_);
glVertex2f(xmax_, ymax_);
glVertex2f(xmin_, ymax_);
glEnd();
// glPopMatrix();
}
WorldPoint BoundingBox::getCornerUL(void) const
{
WorldPoint pt = {xmin_, ymax_};
return pt;
}
WorldPoint BoundingBox::getCornerLR(void) const
{
WorldPoint pt = {xmax_, ymin_};
return pt;
}
void BoundingBox::setColor(ColorIndex color)
{
color_ = color;
}
void BoundingBox::setDefaultColor(ColorIndex color)
{
defaultColor_ = color;
}