void YQuad(byte block, float y, int side)
        {
            int texLoc = game.BlockInfo.GetTextureLoc(block, side);

            texIndex = texLoc / atlas.elementsPerAtlas1D;
            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;

            TextureRec rec;
            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);

            y = scale * (1 - y * 2);
            float minX = scale * (1 - minBB.X * 2), maxX = scale * (1 - maxBB.X * 2);
            float minZ = scale * (1 - minBB.Z * 2), maxZ = scale * (1 - maxBB.Z * 2);

            v.X = minX; v.Y = y; v.Z = minZ; v.U = rec.U2; v.V = rec.V2; Transform(ref v);
            v.X = maxX; v.Y = y; v.Z = minZ; v.U = rec.U1; v.V = rec.V2; Transform(ref v);
            v.X = maxX; v.Y = y; v.Z = maxZ; v.U = rec.U1; v.V = rec.V1; Transform(ref v);
            v.X = minX; v.Y = y; v.Z = maxZ; v.U = rec.U2; v.V = rec.V1; Transform(ref v);
        }
        void SpriteXQuad(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 z1 = firstPart ? -0.1f : 0.5f, z2 = firstPart ? 0.5f : 1.1f;

            rec.U1 = firstPart ? 0.0f : 0.5f; rec.U2 = (firstPart ? 0.5f : 1.0f) * (15.99f / 16f);
            float minY = scale * (1 - 0 * 2), maxY = scale * (1 - 1.1f * 2);
            float minZ = scale * (1 - z1 * 2), maxZ = scale * (1 - z2 * 2);

            v.X = 0; v.Y = minY; v.Z = minZ; v.U = rec.U1; v.V = rec.V2; Transform(ref v);
            v.X = 0; v.Y = maxY; v.Z = minZ; v.U = rec.U1; v.V = rec.V1; Transform(ref v);
            v.X = 0; v.Y = maxY; v.Z = maxZ; v.U = rec.U2; v.V = rec.V1; Transform(ref v);
            v.X = 0; v.Y = minY; v.Z = maxZ; v.U = rec.U2; v.V = rec.V2; Transform(ref 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;
        }
        void XQuad(byte block, float x, int side)
        {
            int texLoc = game.BlockInfo.GetTextureLoc(block, side);

            texIndex = texLoc / atlas.elementsPerAtlas1D;
            if (lastIndex != texIndex)
            {
                Flush();
            }

            VertexP3fT2fC4b v   = default(VertexP3fT2fC4b);
            FastColour      col = fullBright ? colNormal : colXSide;

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

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

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

            x = scale * (1 - x * 2);
            float minY = scale * (1 - minBB.Y * 2), maxY = scale * (1 - maxBB.Y * 2);
            float minZ = scale * (1 - minBB.Z * 2), maxZ = scale * (1 - maxBB.Z * 2);

            v.X = x; v.Y = maxY; v.Z = minZ; v.U = rec.U2; v.V = rec.V2; Transform(ref v);
            v.X = x; v.Y = minY; v.Z = minZ; v.U = rec.U2; v.V = rec.V1; Transform(ref v);
            v.X = x; v.Y = minY; v.Z = maxZ; v.U = rec.U1; v.V = rec.V1; Transform(ref v);
            v.X = x; v.Y = maxY; v.Z = maxZ; v.U = rec.U1; v.V = rec.V2; Transform(ref v);
        }
Exemple #5
0
        void SpriteZQuad(byte 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;

            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), 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.U2; v.V = rec.V2; Transform(ref v);
            v.X = minX; v.Y = maxY; v.Z = 0; v.U = rec.U2; v.V = rec.V1; Transform(ref v);
            v.X = maxX; v.Y = maxY; v.Z = 0; v.U = rec.U1; v.V = rec.V1; Transform(ref v);
            v.X = maxX; v.Y = minY; v.Z = 0; v.U = rec.U1; v.V = rec.V2; Transform(ref v);
        }
