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
|
#include "Element.h"
Element::Element() {}
Element::~Element() {}
void Element::SetPosition(const wxPoint2DDouble position)
{
m_position = position;
m_rect =
wxRect2DDouble(m_position.m_x - m_width / 2.0 - m_borderSize, m_position.m_y - m_height / 2.0 - m_borderSize,
m_width + 2.0 * m_borderSize, m_height + 2.0 * m_borderSize);
}
wxPoint2DDouble Element::WorldToScreen(wxPoint2DDouble translation, double scale, double offsetX, double offsetY) const
{
return wxPoint2DDouble(m_position.m_x + offsetX + translation.m_x, m_position.m_y + offsetY + translation.m_y) *
scale;
}
void Element::DrawCircle(wxPoint2DDouble position, double radius, int numSegments, GLenum mode) const
{
glBegin(mode);
for(int i = 0; i < numSegments; i++) {
double theta = 2.0 * 3.1415926 * double(i) / double(numSegments);
glVertex2f(radius * std::cos(theta) + position.m_x, radius * std::sin(theta) + position.m_y);
}
glEnd();
}
void Element::DrawRectangle(wxPoint2DDouble position, double width, double height, GLenum mode) const
{
glBegin(mode); // TODO: GL_QUADS é obsoleto (OpenGL 3.0+), encontrar outra solução.
glVertex2d(position.m_x - width / 2.0, position.m_y - height / 2.0);
glVertex2d(position.m_x - width / 2.0, position.m_y + height / 2.0);
glVertex2d(position.m_x + width / 2.0, position.m_y + height / 2.0);
glVertex2d(position.m_x + width / 2.0, position.m_y - height / 2.0);
glEnd();
}
void Element::DrawRectangle(wxPoint2DDouble* points, GLenum mode) const
{
glBegin(mode); // TODO: GL_QUADS é obsoleto (OpenGL 3.0+), encontrar outra solução.
glVertex2d(points[0].m_x, points[0].m_y);
glVertex2d(points[1].m_x, points[1].m_y);
glVertex2d(points[2].m_x, points[2].m_y);
glVertex2d(points[3].m_x, points[3].m_y);
glEnd();
}
void Element::DrawPickbox(wxPoint2DDouble position) const
{
glColor4d(1.0, 1.0, 1.0, 0.8);
DrawRectangle(position, 8.0, 8.0);
glColor4d(0.0, 0.0, 0.0, 1.0);
DrawRectangle(position, 8.0, 8.0, GL_LINE_LOOP);
}
wxPoint2DDouble Element::RotateAtPosition(wxPoint2DDouble pointToRotate, double angle, bool degrees) const
{
double radAngle = angle;
if(degrees) radAngle = wxDegToRad(angle);
return wxPoint2DDouble(std::cos(radAngle) * (pointToRotate.m_x - m_position.m_x) -
std::sin(radAngle) * (pointToRotate.m_y - m_position.m_y) + m_position.m_x,
std::sin(radAngle) * (pointToRotate.m_x - m_position.m_x) +
std::cos(radAngle) * (pointToRotate.m_y - m_position.m_y) + m_position.m_y);
}
|