void DrawY(int x1, int z1, int x2, int z2, int y, int axisSize, FastColour col, ref VertexPos3fTex2fCol4b *vertices)
        {
            int endX = x2, endZ = z2, startZ = z1;

            for ( ; x1 < endX; x1 += axisSize)
            {
                x2 = x1 + axisSize;
                if (x2 > endX)
                {
                    x2 = endX;
                }
                z1 = startZ;
                for ( ; z1 < endZ; z1 += axisSize)
                {
                    z2 = z1 + axisSize;
                    if (z2 > endZ)
                    {
                        z2 = endZ;
                    }

                    TextureRec rec        = new TextureRec(0, 0, x2 - x1, z2 - z1);
                    *          vertices++ = new VertexPos3fTex2fCol4b(x1, y, z1, rec.U1, rec.V1, col);
                    *          vertices++ = new VertexPos3fTex2fCol4b(x1, y, z2, rec.U1, rec.V2, col);
                    *          vertices++ = new VertexPos3fTex2fCol4b(x2, y, z2, rec.U2, rec.V2, col);
                    *          vertices++ = new VertexPos3fTex2fCol4b(x2, y, z1, rec.U2, rec.V1, col);
                }
            }
        }
        void DrawX(int x, int z1, int z2, int y1, int y2, int axisSize, FastColour col, ref VertexPos3fTex2fCol4b *vertices)
        {
            int endZ = z2, endY = y2, startY = y1;

            for ( ; z1 < endZ; z1 += axisSize)
            {
                z2 = z1 + axisSize;
                if (z2 > endZ)
                {
                    z2 = endZ;
                }
                y1 = startY;
                for ( ; y1 < endY; y1 += axisSize)
                {
                    y2 = y1 + axisSize;
                    if (y2 > endY)
                    {
                        y2 = endY;
                    }

                    TextureRec rec        = new TextureRec(0, 0, z2 - z1, y2 - y1);
                    *          vertices++ = new VertexPos3fTex2fCol4b(x, y1, z1, rec.U1, rec.V2, col);
                    *          vertices++ = new VertexPos3fTex2fCol4b(x, y2, z1, rec.U1, rec.V1, col);
                    *          vertices++ = new VertexPos3fTex2fCol4b(x, y2, z2, rec.U2, rec.V1, col);
                    *          vertices++ = new VertexPos3fTex2fCol4b(x, y1, z2, rec.U2, rec.V2, col);
                }
            }
        }
        void DrawZ(int z, int x1, int x2, int y1, int y2, int axisSize, FastColour col, ref VertexPos3fTex2fCol4b *vertices)
        {
            int endX = x2, endY = y2, startY = y1;

            for ( ; x1 < endX; x1 += axisSize)
            {
                x2 = x1 + axisSize;
                if (x2 > endX)
                {
                    x2 = endX;
                }
                y1 = startY;
                for ( ; y1 < endY; y1 += axisSize)
                {
                    y2 = y1 + axisSize;
                    if (y2 > endY)
                    {
                        y2 = endY;
                    }

                    TextureRec rec        = new TextureRec(0, 0, x2 - x1, y2 - y1);
                    *          vertices++ = new VertexPos3fTex2fCol4b(x1, y1, z, rec.U1, rec.V2, col);
                    *          vertices++ = new VertexPos3fTex2fCol4b(x1, y2, z, rec.U1, rec.V1, col);
                    *          vertices++ = new VertexPos3fTex2fCol4b(x2, y2, z, rec.U2, rec.V1, col);
                    *          vertices++ = new VertexPos3fTex2fCol4b(x2, y1, z, rec.U2, rec.V2, col);
                }
            }
        }
