コード例 #1
0
ファイル: RayMarchingAo.cs プロジェクト: wachel/block
        public static Color[] ToColorsA(RayTraceChunkManager rtc, int bits)
        {
            int dcx = rtc.getChunkSize().x;
            int dcy = rtc.getChunkSize().y;
            int dcz = rtc.getChunkSize().z;
            int dgx = rtc.getSizeX();
            int dgy = rtc.getSizeY();
            int dgz = rtc.getSizeZ();

            Color[,,] colors = new Color[dgx, (dgy / bits), dgz];
            for (int cx = 0; cx < dcx; cx++)
            {
                for (int cy = 0; cy < dcy; cy++)
                {
                    for (int cz = 0; cz < dcz; cz++)
                    {
                        RayTraceChunk chunk = rtc.getChunk(cx, cy, cz);
                        for (int bx = 0; bx < Const.ChunkSize; bx++)
                        {
                            for (int by = 0; by < Const.ChunkSize / bits; by++)
                            {
                                for (int bz = 0; bz < Const.ChunkSize; bz++)
                                {
                                    int iv = 0;
                                    for (int n = 0; n < bits; n++)
                                    {
                                        iv |= chunk.testBlock(bx, by * bits + n, bz) ? (1 << n) : 0;
                                    }
                                    float a  = iv / (float)((1 << bits) - 1);
                                    int   gx = cx * Const.ChunkSize + bx;
                                    int   gy = cy * Const.ChunkSize / bits + by;
                                    int   gz = cz * Const.ChunkSize + bz;
                                    colors[gx, gy, gz] = new Color(0, 0, 0, a);
                                }
                            }
                        }
                    }
                }
            }

            int sizeX = colors.GetLength(0);
            int sizeY = colors.GetLength(1);
            int sizeZ = colors.GetLength(2);

            Color[] rlt = new Color[sizeX * sizeY * sizeZ];
            for (int x = 0; x < sizeX; x++)
            {
                for (int y = 0; y < sizeY; y++)
                {
                    for (int z = 0; z < sizeZ; z++)
                    {
                        rlt[z * sizeY * sizeX + y * sizeX + x] = colors[x, y, z];
                    }
                }
            }
            return(rlt);
        }
コード例 #2
0
ファイル: RayTraceChunkManager.cs プロジェクト: wachel/block
 private void updateChunk(bool[] data, int chunkSize, RayTraceChunk chunk)
 {
     chunk.clearAll();
     for (int k = 0; k < chunkSize; k++)
     {
         for (int j = 0; j < chunkSize; j++)
         {
             for (int i = 0; i < chunkSize; i++)
             {
                 if (data[k * chunkSize * chunkSize + j * chunkSize + i])
                 {
                     chunk.setBlock(i, j, k);
                 }
             }
         }
     }
 }
コード例 #3
0
ファイル: RayTraceChunkManager.cs プロジェクト: wachel/block
 public void create(int chunkNumX, int chunkNumY, int chunkNumZ, int chunkSize)
 {
     curStartChunkX = curStartChunkY = curStartChunkZ = -65536;
     sizeX          = chunkNumX; sizeY = chunkNumY; sizeZ = chunkNumZ;
     this.chunkSize = chunkSize;
     chunks         = new RayTraceChunk[sizeX, sizeY, sizeZ];
     for (int k = 0; k < sizeZ; k++)
     {
         for (int j = 0; j < sizeY; j++)
         {
             for (int i = 0; i < sizeX; i++)
             {
                 RayTraceChunk temp = new RayTraceChunk();
                 temp.create(chunkSize, chunkSize, chunkSize);
                 temp.clearAll();
                 chunks[i, j, k] = temp;
             }
         }
     }
 }
コード例 #4
0
ファイル: RayTraceChunkManager.cs プロジェクト: wachel/block
        public void moveTo(int startChunkX, int startChunkY, int startChunkZ, GetChunkFun getChunk)
        {
            RayTraceChunk[,,] oldChunks = new RayTraceChunk[chunks.GetLength(0), chunks.GetLength(1), chunks.GetLength(2)];
            for (int k = 0; k < sizeZ; k++)
            {
                for (int j = 0; j < sizeY; j++)
                {
                    for (int i = 0; i < sizeX; i++)
                    {
                        oldChunks[i, j, k] = chunks[i, j, k];
                    }
                }
            }

            int dx = startChunkX - curStartChunkX;
            int dy = startChunkY - curStartChunkY;
            int dz = startChunkZ - curStartChunkZ;

            for (int k = 0; k < sizeZ; k++)
            {
                for (int j = 0; j < sizeY; j++)
                {
                    for (int i = 0; i < sizeX; i++)
                    {
                        int fromX = i + dx;
                        int fromY = j + dy;
                        int fromZ = k + dz;
                        chunks[i, j, k] = oldChunks[(fromX % sizeX), (fromY % sizeY), (fromZ % sizeZ)];
                        if (fromX < 0 || fromX >= sizeX || fromY < 0 || fromY >= sizeY || fromZ < 0 || fromZ >= sizeZ)
                        {
                            //此格子不在原范围,需要更新
                            bool[] temp = getChunk(startChunkX + i, startChunkY + j, startChunkZ + k);
                            updateChunk(temp, chunkSize, chunks[i, j, k]);
                        }
                    }
                }
            }
            curStartChunkX = startChunkX;
            curStartChunkY = startChunkY;
            curStartChunkZ = startChunkZ;
        }