summary refs log tree commit diff
path: root/src/Drawer.c
blob: 527a5a17333a69053ffec943fb6b37f5b356d440 (plain)
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#include "Drawer.h"
#include "TexturePack.h"
#include "Constants.h"
#include "Graphics.h"
struct _DrawerData Drawer;

void Drawer_XMin(int count, PackedCol col, TextureLoc texLoc, struct VertexTextured** vertices) {
	struct VertexTextured* v = *vertices;
	float vOrigin = Atlas1D_RowId(texLoc) * Atlas1D.InvTileSize;

	float u1 = Drawer.MinBB.z;
	float u2 = (count - 1) + Drawer.MaxBB.z * UV2_Scale;
	float v1 = vOrigin + Drawer.MaxBB.y * Atlas1D.InvTileSize;
	float v2 = vOrigin + Drawer.MinBB.y * Atlas1D.InvTileSize * UV2_Scale;

	float x1 = Drawer.X1;
	float y1 = Drawer.Y1, y2 = Drawer.Y2;
	float z1 = Drawer.Z1, z2 = Drawer.Z2 + (count - 1);

	if (Drawer.Tinted) col = PackedCol_Tint(col, Drawer.TintCol);

	v->x = x1; v->y = y2; v->z = z2; v->Col = col; v->U = u2; v->V = v1; v++;
	v->x = x1; v->y = y2; v->z = z1; v->Col = col; v->U = u1; v->V = v1; v++;
	v->x = x1; v->y = y1; v->z = z1; v->Col = col; v->U = u1; v->V = v2; v++;
	v->x = x1; v->y = y1; v->z = z2; v->Col = col; v->U = u2; v->V = v2; v++;
	*vertices = v;
}

void Drawer_XMax(int count, PackedCol col, TextureLoc texLoc, struct VertexTextured** vertices) {
	struct VertexTextured* v = *vertices;
	float vOrigin = Atlas1D_RowId(texLoc) * Atlas1D.InvTileSize;

	float u1 = (count - Drawer.MinBB.z);
	float u2 = (1 - Drawer.MaxBB.z) * UV2_Scale;
	float v1 = vOrigin + Drawer.MaxBB.y * Atlas1D.InvTileSize;
	float v2 = vOrigin + Drawer.MinBB.y * Atlas1D.InvTileSize * UV2_Scale;

	float x2 = Drawer.X2;
	float y1 = Drawer.Y1, y2 = Drawer.Y2;
	float z1 = Drawer.Z1, z2 = Drawer.Z2 + (count - 1);

	if (Drawer.Tinted) col = PackedCol_Tint(col, Drawer.TintCol);

	v->x = x2; v->y = y2; v->z = z1; v->Col = col; v->U = u1; v->V = v1; v++;
	v->x = x2; v->y = y2; v->z = z2; v->Col = col; v->U = u2; v->V = v1; v++;
	v->x = x2; v->y = y1; v->z = z2; v->Col = col; v->U = u2; v->V = v2; v++;
	v->x = x2; v->y = y1; v->z = z1; v->Col = col; v->U = u1; v->V = v2; v++;
	*vertices = v;
}

void Drawer_ZMin(int count, PackedCol col, TextureLoc texLoc, struct VertexTextured** vertices) {
	struct VertexTextured* v = *vertices;
	float vOrigin = Atlas1D_RowId(texLoc) * Atlas1D.InvTileSize;

	float u1 = (count - Drawer.MinBB.x);
	float u2 = (1 - Drawer.MaxBB.x) * UV2_Scale;
	float v1 = vOrigin + Drawer.MaxBB.y * Atlas1D.InvTileSize;
	float v2 = vOrigin + Drawer.MinBB.y * Atlas1D.InvTileSize * UV2_Scale;

	float x1 = Drawer.X1, x2 = Drawer.X2 + (count - 1);
	float y1 = Drawer.Y1, y2 = Drawer.Y2;
	float z1 = Drawer.Z1;

	if (Drawer.Tinted) col = PackedCol_Tint(col, Drawer.TintCol);

	v->x = x2; v->y = y1; v->z = z1; v->Col = col; v->U = u2; v->V = v2; v++;
	v->x = x1; v->y = y1; v->z = z1; v->Col = col; v->U = u1; v->V = v2; v++;
	v->x = x1; v->y = y2; v->z = z1; v->Col = col; v->U = u1; v->V = v1; v++;
	v->x = x2; v->y = y2; v->z = z1; v->Col = col; v->U = u2; v->V = v1; v++;
	*vertices = v;
}