Beispiel #4
0
        void DrawCoords(VertexPos3fTex2fCol4b[] verts, ref int index, ShadowData data,
                        float x1, float z1, float x2, float z2)
        {
            Vector3   centre = entity.Position;
            BlockInfo info   = game.BlockInfo;

            if (lequal(x2, x1) || lequal(z2, z1))
            {
                return;
            }
            float u1 = (x1 - centre.X) * 16 / 14f + 0.5f;
            float v1 = (z1 - centre.Z) * 16 / 14f + 0.5f;
            float u2 = (x2 - centre.X) * 16 / 14f + 0.5f;
            float v2 = (z2 - centre.Z) * 16 / 14f + 0.5f;

            if (u2 <= 0 || v2 <= 0 || u1 >= 1 || v1 >= 1)
            {
                return;
            }

            x1 = Math.Max(x1, centre.X - 7 / 16f); u1 = Math.Max(u1, 0);
            z1 = Math.Max(z1, centre.Z - 7 / 16f); v1 = Math.Max(v1, 0);
            x2 = Math.Min(x2, centre.X + 7 / 16f); u2 = Math.Min(u2, 1);
            z2 = Math.Min(z2, centre.Z + 7 / 16f); v2 = Math.Min(v2, 1);

            FastColour col = FastColour.White; col.A = data.A;

            verts[index++] = new VertexPos3fTex2fCol4b(x1, data.Y, z1, u1, v1, col);
            verts[index++] = new VertexPos3fTex2fCol4b(x2, data.Y, z1, u2, v1, col);
            verts[index++] = new VertexPos3fTex2fCol4b(x2, data.Y, z2, u2, v2, col);
            verts[index++] = new VertexPos3fTex2fCol4b(x1, data.Y, z2, u1, v2, col);
        }
 static void TransformVertex( ref VertexPos3fTex2fCol4b vertex )
 {
     Vector3 p = new Vector3( vertex.X, vertex.Y, vertex.Z );
     //p = Utils.RotateY( p - pos, time ) + pos;
     // See comment in IGraphicsApi.Draw2DTexture()
     p.X -= 0.5f; p.Y -= 0.5f;
     p = Utils.RotateX( Utils.RotateY( p, cosY, sinY ), cosX, sinX );
     vertex.X = p.X; vertex.Y = p.Y; vertex.Z = p.Z;
 }
        static void TransformVertex(ref VertexPos3fTex2fCol4b vertex)
        {
            Vector3 p = new Vector3(vertex.X, vertex.Y, vertex.Z);

            //p = Utils.RotateY( p - pos, time ) + pos;
            // See comment in IGraphicsApi.Draw2DTexture()
            p.X     -= 0.5f; p.Y -= 0.5f;
            p        = Utils.RotateX(Utils.RotateY(p, cosY, sinY), cosX, sinX);
            vertex.X = p.X; vertex.Y = p.Y; vertex.Z = p.Z;
        }
