Get rid of hardcoding of last two vertices having max UV coords for model rendering.

This commit is contained in:
UnknownShadow200 2017-08-19 09:39:02 +10:00
parent c5704840cb
commit 7ace31ee78
2 changed files with 22 additions and 17 deletions

View File

@ -19,6 +19,10 @@ namespace ClassicalSharp.Model {
protected const int boxVertices = 6 * quadVertices;
protected RotateOrder Rotate = RotateOrder.ZYX;
internal bool initalised;
public const ushort UVMask = 0x7FFF;
public const ushort UVMaxBit = 0x8000;
public const ushort UVMaxShift = 15;
public IModel(Game game) { this.game = game; }
@ -193,10 +197,10 @@ namespace ClassicalSharp.Model {
vertex.X = v.X; vertex.Y = v.Y; vertex.Z = v.Z;
vertex.Colour = cols[i >> 2];
vertex.U = v.U * uScale; vertex.V = v.V * vScale;
int quadI = i & 3;
if (quadI == 0 || quadI == 3) vertex.V -= 0.01f * vScale;
if (quadI == 2 || quadI == 3) vertex.U -= 0.01f * uScale;
vertex.U = (v.U & UVMask) * uScale;
vertex.U -= (v.U >> UVMaxShift) * 0.01f * uScale;
vertex.V = (v.V & UVMask) * vScale;
vertex.V -= (v.V >> UVMaxShift) * 0.01f * vScale;
finVertices[index++] = vertex;
}
}
@ -232,10 +236,10 @@ namespace ClassicalSharp.Model {
vertex.X = v.X + x; vertex.Y = v.Y + y; vertex.Z = v.Z + z;
vertex.Colour = cols[i >> 2];
vertex.U = v.U * uScale; vertex.V = v.V * vScale;
int quadI = i & 3;
if (quadI == 0 || quadI == 3) vertex.V -= 0.01f * vScale;
if (quadI == 2 || quadI == 3) vertex.U -= 0.01f * uScale;
vertex.U = (v.U & UVMask) * uScale;
vertex.U -= (v.U >> UVMaxShift) * 0.01f * uScale;
vertex.V = (v.V & UVMask) * vScale;
vertex.V -= (v.V >> UVMaxShift) * 0.01f * vScale;
finVertices[index++] = vertex;
}
}

View File

@ -53,6 +53,7 @@ namespace ClassicalSharp.Model {
/// <summary> Contains methods to create parts of 3D objects, typically boxes and quads. </summary>
public static class ModelBuilder {
const ushort UVMaxBit = IModel.UVMaxBit;
public static BoxDesc MakeBoxBounds(int x1, int y1, int z1, int x2, int y2, int z2) {
BoxDesc desc = default(BoxDesc).SetModelBounds(x1, y1, z1, x2, y2, z2);
desc.SidesW = Math.Abs(z2 - z1);
@ -134,26 +135,26 @@ namespace ClassicalSharp.Model {
public static void XQuad(IModel m, int texX, int texY, int texWidth, int texHeight,
float z1, float z2, float y1, float y2, float x) {
m.vertices[m.index++] = new ModelVertex(x, y1, z1, texX, texY + texHeight);
m.vertices[m.index++] = new ModelVertex(x, y1, z1, texX, texY + texHeight | UVMaxBit);
m.vertices[m.index++] = new ModelVertex(x, y2, z1, texX, texY);
m.vertices[m.index++] = new ModelVertex(x, y2, z2, texX + texWidth, texY);
m.vertices[m.index++] = new ModelVertex(x, y1, z2, texX + texWidth, texY + texHeight);
m.vertices[m.index++] = new ModelVertex(x, y2, z2, texX + texWidth | UVMaxBit, texY);
m.vertices[m.index++] = new ModelVertex(x, y1, z2, texX + texWidth | UVMaxBit, texY + texHeight | UVMaxBit);
}
public static void YQuad(IModel m, int texX, int texY, int texWidth, int texHeight,
float x1, float x2, float z1, float z2, float y) {
m.vertices[m.index++] = new ModelVertex(x1, y, z2, texX, texY + texHeight);
m.vertices[m.index++] = new ModelVertex(x1, y, z2, texX, texY + texHeight | UVMaxBit);
m.vertices[m.index++] = new ModelVertex(x1, y, z1, texX, texY);
m.vertices[m.index++] = new ModelVertex(x2, y, z1, texX + texWidth, texY);
m.vertices[m.index++] = new ModelVertex(x2, y, z2, texX + texWidth, texY + texHeight);
m.vertices[m.index++] = new ModelVertex(x2, y, z1, texX + texWidth | UVMaxBit, texY);
m.vertices[m.index++] = new ModelVertex(x2, y, z2, texX + texWidth | UVMaxBit, texY + texHeight | UVMaxBit);
}
public static void ZQuad(IModel m, int texX, int texY, int texWidth, int texHeight,
float x1, float x2, float y1, float y2, float z) {
m.vertices[m.index++] = new ModelVertex(x1, y1, z, texX, texY + texHeight);
m.vertices[m.index++] = new ModelVertex(x1, y1, z, texX, texY + texHeight | UVMaxBit);
m.vertices[m.index++] = new ModelVertex(x1, y2, z, texX, texY);
m.vertices[m.index++] = new ModelVertex(x2, y2, z, texX + texWidth, texY);
m.vertices[m.index++] = new ModelVertex(x2, y1, z, texX + texWidth, texY + texHeight);
m.vertices[m.index++] = new ModelVertex(x2, y2, z, texX + texWidth | UVMaxBit, texY);
m.vertices[m.index++] = new ModelVertex(x2, y1, z, texX + texWidth | UVMaxBit, texY + texHeight | UVMaxBit);
}
}
}