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 "Model.h"
3#include "ModelPart.h"
4#include "Cube.h"
5
6
7
8// 4J - added - helper function to set up vertex arrays
9VertexArray Cube::VertexArray4(Vertex *v0, Vertex *v1, Vertex *v2, Vertex *v3)
10{
11 VertexArray ret = VertexArray(4);
12 ret[0] = v0;
13 ret[1] = v1;
14 ret[2] = v2;
15 ret[3] = v3;
16
17 return ret;
18}
19
20//void Cube::addBox(float x0, float y0, float z0, int w, int h, int d, float g)
21Cube::Cube(ModelPart *modelPart, int xTexOffs, int yTexOffs, float x0, float y0, float z0, int w, int h, int d, float g, int faceMask /* = 63 */, bool bFlipPoly3UVs) : // 4J - added faceMask, added bFlipPoly3UVs to reverse the uvs back so player skins display right
22 x0(x0),
23 y0(y0),
24 z0(z0),
25 x1(x0 + w),
26 y1(y0 + h),
27 z1(z0 + d)
28{
29// this->x0 = x0;
30// this->y0 = y0;
31// this->z0 = z0;
32// this->x1 = x0 + w;
33// this->y1 = y0 + h;
34// this->z1 = z0 + d;
35
36 vertices = VertexArray(8);
37 polygons = PolygonArray(6);
38
39 float x1 = x0 + w;
40 float y1 = y0 + h;
41 float z1 = z0 + d;
42
43 x0 -= g;
44 y0 -= g;
45 z0 -= g;
46 x1 += g;
47 y1 += g;
48 z1 += g;
49
50 if (modelPart->bMirror)
51 {
52 float tmp = x1;
53 x1 = x0;
54 x0 = tmp;
55 }
56
57 Vertex *u0 = new Vertex(x0, y0, z0, 0, 0);
58 Vertex *u1 = new Vertex(x1, y0, z0, 0, 8);
59 Vertex *u2 = new Vertex(x1, y1, z0, 8, 8);
60 Vertex *u3 = new Vertex(x0, y1, z0, 8, 0);
61
62 Vertex *l0 = new Vertex(x0, y0, z1, 0, 0);
63 Vertex *l1 = new Vertex(x1, y0, z1, 0, 8);
64 Vertex *l2 = new Vertex(x1, y1, z1, 8, 8);
65 Vertex *l3 = new Vertex(x0, y1, z1, 8, 0);
66
67 vertices[0] = u0;
68 vertices[1] = u1;
69 vertices[2] = u2;
70 vertices[3] = u3;
71 vertices[4] = l0;
72 vertices[5] = l1;
73 vertices[6] = l2;
74 vertices[7] = l3;
75
76 // 4J - added ability to mask individual faces
77 int faceCount = 0;
78 if( faceMask & 1 ) polygons[faceCount++] = new _Polygon(VertexArray4(l1, u1, u2, l2), xTexOffs + d + w, yTexOffs + d, xTexOffs + d + w + d, yTexOffs + d + h, modelPart->xTexSize, modelPart->yTexSize); // Right
79 if( faceMask & 2 ) polygons[faceCount++] = new _Polygon(VertexArray4(u0, l0, l3, u3), xTexOffs + 0, yTexOffs + d, xTexOffs + d, yTexOffs + d + h, modelPart->xTexSize, modelPart->yTexSize); // Left
80 if( faceMask & 4 ) polygons[faceCount++] = new _Polygon(VertexArray4(l1, l0, u0, u1), xTexOffs + d, yTexOffs + 0, xTexOffs + d + w, yTexOffs + d, modelPart->xTexSize, modelPart->yTexSize); // Up
81 if(bFlipPoly3UVs)
82 {
83 if( faceMask & 8 ) polygons[faceCount++] = new _Polygon(VertexArray4(u2, u3, l3, l2), xTexOffs + d + w, yTexOffs + 0, xTexOffs + d + w + w, yTexOffs + d, modelPart->xTexSize, modelPart->yTexSize); // Down
84 }
85 else
86 {
87 if( faceMask & 8 ) polygons[faceCount++] = new _Polygon(VertexArray4(u2, u3, l3, l2), xTexOffs + d + w, yTexOffs + d, xTexOffs + d + w + w, yTexOffs + 0, modelPart->xTexSize, modelPart->yTexSize); // Down
88 }
89 if( faceMask & 16 ) polygons[faceCount++] = new _Polygon(VertexArray4(u1, u0, u3, u2), xTexOffs + d, yTexOffs + d, xTexOffs + d + w, yTexOffs + d + h, modelPart->xTexSize, modelPart->yTexSize); // Front
90 if( faceMask & 32 ) polygons[faceCount++] = new _Polygon(VertexArray4(l0, l1, l2, l3), xTexOffs + d + w + d, yTexOffs + d, xTexOffs + d + w + d + w, yTexOffs + d + h, modelPart->xTexSize, modelPart->yTexSize); // Back
91 polygons.length = faceCount;
92
93 if (modelPart->bMirror)
94 {
95 for (unsigned int i = 0; i < polygons.length; i++)
96 polygons[i]->mirror();
97 }
98}
99
100
101void Cube::render(Tesselator *t,float scale)
102{
103 for (int i = 0; i < polygons.length; i++)
104 {
105 polygons[i]->render(t, scale);
106 }
107}
108
109Cube *Cube::setId(const wstring &id)
110{
111 this->id = id;
112 return this;
113}