void Drawer_ZMax(int count, PackedCol col, TextureLoc texLoc, struct VertexTextured** vertices) {
	struct VertexTextured* v = *vertices;
	float vOrigin = Atlas1D_RowId(texLoc) * Atlas1D.InvTileSize;

	float u1 = Drawer.MinBB.x;
	float u2 = (count - 1) + Drawer.MaxBB.x * UV2_Scale;
	float v1 = vOrigin + Drawer.MaxBB.y * Atlas1D.InvTileSize;
	float v2 = vOrigin + Drawer.MinBB.y * Atlas1D.InvTileSize * UV2_Scale;

	float x1 = Drawer.X1, x2 = Drawer.X2 + (count - 1);
	float y1 = Drawer.Y1, y2 = Drawer.Y2;
	float z2 = Drawer.Z2;

	if (Drawer.Tinted) col = PackedCol_Tint(col, Drawer.TintCol);

	v->x = x2; v->y = y2; v->z = z2; v->Col = col; v->U = u2; v->V = v1; v++;
	v->x = x1; v->y = y2; v->z = z2; v->Col = col; v->U = u1; v->V = v1; v++;
	v->x = x1; v->y = y1; v->z = z2; v->Col = col; v->U = u1; v->V = v2; v++;
	v->x = x2; v->y = y1; v->z = z2; v->Col = col; v->U = u2; v->V = v2; v++;
	*vertices = v;
}

void Drawer_YMin(int count, PackedCol col, TextureLoc texLoc, struct VertexTextured** vertices) {
	struct VertexTextured* v = *vertices;

	float vOrigin = Atlas1D_RowId(texLoc) * Atlas1D.InvTileSize;
	float u1 = Drawer.MinBB.x;
	float u2 = (count - 1) + Drawer.MaxBB.x * UV2_Scale;
	float v1 = vOrigin + Drawer.MinBB.z * Atlas1D.InvTileSize;
	float v2 = vOrigin + Drawer.MaxBB.z * Atlas1D.InvTileSize * UV2_Scale;

	float x1 = Drawer.X1, x2 = Drawer.X2 + (count - 1);
	float y1 = Drawer.Y1;
	float z1 = Drawer.Z1, z2 = Drawer.Z2;

	if (Drawer.Tinted) col = PackedCol_Tint(col, Drawer.TintCol);

	v->x = x2; v->y = y1; v->z = z2; v->Col = col; v->U = u2; v->V = v2; v++;
	v->x = x1; v->y = y1; v->z = z2; v->Col = col; v->U = u1; v->V = v2; v++;
	v->x = x1; v->y = y1; v->z = z1; v->Col = col; v->U = u1; v->V = v1; v++;
	v->x = x2; v->y = y1; v->z = z1; v->Col = col; v->U = u2; v->V = v1; v++;
	*vertices = v;
}

void Drawer_YMax(int count, PackedCol col, TextureLoc texLoc, struct VertexTextured** vertices) {
	struct VertexTextured* v = *vertices;
	float vOrigin = Atlas1D_RowId(texLoc) * Atlas1D.InvTileSize;

	float u1 = Drawer.MinBB.x;
	float u2 = (count - 1) + Drawer.MaxBB.x * UV2_Scale;
	float v1 = vOrigin + Drawer.MinBB.z * Atlas1D.InvTileSize;
	float v2 = vOrigin + Drawer.MaxBB.z * Atlas1D.InvTileSize * UV2_Scale;

	float x1 = Drawer.X1, x2 = Drawer.X2 + (count - 1);
	float y2 = Drawer.Y2;
	float z1 = Drawer.Z1, z2 = Drawer.Z2;

	if (Drawer.Tinted) col = PackedCol_Tint(col, Drawer.TintCol);

	v->x = x2; v->y = y2; v->z = z1; v->Col = col; v->U = u2; v->V = v1; v++;
	v->x = x1; v->y = y2; v->z = z1; v->Col = col; v->U = u1; v->V = v1; v++;
	v->x = x1; v->y = y2; v->z = z2; v->Col = col; v->U = u1; v->V = v2; v++;
	v->x = x2; v->y = y2; v->z = z2; v->Col = col; v->U = u2; v->V = v2; v++;
	*vertices = v;
}