Exemple #6
0
        void SpriteZQuad(BlockID block, bool firstPart)
        {
            int        texLoc = BlockInfo.GetTextureLoc(block, Side.Right);
            TextureRec rec    = Atlas1D.GetTexRec(texLoc, 1, out texIndex);

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

            VertexP3fT2fC4b v = default(VertexP3fT2fC4b);

            v.Col = colNormal;
            if (BlockInfo.Tinted[block])
            {
                v.Col *= BlockInfo.FogCol[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.Z = pos.Z;
            v.X = minX; v.Y = minY; v.U = rec.U2; v.V = rec.V2; vertices[index++] = v;
            v.Y = maxY;               v.V = rec.V1; vertices[index++] = v;
            v.X = maxX;             v.U = rec.U1;               vertices[index++] = v;
            v.Y = minY;               v.V = rec.V2; vertices[index++] = v;
        }
Exemple #7
0
        void ZQuad(byte block, float z, int side)
        {
            int texLoc = game.BlockInfo.GetTextureLoc(block, side);

            texIndex = texLoc / atlas.elementsPerAtlas1D;
            if (lastIndex != texIndex)
            {
                Flush();
            }

            VertexP3fT2fC4b v = default(VertexP3fT2fC4b);

            v.Colour = fullBright ? colNormal : colZSide;

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

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

            z = scale * (1 - z * 2);
            float minX = scale * (1 - minBB.X * 2), maxX = scale * (1 - maxBB.X * 2);
            float minY = scale * (1 - minBB.Y * 2), maxY = scale * (1 - maxBB.Y * 2);

            v.X = minX; v.Y = maxY; v.Z = z; v.U = rec.U2; v.V = rec.V2; Transform(ref v);
            v.X = minX; v.Y = minY; v.Z = z; v.U = rec.U2; v.V = rec.V1; Transform(ref v);
            v.X = maxX; v.Y = minY; v.Z = z; v.U = rec.U1; v.V = rec.V1; Transform(ref v);
            v.X = maxX; v.Y = maxY; v.Z = z; v.U = rec.U1; v.V = rec.V2; Transform(ref v);
        }
 public void BeginBatch( Game game, VertexP3fT2fC4b[] vertices, int vb )
 {
     this.game = game;
     lastIndex = -1;
     index = 0;
     this.vertices = vertices;
     this.vb = vb;
 }
        void Transform(ref VertexP3fT2fC4b v)
        {
            v.X += pos.X; v.Y += pos.Y; v.Z += pos.Z;
            //Vector3 p = new Vector3( v.X, v.Y, v.Z ) + pos;
            //p = Utils.RotateY( p - pos, time ) + pos;
            //v coords = p

            // See comment in IGraphicsApi.Draw2DTexture()
            v.X -= 0.5f; v.Y -= 0.5f;
            float 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
            vertices[index++] = v;
        }
        void DrawTopFace(int count)
        {
            int   texId   = BlockInfo.textures[curBlock * Side.Sides + Side.Top];
            int   i       = texId >> Atlas1D.Shift;
            float vOrigin = (texId & Atlas1D.Mask) * Atlas1D.invTileSize;
            int   offset  = (lightFlags >> Side.Top) & 1;

            float    u1 = minBB.X, u2 = (count - 1) + maxBB.X * 15.99f / 16f;
            float    v1   = vOrigin + minBB.Z * Atlas1D.invTileSize;
            float    v2   = vOrigin + maxBB.Z * Atlas1D.invTileSize * 15.99f / 16f;
            DrawInfo part = isTranslucent ? translucentParts[i] : normalParts[i];

            int F      = bitFlags[cIndex];
            int aX0_Z0 = ((F >> xM1_yP1_zM1) & 1) + ((F >> xM1_yP1_zCC) & 1) + ((F >> xCC_yP1_zM1) & 1) + ((F >> xCC_yP1_zCC) & 1);
            int aX1_Z0 = ((F >> xP1_yP1_zM1) & 1) + ((F >> xP1_yP1_zCC) & 1) + ((F >> xCC_yP1_zM1) & 1) + ((F >> xCC_yP1_zCC) & 1);
            int aX0_Z1 = ((F >> xM1_yP1_zP1) & 1) + ((F >> xM1_yP1_zCC) & 1) + ((F >> xCC_yP1_zP1) & 1) + ((F >> xCC_yP1_zCC) & 1);
            int aX1_Z1 = ((F >> xP1_yP1_zP1) & 1) + ((F >> xP1_yP1_zCC) & 1) + ((F >> xCC_yP1_zP1) & 1) + ((F >> xCC_yP1_zCC) & 1);

            PackedCol col0_0 = fullBright ? PackedCol.White : lerp[aX0_Z0], col1_0 = fullBright ? PackedCol.White : lerp[aX1_Z0];
            PackedCol col1_1 = fullBright ? PackedCol.White : lerp[aX1_Z1], col0_1 = fullBright ? PackedCol.White : lerp[aX0_Z1];

            if (tinted)
            {
                PackedCol tint = BlockInfo.FogCol[curBlock];
                col0_0 *= tint; col1_0 *= tint; col1_1 *= tint; col0_1 *= tint;
            }

            int index = part.vIndex[Side.Top];

            if (aX0_Z0 + aX1_Z1 > aX0_Z1 + aX1_Z0)
            {
                vertices[index]     = new VertexP3fT2fC4b(x2 + (count - 1), y2, z1, u2, v1, col1_0);
                vertices[index + 1] = new VertexP3fT2fC4b(x1, y2, z1, u1, v1, col0_0);
                vertices[index + 2] = new VertexP3fT2fC4b(x1, y2, z2, u1, v2, col0_1);
                vertices[index + 3] = new VertexP3fT2fC4b(x2 + (count - 1), y2, z2, u2, v2, col1_1);
            }
            else
            {
                vertices[index]     = new VertexP3fT2fC4b(x1, y2, z1, u1, v1, col0_0);
                vertices[index + 1] = new VertexP3fT2fC4b(x1, y2, z2, u1, v2, col0_1);
                vertices[index + 2] = new VertexP3fT2fC4b(x2 + (count - 1), y2, z2, u2, v2, col1_1);
                vertices[index + 3] = new VertexP3fT2fC4b(x2 + (count - 1), y2, z1, u2, v1, col1_0);
            }
            part.vIndex[Side.Top] += 4;
        }
Exemple #11
0
        protected virtual void PostStretchTiles(int x1, int y1, int z1)
        {
            int vertsCount = TotalVerticesCount();

            if (vertices == null || (vertsCount + 2) > vertices.Length)
            {
                vertices = new VertexP3fT2fC4b[vertsCount + 2];
                // ensure buffer is up to 64 bits aligned for last element
            }

            // organised as: all N_0, all T_0, all N_1, all T1, etc
            vertsCount = 0;
            for (int i = 0; i < normalParts.Length; i++)
            {
                normalParts[i].CalcOffsets(ref vertsCount);
                translucentParts[i].CalcOffsets(ref vertsCount);
            }
        }
        static void TransformVertex( ref VertexP3fT2fC4b v )
        {
            v.X += pos.X; v.Y += pos.Y; v.Z += pos.Z;
            //Vector3 p = new Vector3( v.X, v.Y, v.Z ) + pos;
            //p = Utils.RotateY( p - pos, time ) + pos;
            //v coords = p

            // See comment in IGraphicsApi.Draw2DTexture()
            v.X -= 0.5f; v.Y -= 0.5f;
            float 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
        }