diff options
author | WlodekM <[email protected]> | 2024-06-16 10:35:45 +0300 |
---|---|---|
committer | WlodekM <[email protected]> | 2024-06-16 10:35:45 +0300 |
commit | abef6da56913f1c55528103e60a50451a39628b1 (patch) | |
tree | b3c8092471ecbb73e568cd0d336efa0e7871ee8d /src/Drawer.c |
initial commit
Diffstat (limited to 'src/Drawer.c')
-rw-r--r-- | src/Drawer.c | 137 |
1 files changed, 137 insertions, 0 deletions
diff --git a/src/Drawer.c b/src/Drawer.c new file mode 100644 index 0000000..527a5a1 --- /dev/null +++ b/src/Drawer.c @@ -0,0 +1,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; +} |