forked from FranciscoBiaso/TileMapEditorRealmz
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGLRect.cpp
102 lines (85 loc) · 2.59 KB
/
GLRect.cpp
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
102
#include "GLRect.h"
#include "MapResources.h"
extern data::MapResources* gResources;
GLRect::GLRect(){}
GLRect::GLRect(glm::vec3 leftTop, glm::vec3 bottomRight, glm::vec4 color)
{
glm::vec3 A = leftTop;
glm::vec3 B = leftTop - glm::vec3(0, glm::abs(leftTop.y - bottomRight.y), 0);
glm::vec3 C = bottomRight;
glm::vec3 D = leftTop + glm::vec3(glm::abs(leftTop.x - bottomRight.x), 0, 0);
T1 = GLTriangle(A, B, D);
T2 = GLTriangle(B, C, D);
setColor(color);
}
GLRect::GLRect(glm::vec3 leftTop, float side, glm::vec4 color)
{
// Opengl Coords //
/*
U
(0,0) ---------> 1
|
V|
|
v
1
*/
updatePosition(leftTop, side);
setColor(color);
}
void GLRect::setColor(glm::vec4 a, glm::vec4 b, glm::vec4 c, glm::vec4 d)
{
this->T1.setColor(a, b, d);
this->T2.setColor(b, c, d);
}
void GLRect::setTextCoord(int u, int v, int w, int h)
{
if (w == -1 && h == -1)
{
w = gdk_pixbuf_get_width(gResources->getImgPack().getTextureAtlas()->getPixelbuf());
h = gdk_pixbuf_get_height(gResources->getImgPack().getTextureAtlas()->getPixelbuf());
}
float x_left = (u * REALMZ_GRID_SIZE) / (float)w;
float x_right = (u * REALMZ_GRID_SIZE + REALMZ_GRID_SIZE) / (float)w;
float y_top = (v * REALMZ_GRID_SIZE) / (float)h;
float y_bot = (v * REALMZ_GRID_SIZE + REALMZ_GRID_SIZE) / (float)h;
T1.setTextCoord(glm::vec2(x_left, y_top), glm::vec2(x_left, y_bot), glm::vec2(x_right, y_top));
T2.setTextCoord(glm::vec2(x_left, y_bot), glm::vec2(x_right, y_bot), glm::vec2(x_right, y_top));
}
void GLRect::setCoordZ(float z)
{
T1.setCoordZ(z);
T2.setCoordZ(z);
}
void GLRect::setTextCoord(glm::vec2 coords)
{
setTextCoord(coords.x, coords.y);
}
void GLRect::updatePosition(glm::vec3 leftTop, float topSide, float leftSide)
{
if (leftSide == 0)
leftSide = topSide;
glm::vec3 A = leftTop;
glm::vec3 B = leftTop + glm::vec3(0, -leftSide, 0);
glm::vec3 C = leftTop + glm::vec3(+topSide, -leftSide, 0);
glm::vec3 D = leftTop + glm::vec3(topSide, 0, 0);
T1 = GLTriangle(A, B, D);
T2 = GLTriangle(B, C, D);
}
void GLRect::reset_textcoord(float val)
{
T1.A_text_coord = glm::vec2(val, val);
T1.B_text_coord = glm::vec2(val, val);
T1.C_text_coord = glm::vec2(val, val);
T2.A_text_coord = glm::vec2(val, val);
T2.B_text_coord = glm::vec2(val, val);
T2.C_text_coord = glm::vec2(val, val);
}
void GLRect::setColor(glm::vec4 color)
{
setColor(color, color, color, color);
}
void GLRect::reset_color()
{
setColor(glm::vec4(0, 0, 0, 0));
}