Beispiel #7
0
        void DraqSquareShadow(VertexPos3fTex2fCol4b[] verts, ref int index, float y, byte alpha, float x, float z)
        {
            FastColour col = FastColour.White; col.A = alpha;
            TextureRec rec = new TextureRec(63 / 128f, 63 / 128f, 1 / 128f, 1 / 128f);

            verts[index++] = new VertexPos3fTex2fCol4b(x, y, z, rec.U1, rec.V1, col);
            verts[index++] = new VertexPos3fTex2fCol4b(x + 1, y, z, rec.U2, rec.V1, col);
            verts[index++] = new VertexPos3fTex2fCol4b(x + 1, y, z + 1, rec.U2, rec.V2, col);
            verts[index++] = new VertexPos3fTex2fCol4b(x, y, z + 1, rec.U1, rec.V2, col);
        }
        void MakeRainForSquare(int x, float y, float height, int z, FastColour col, ref int index)
        {
            float worldV = vOffset + (z & 1) / 2f - (x & 0x0F) / 16f;
            float v1     = y / 6f + worldV;
            float v2     = (y + height) / 6f + worldV;

            vertices[index++] = new VertexPos3fTex2fCol4b(x, y, z, 0, v2, col);
            vertices[index++] = new VertexPos3fTex2fCol4b(x, y + height, z, 0, v1, col);
            vertices[index++] = new VertexPos3fTex2fCol4b(x + 1, y + height, z + 1, 2, v1, col);
            vertices[index++] = new VertexPos3fTex2fCol4b(x + 1, y, z + 1, 2, v2, col);

            vertices[index++] = new VertexPos3fTex2fCol4b(x + 1, y, z, 2, v2, col);
            vertices[index++] = new VertexPos3fTex2fCol4b(x + 1, y + height, z, 2, v1, col);
            vertices[index++] = new VertexPos3fTex2fCol4b(x, y + height, z + 1, 0, v1, col);
            vertices[index++] = new VertexPos3fTex2fCol4b(x, y, z + 1, 0, 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);
        }
        void MakeRainForSquare( int x, int y, int height, int z, FastColour col, ref int index )
        {
            float v1 = vOffset + (z & 0x01) * 0.5f - (x & 0x0F) * 0.0625f;
            float v2 = height / 6f + v1;

            vertices[index++] = new VertexPos3fTex2fCol4b( x, y, z, 0, v2, col );
            vertices[index++] = new VertexPos3fTex2fCol4b( x, y + height, z, 0, v1, col );
            vertices[index++] = new VertexPos3fTex2fCol4b( x + 1, y + height, z + 1, 2, v1, col );
            vertices[index++] = new VertexPos3fTex2fCol4b( x + 1, y, z + 1, 2, v2, col );

            vertices[index++] = new VertexPos3fTex2fCol4b( x + 1, y, z, 2, v2, col );
            vertices[index++] = new VertexPos3fTex2fCol4b( x + 1, y + height, z, 2, v1, col );
            vertices[index++] = new VertexPos3fTex2fCol4b( x, y + height, z + 1, 0, v1, col );
            vertices[index++] = new VertexPos3fTex2fCol4b( x, y, z + 1, 0, v2, col );
        }
        void DrawZ( int z, int x1, int x2, int y1, int y2, int axisSize, FastColour col, ref VertexPos3fTex2fCol4b* vertices )
        {
            int endX = x2, endY = y2, startY = y1;
            for( ; x1 < endX; x1 += axisSize ) {
                x2 = x1 + axisSize;
                if( x2 > endX ) x2 = endX;
                y1 = startY;
                for( ; y1 < endY; y1 += axisSize ) {
                    y2 = y1 + axisSize;
                    if( y2 > endY ) y2 = endY;

                    TextureRectangle rec = new TextureRectangle( 0, 0, x2 - x1, y2 - y1 );
                    *vertices++ = new VertexPos3fTex2fCol4b( x1, y1, z, rec.U1, rec.V1, col );
                    *vertices++ = new VertexPos3fTex2fCol4b( x1, y2, z, rec.U1, rec.V2, col );
                    *vertices++ = new VertexPos3fTex2fCol4b( x2, y2, z, rec.U2, rec.V2, col );
                    *vertices++ = new VertexPos3fTex2fCol4b( x2, y1, z, rec.U2, rec.V1, col );
                }
            }
        }
        void DrawY( int x1, int z1, int x2, int z2, int y, int axisSize, FastColour col, ref VertexPos3fTex2fCol4b* vertices )
        {
            int endX = x2, endZ = z2, startZ = z1;
            for( ; x1 < endX; x1 += axisSize ) {
                x2 = x1 + axisSize;
                if( x2 > endX ) x2 = endX;
                z1 = startZ;
                for( ; z1 < endZ; z1 += axisSize ) {
                    z2 = z1 + axisSize;
                    if( z2 > endZ ) z2 = endZ;

                    TextureRectangle rec = new TextureRectangle( 0, 0, x2 - x1, z2 - z1 );
                    *vertices++ = new VertexPos3fTex2fCol4b( x1, y, z1, rec.U1, rec.V1, col );
                    *vertices++ = new VertexPos3fTex2fCol4b( x1, y, z2, rec.U1, rec.V2, col );
                    *vertices++ = new VertexPos3fTex2fCol4b( x2, y, z2, rec.U2, rec.V2, col );
                    *vertices++ = new VertexPos3fTex2fCol4b( x2, y, z1, rec.U2, rec.V1, col );
                }
            }
        }
        void DrawX( int x, int z1, int z2, int y1, int y2, int axisSize, FastColour col, ref VertexPos3fTex2fCol4b* vertices )
        {
            int endZ = z2, endY = y2, startY = y1;
            for( ; z1 < endZ; z1 += axisSize ) {
                z2 = z1 + axisSize;
                if( z2 > endZ ) z2 = endZ;
                y1 = startY;
                for( ; y1 < endY; y1 += axisSize ) {
                    y2 = y1 + axisSize;
                    if( y2 > endY ) y2 = endY;

                    TextureRectangle rec = new TextureRectangle( 0, 0, z2 - z1, y2 - y1 );
                    *vertices++ = new VertexPos3fTex2fCol4b( x, y1, z1, rec.U1, rec.V1, col );
                    *vertices++ = new VertexPos3fTex2fCol4b( x, y2, z1, rec.U1, rec.V2, col );
                    *vertices++ = new VertexPos3fTex2fCol4b( x, y2, z2, rec.U2, rec.V2, col );
                    *vertices++ = new VertexPos3fTex2fCol4b( x, y1, z2, rec.U2, rec.V1, col );
                }
            }
        }
        void MakeRainForSquare( int x, float y, float height, int z, FastColour col, ref int index )
        {
            float worldV = vOffset + (z & 1) / 2f - (x & 0x0F) / 16f;
            float v1 = y / 6f + worldV;
            float v2 = (y + height) / 6f + worldV;

            vertices[index++] = new VertexPos3fTex2fCol4b( x, y, z, 0, v2, col );
            vertices[index++] = new VertexPos3fTex2fCol4b( x, y + height, z, 0, v1, col );
            vertices[index++] = new VertexPos3fTex2fCol4b( x + 1, y + height, z + 1, 2, v1, col );
            vertices[index++] = new VertexPos3fTex2fCol4b( x + 1, y, z + 1, 2, v2, col );

            vertices[index++] = new VertexPos3fTex2fCol4b( x + 1, y, z, 2, v2, col );
            vertices[index++] = new VertexPos3fTex2fCol4b( x + 1, y + height, z, 2, v1, col );
            vertices[index++] = new VertexPos3fTex2fCol4b( x, y + height, z + 1, 0, v1, col );
            vertices[index++] = new VertexPos3fTex2fCol4b( x, y, z + 1, 0, v2, col );
        }