void SpriteZQuad(byte block, int side, bool firstPart)
        {
            int        texLoc = game.BlockInfo.GetTextureLoc(block, side);
            TextureRec rec    = atlas.GetTexRec(texLoc, 1, out texIndex);

            if (lastIndex != texIndex)
            {
                Flush();
            }

            VertexP3fT2fC4b v   = default(VertexP3fT2fC4b);
            FastColour      col = colNormal;

            v.A = col.A; v.R = col.R; v.G = col.G; v.B = col.B;

            float x1 = firstPart ? -0.1f : 0.5f, x2 = firstPart ? 0.5f : 1.1f;

            rec.U1 = firstPart ? 0.0f : 0.5f; rec.U2 = (firstPart ? 0.5f : 1.0f) * (15.99f / 16f);
            float minX = scale * (1 - x1 * 2), maxX = scale * (1 - x2 * 2);
            float minY = scale * (1 - 0 * 2), maxY = scale * (1 - 1.1f * 2);

            v.X = minX; v.Y = minY; v.Z = 0; v.U = rec.U1; v.V = rec.V2; Transform(ref v);
            v.X = minX; v.Y = maxY; v.Z = 0; v.U = rec.U1; v.V = rec.V1; Transform(ref v);
            v.X = maxX; v.Y = maxY; v.Z = 0; v.U = rec.U2; v.V = rec.V1; Transform(ref v);
            v.X = maxX; v.Y = minY; v.Z = 0; v.U = rec.U2; v.V = rec.V2; Transform(ref v);
        }
        void SpriteZQuad(BlockID block, bool firstPart)
        {
            int        texLoc = game.BlockInfo.GetTextureLoc(block, Side.Right);
            TextureRec rec    = atlas.GetTexRec(texLoc, 1, out texIndex);

            if (lastIndex != texIndex)
            {
                Flush();
            }

            VertexP3fT2fC4b v = default(VertexP3fT2fC4b);

            v.Colour = colNormal;

            if (game.BlockInfo.Tinted[block])
            {
                v.Colour = Utils.Tint(v.Colour, game.BlockInfo.FogColour[block]);
            }

            float x1 = firstPart ? 0.5f : -0.1f, x2 = firstPart ? 1.1f : 0.5f;

            rec.U1 = firstPart ? 0.0f : 0.5f; rec.U2 = (firstPart ? 0.5f : 1.0f) * (15.99f / 16f);
            float minX = scale * (1 - x1 * 2) + pos.X, maxX = scale * (1 - x2 * 2) + pos.X;
            float minY = scale * (1 - 0 * 2) + pos.Y, maxY = scale * (1 - 1.1f * 2) + pos.Y;

            v.X = minX; v.Y = minY; v.Z = pos.Z; v.U = rec.U2; v.V = rec.V2; vertices[index++] = v;
            v.X = minX; v.Y = maxY; v.Z = pos.Z; v.U = rec.U2; v.V = rec.V1; vertices[index++] = v;
            v.X = maxX; v.Y = maxY; v.Z = pos.Z; v.U = rec.U1; v.V = rec.V1; vertices[index++] = v;
            v.X = maxX; v.Y = minY; v.Z = pos.Z; v.U = rec.U1; v.V = rec.V2; vertices[index++] = v;
        }
        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();
            }

            VertexP3fT2fC4b v = default(VertexP3fT2fC4b);

            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;
        }
Exemple #4
0
        static void YQuad(byte block, float y, int side)
        {
            int        texLoc = info.GetTextureLoc(block, side);
            TextureRec rec    = atlas.GetTexRec(texLoc, 1, out texIndex);

            FlushIfNotSame();
            FastColour col = colNormal;

            float vOrigin = (texLoc % atlas.elementsPerAtlas1D) * atlas.invElementSize;

            rec.U1 = minBB.X; rec.U2 = maxBB.X;
            rec.V1 = vOrigin + minBB.Z * atlas.invElementSize;
            rec.V2 = vOrigin + maxBB.Z * atlas.invElementSize * (15.99f / 16f);

            cache.vertices[index++] = new VertexPos3fTex2fCol4b(Make(minBB.X), y, Make(minBB.Z), rec.U1, rec.V1, col);
            cache.vertices[index++] = new VertexPos3fTex2fCol4b(Make(maxBB.X), y, Make(minBB.Z), rec.U2, rec.V1, col);
            cache.vertices[index++] = new VertexPos3fTex2fCol4b(Make(maxBB.X), y, Make(maxBB.Z), rec.U2, rec.V2, col);
            cache.vertices[index++] = new VertexPos3fTex2fCol4b(Make(minBB.X), y, Make(maxBB.Z), rec.U1, rec.V2, col);
        }
        void DrawBackground()
        {
            VertexPos3fTex2fCol4b[] vertices = game.ModelCache.vertices;
            int        index = 0, atlasIndex = 0;
            int        drawnY = 0, height = game.Height;
            FastColour col = new FastColour(64, 64, 64);

            int            texLoc = game.BlockInfo.GetTextureLoc((byte)Block.Dirt, TileSide.Top);
            TerrainAtlas1D atlas  = game.TerrainAtlas1D;
            TextureRec     tex = atlas.GetTexRec(texLoc, 1, out atlasIndex);

            tex.U2 = (float)game.Width / 64;
            bool bound = false;

            while (drawnY < height)
            {
                float x1 = 0, x2 = game.Width;
                float y1 = drawnY, y2 = drawnY + 64;
                                #if USE_DX
                // NOTE: see "https://msdn.microsoft.com/en-us/library/windows/desktop/bb219690(v=vs.85).aspx",
                // i.e. the msdn article called "Directly Mapping Texels to Pixels (Direct3D 9)" for why we have to do this.
                x1 -= 0.5f; x2 -= 0.5f;
                y1 -= 0.5f; y2 -= 0.5f;
                                #endif

                vertices[index++] = new VertexPos3fTex2fCol4b(x1, y1, 0, tex.U1, tex.V1, col);
                vertices[index++] = new VertexPos3fTex2fCol4b(x2, y1, 0, tex.U2, tex.V1, col);
                vertices[index++] = new VertexPos3fTex2fCol4b(x2, y2, 0, tex.U2, tex.V2, col);
                vertices[index++] = new VertexPos3fTex2fCol4b(x1, y2, 0, tex.U1, tex.V2, col);
                if (index >= vertices.Length)
                {
                    DrawBackgroundVertices(ref index, atlasIndex, ref bound);
                }
                drawnY += 64;
            }
            DrawBackgroundVertices(ref index, atlasIndex, ref bound);
        }