-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTile.cpp
96 lines (70 loc) · 1.97 KB
/
Tile.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
/***
* @file Tile.cpp
* Tile type implementations
*/
// Copyright 2019 by Julio Albornoz <[email protected]>
// The License.txt file describes the conditions under which this software may be distributed.
#include "Tile.h"
#include <math.h>
#define PI 3.141592653589793
Square_Tile::Square_Tile(int scale){
int R = scale;
this->scale = R;
X = R;
Y = R;
directions = {{0, glm::vec2(0.0, R)},
{1, glm::vec2(R,0.0)},
{2, glm::vec2(0.0, -R)},
{3,glm::vec2(-R, 0.0)}};
offset = {{'R', 1}, {'L', -1}, {'U', 0}, {'D', 2}};
}
void Square_Tile::compile(glm::vec3* color){
int TileID = glGenLists(1);
float k = (float)scale / 2.0f;
glm::vec3 n_col = *color / 255.0f; //Color Normalization
float* p_col = glm::value_ptr(n_col); //Cast to float array
//------------------------------------
glNewList(TileID, GL_COMPILE);
glPushMatrix();
glBegin(GL_QUADS);
glColor3fv(p_col);
glVertex2f(-k, -k);
glVertex2f(-k, k);
glVertex2f(k, k);
glVertex2f(k, -k);
glEnd();
glPopMatrix();
glEndList();
}
Hexagon_Tile::Hexagon_Tile(int scale){
this->scale = scale;
float R = (float)this->scale / 2.0f;
int r = (int)(R * cos(PI / 6.0f));
int d = (int)(3.0f*R/2.0f);
X = 2*d;
Y = 2*r;
directions = {{0, glm::vec2(0.0f, 2*r)},
{1, glm::vec2(d,r)},
{2, glm::vec2(d, -r)},
{3, glm::vec2(0.0f, -2*r)},
{4, glm::vec2(-d,-r)},
{5, glm::vec2(-d, r)}};
offset = {{'R', 1}, {'S',2}, {'L',-1}, {'M',-2}, {'T',0}, {'B',3}};
}
void Hexagon_Tile::compile(glm::vec3 *color){
int TileID = glGenLists(1);
float R = (float)(scale / 2.0f);
glm::vec3 n_col = *color / 255.0f;
float* p_col = glm::value_ptr(n_col); //Cast to float array
//------------------------------------
glNewList(TileID,GL_COMPILE);
glPushMatrix();
glBegin(GL_POLYGON);
glColor3fv(p_col);
for (int i = 0; i < 6; i++){
glVertex2f(R * cos(i*PI/3.0f), R * sin(i*PI/3.0f));
}
glEnd();
glPopMatrix();
glEndList();
}