void SpriteXQuad(BlockID block, bool firstPart) { int texLoc = BlockInfo.GetTextureLoc(block, Side.Right); TextureRec rec = TerrainAtlas1D.GetTexRec(texLoc, 1, out texIndex); if (lastTexIndex != texIndex) { Flush(); } VertexP3fT2fC4bN1v v = default(VertexP3fT2fC4bN1v); v.Colour = colNormal; if (BlockInfo.Tinted[block]) { v.Colour = Utils.Tint(v.Colour, BlockInfo.FogColour[block]); } float z1 = firstPart ? 0.5f : -0.1f, z2 = firstPart ? 1.1f : 0.5f; rec.U1 = firstPart ? 0.0f : 0.5f; rec.U2 = (firstPart ? 0.5f : 1.0f) * (15.99f / 16f); float minY = scale * (1 - 0 * 2) + pos.Y, maxY = scale * (1 - 1.1f * 2) + pos.Y; float minZ = scale * (1 - z1 * 2) + pos.Z, maxZ = scale * (1 - z2 * 2) + pos.Z; v.X = pos.X; v.Y = minY; v.Z = minZ; v.U = rec.U2; v.V = rec.V2; vertices[index++] = v; v.Y = maxY; v.V = rec.V1; vertices[index++] = v; v.Z = maxZ; v.U = rec.U1; vertices[index++] = v; v.Y = minY; v.V = rec.V2; vertices[index++] = v; }
const byte c = 255; // avoids 'ambiguous match' compile errors. static void DrawSquareShadow(VertexP3fT2fC4bN1v[] verts, ref int index, float y, float x, float z) { int col = new FastColour(c, c, c, (byte)220).Pack(); TextureRec rec = new TextureRec(63 / 128f, 63 / 128f, 1 / 128f, 1 / 128f); verts[index++] = new VertexP3fT2fC4bN1v(x, y, z, rec.U1, rec.V1, col); verts[index++] = new VertexP3fT2fC4bN1v(x + 1, y, z, rec.U2, rec.V1, col); verts[index++] = new VertexP3fT2fC4bN1v(x + 1, y, z + 1, rec.U2, rec.V2, col); verts[index++] = new VertexP3fT2fC4bN1v(x, y, z + 1, rec.U1, rec.V2, col); }
protected void DrawPart(ModelPart part) { VertexP3fT2fC4bN1v vertex = default(VertexP3fT2fC4bN1v); VertexP3fT2fC4bN1v[] finVertices = game.ModelCache.vertices; for (int i = 0; i < part.Count; i++) { ModelVertex v = vertices[part.Offset + i]; vertex.X = v.X; vertex.Y = v.Y; vertex.Z = v.Z; vertex.Colour = cols[i >> 2]; vertex.Normal = v.D; vertex.U = (v.U & UVMask) * uScale - (v.U >> UVMaxShift) * 0.01f * uScale; vertex.V = (v.V & UVMask) * vScale - (v.V >> UVMaxShift) * 0.01f * vScale; finVertices[index++] = vertex; } }
protected void DrawRotate(float angleX, float angleY, float angleZ, ModelPart part, bool head, bool rotNormal) { float cosX = (float)Math.Cos(-angleX), sinX = (float)Math.Sin(-angleX); float cosY = (float)Math.Cos(-angleY), sinY = (float)Math.Sin(-angleY); float cosZ = (float)Math.Cos(-angleZ), sinZ = (float)Math.Sin(-angleZ); float x = part.RotX, y = part.RotY, z = part.RotZ; VertexP3fT2fC4bN1v vertex = default(VertexP3fT2fC4bN1v); VertexP3fT2fC4bN1v[] finVertices = game.ModelCache.vertices; for (int i = 0; i < part.Count; i++) { ModelVertex v = vertices[part.Offset + i]; v.X -= x; v.Y -= y; v.Z -= z; float t = 0; // Rotate locally if (Rotate == RotateOrder.ZYX) { t = cosZ * v.X + sinZ * v.Y; v.Y = -sinZ * v.X + cosZ * v.Y; v.X = t; // Inlined RotZ t = cosY * v.X - sinY * v.Z; v.Z = sinY * v.X + cosY * v.Z; v.X = t; // Inlined RotY t = cosX * v.Y + sinX * v.Z; v.Z = -sinX * v.Y + cosX * v.Z; v.Y = t; // Inlined RotX } else if (Rotate == RotateOrder.XZY) { t = cosX * v.Y + sinX * v.Z; v.Z = -sinX * v.Y + cosX * v.Z; v.Y = t; // Inlined RotX t = cosZ * v.X + sinZ * v.Y; v.Y = -sinZ * v.X + cosZ * v.Y; v.X = t; // Inlined RotZ t = cosY * v.X - sinY * v.Z; v.Z = sinY * v.X + cosY * v.Z; v.X = t; // Inlined RotY } else if (Rotate == RotateOrder.YZX) { t = cosY * v.X - sinY * v.Z; v.Z = sinY * v.X + cosY * v.Z; v.X = t; // Inlined RotY t = cosZ * v.X + sinZ * v.Y; v.Y = -sinZ * v.X + cosZ * v.Y; v.X = t; // Inlined RotZ t = cosX * v.Y + sinX * v.Z; v.Z = -sinX * v.Y + cosX * v.Z; v.Y = t; // Inlined RotX } // Rotate globally if (head) { t = cosHead * v.X - sinHead * v.Z; v.Z = sinHead * v.X + cosHead * v.Z; v.X = t; // Inlined RotY } vertex.X = v.X + x; vertex.Y = v.Y + y; vertex.Z = v.Z + z; vertex.Colour = cols[i >> 2]; if (!v.N) { vertex.Normal = v.D; } float normalAngleX = angleX; float normalAngleY = angleY; float normalAngleZ = angleZ; if (rotNormal) { normalAngleX = angleX; normalAngleY = angleY; normalAngleZ = -angleZ; } if (Rotate == RotateOrder.ZYX) { Vector3 newNormal = vertex.Normal; newNormal = Utils.RotateZ(newNormal, -normalAngleZ); newNormal = Utils.RotateY(newNormal, -normalAngleY); newNormal = Utils.RotateX(newNormal, -normalAngleX); vertex.Normal = newNormal; } else if (Rotate == RotateOrder.XZY) { Vector3 newNormal = vertex.Normal; newNormal = Utils.RotateX(newNormal, -normalAngleX); newNormal = Utils.RotateZ(newNormal, -normalAngleZ); newNormal = Utils.RotateY(newNormal, -normalAngleY); vertex.Normal = newNormal; } else if (Rotate == RotateOrder.YZX) { Vector3 newNormal = vertex.Normal; newNormal = Utils.RotateY(newNormal, -normalAngleY); newNormal = Utils.RotateZ(newNormal, -normalAngleZ); newNormal = Utils.RotateX(newNormal, -normalAngleX); vertex.Normal = newNormal; } v.N = true; vertex.U = (v.U & UVMask) * uScale - (v.U >> UVMaxShift) * 0.01f * uScale; vertex.V = (v.V & UVMask) * vScale - (v.V >> UVMaxShift) * 0.01f * vScale; finVertices[index++] = vertex; } }