示例#1
0
        public uint DrawToTexture(Map map, CustomVertex.TransformedTextured[] pV, float cogX, float cogY)
        {
            const float CellSize = 16.0f;
            const uint uChars = 16;
            const uint vChars = 2;
            const float uScale = 1.0f / uChars;
            const float vScale = 1.0f / vChars;

            uint startX = 0;
            uint endX = 0;
            uint startY = 0;
            uint endY = 0;
            map.GetActive(ref cogX, ref cogY, ref startX, ref startY, ref endX, ref endY);

            float xBase = -cogX * 16.0f - 0.5f;
            float yBase = -cogY * 16.0f - 0.5f;

            uint dwNumTris = 0;
            uint index = 0;
            for(uint x = startX; x < endX; x++)
            {
            for(uint y = startY; y < endY; y ++)
            {
                byte b = (byte) map.Get(x, y);
                float uLow = (b % uChars) * uScale;
                float uHigh = uLow + uScale;
                float vLow = (b / uChars) * vScale;
                float vHigh = vLow + vScale;

                float xLow = xBase + x * CellSize;
                float xHigh = xLow + CellSize;
                float yLow = yBase + y * CellSize;
                float yHigh = yLow + CellSize;

                // Set the two triangles

                // First triangle
                pV[index].X = xLow;
                pV[index].Y = yLow;
                pV[index].Z = 0.0f;
                pV[index].Rhw = 1.0f;
                pV[index].Tu = uLow;
                pV[index].Tv = vLow;

                index++;

                pV[index].X = xHigh;
                pV[index].Y = yLow;
                pV[index].Z = 0.0f;
                pV[index].Rhw = 1.0f;
                pV[index].Tu = uHigh;
                pV[index].Tv = vLow;

                index++;

                pV[index].X = xLow;
                pV[index].Y = yHigh;
                pV[index].Z = 0.0f;
                pV[index].Rhw = 1.0f;
                pV[index].Tu = uLow;
                pV[index].Tv = vHigh;

                // Second triangle
                index++;

                pV[index].X = xLow;
                pV[index].Y = yHigh;
                pV[index].Z = 0.0f;
                pV[index].Rhw = 1.0f;
                pV[index].Tu = uLow;
                pV[index].Tv = vHigh;

                index++;

                pV[index].X = xHigh;
                pV[index].Y = yLow;
                pV[index].Z = 0.0f;
                pV[index].Rhw = 1.0f;
                pV[index].Tu = uHigh;
                pV[index].Tv = vLow;

                index++;

                pV[index].X = xHigh;
                pV[index].Y = yHigh;
                pV[index].Z = 0.0f;
                pV[index].Rhw = 1.0f;
                pV[index].Tu = uHigh;
                pV[index].Tv = vHigh;

                index++;

                dwNumTris += 2;
            }
            }
            return dwNumTris;
        }