the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
1#include "stdafx.h"
2#include "Polygon.h"
3
4// 4J added for common init code
5void _Polygon::_init(VertexArray vertices)
6{
7 vertexCount = 0;
8 _flipNormal = false;
9
10 this->vertices = vertices;
11 vertexCount = vertices.length;
12}
13
14_Polygon::_Polygon(VertexArray vertices)
15{
16 _init(vertices);
17}
18
19_Polygon::_Polygon(VertexArray vertices, int u0, int v0, int u1, int v1, float xTexSize, float yTexSize)
20{
21 _init(vertices);
22
23 // 4J - added - don't assume that u1 > u0, v1 > v0
24 float us = ( u1 > u0 ) ? ( 0.1f / xTexSize ) : ( -0.1f / xTexSize );
25 float vs = ( v1 > v0 ) ? ( 0.1f / yTexSize ) : ( -0.1f / yTexSize );
26
27 vertices[0] = vertices[0]->remap(u1 / xTexSize - us, v0 / yTexSize + vs);
28 vertices[1] = vertices[1]->remap(u0 / xTexSize + us, v0 / yTexSize + vs);
29 vertices[2] = vertices[2]->remap(u0 / xTexSize + us, v1 / yTexSize - vs);
30 vertices[3] = vertices[3]->remap(u1 / xTexSize - us, v1 / yTexSize - vs);
31}
32
33_Polygon::_Polygon(VertexArray vertices, float u0, float v0, float u1, float v1)
34{
35 _init(vertices);
36
37 vertices[0] = vertices[0]->remap(u1, v0);
38 vertices[1] = vertices[1]->remap(u0, v0);
39 vertices[2] = vertices[2]->remap(u0, v1);
40 vertices[3] = vertices[3]->remap(u1, v1);
41}
42
43void _Polygon::mirror()
44{
45 VertexArray newVertices = VertexArray(vertices.length);
46 for (unsigned int i = 0; i < vertices.length; i++)
47 newVertices[i] = vertices[vertices.length - i - 1];
48 delete [] vertices.data;
49 vertices = newVertices;
50}
51
52void _Polygon::render(Tesselator *t, float scale)
53{
54 Vec3 *v0 = vertices[1]->pos->vectorTo(vertices[0]->pos);
55 Vec3 *v1 = vertices[1]->pos->vectorTo(vertices[2]->pos);
56 Vec3 *n = v1->cross(v0)->normalize();
57
58 t->begin();
59 if (_flipNormal)
60 {
61 t->normal(-(float)n->x, -(float)n->y, -(float)n->z);
62 }
63 else
64 {
65 t->normal((float)n->x, (float)n->y, (float)n->z);
66 }
67
68 for (int i = 0; i < 4; i++)
69 {
70 Vertex *v = vertices[i];
71 t->vertexUV((float)(v->pos->x * scale), (float)( v->pos->y * scale), (float)( v->pos->z * scale), (float)( v->u), (float)( v->v));
72 }
73 t->end();
74}
75
76_Polygon *_Polygon::flipNormal()
77{
78 _flipNormal = true;
79 return this;
80}