Пример #1
0
        void MakeStars()
        {
            VertexP3fT2fC4b v;

            v.Colour = starColour.Pack();

            for (int i = 0; i < 500; i++)
            {
                float pitch = (float)(Utils.Lerp(0.025f, 0.975f, rand.NextFloat()) * 2 * Math.PI);
                float yaw   = (float)(Utils.Lerp(0.025f, 0.975f, rand.NextFloat()) * 2 * Math.PI);

                const float size = 0.001f;
                Vector3     p00  = new Vector3(-size, -size, 0.2f);
                Vector3     p10  = new Vector3(+size, -size, 0.2f);
                Vector3     p11  = new Vector3(+size, +size, 0.2f);
                Vector3     p01  = new Vector3(-size, +size, 0.2f);

                p00 = Utils.RotateY(p00, yaw);
                p10 = Utils.RotateY(p10, yaw);
                p11 = Utils.RotateY(p11, yaw);
                p01 = Utils.RotateY(p01, yaw);

                p00 = Utils.RotateZ(p00, pitch);
                p10 = Utils.RotateZ(p10, pitch);
                p11 = Utils.RotateZ(p11, pitch);
                p01 = Utils.RotateZ(p01, pitch);

                v.X = p00.X; v.Y = p00.Y; v.Z = p00.Z; v.U = 0.00f; v.V = 0.00f; vertices4[index3] = v; index3++;
                v.X = p10.X; v.Y = p10.Y; v.Z = p10.Z; v.U = 1.00f;              vertices4[index3] = v; index3++;
                v.X = p11.X; v.Y = p11.Y; v.Z = p11.Z;              v.V = 1.00f; vertices4[index3] = v; index3++;
                v.X = p01.X; v.Y = p01.Y; v.Z = p01.Z; v.U = 0.00f;              vertices4[index3] = v; index3++;
            }
            madeStars = true;
        }
Пример #2
0
        void GrowTree(int treeX, int treeY, int treeZ, int height)
        {
            int baseHeight = height - 4;

            // leaves bottom layer
            for (int y = treeY + baseHeight; y < treeY + baseHeight + 2; y++)
            {
                for (int zz = -2; zz <= 2; zz++)
                {
                    for (int xx = -2; xx <= 2; xx++)
                    {
                        int x = xx + treeX, z = zz + treeZ;

                        if (Math.Abs(xx) == 2 && Math.Abs(zz) == 2)
                        {
                            if (rnd.NextFloat() >= 0.5)
                            {
                                ChunkHandler.SetBlockAdj(x, y, z, Block.Leaves);
                            }
                        }
                        else
                        {
                            ChunkHandler.SetBlockAdj(x, y, z, Block.Leaves);
                        }
                    }
                }
            }

            // leaves top layer
            int bottomY = treeY + baseHeight + 2;

            for (int y = treeY + baseHeight + 2; y < treeY + height; y++)
            {
                for (int zz = -1; zz <= 1; zz++)
                {
                    for (int xx = -1; xx <= 1; xx++)
                    {
                        int x = xx + treeX, z = zz + treeZ;

                        if (xx == 0 || zz == 0)
                        {
                            ChunkHandler.SetBlockAdj(x, y, z, Block.Leaves);
                        }
                        else if (y == bottomY && rnd.NextFloat() >= 0.5)
                        {
                            ChunkHandler.SetBlockAdj(x, y, z, Block.Leaves);
                        }
                    }
                }
            }

            // then place trunk
            for (int y = 0; y < height - 1; y++)
            {
                //blocks[index] = Block.Log;
                ChunkHandler.SetBlockAdj(treeX, (treeY + y), treeZ, Block.Log);
            }
        }
Пример #3
0
        public unsafe void Tick(int *ptr, int size)
        {
            if (rnd == null)
            {
                rnd = new JavaRandom(new Random().Next());
            }
            int mask = size - 1, shift = CheckSize(size);

            int i = 0;

            for (int y = 0; y < size; y++)
            {
                for (int x = 0; x < size; x++)
                {
                    // Calculate the colour at this coordinate in the heatmap
                    float lSoupHeat = 0;
                    int   xOffset   = x + (int)(1.2 * Math.Sin(y * 22.5 * Utils.Deg2Rad));
                    int   yOffset   = y + (int)(1.2 * Math.Sin(x * 22.5 * Utils.Deg2Rad));
                    for (int j = 0; j < 9; j++)
                    {
                        int xx = xOffset + (j % 3 - 1);
                        int yy = yOffset + (j / 3 - 1);
                        lSoupHeat += soupHeat[(yy & mask) << shift | (xx & mask)];
                    }

                    float lPotHeat = potHeat[i]                                              // x    , y
                                     + potHeat[y << shift | ((x + 1) & mask)] +              // x + 1, y
                                     +potHeat[((y + 1) & mask) << shift | x] +               // x    , y + 1
                                     +potHeat[((y + 1) & mask) << shift | ((x + 1) & mask)]; // x + 1, y + 1

                    soupHeat[i] = lSoupHeat * 0.1f + lPotHeat * 0.2f;
                    potHeat[i] += flameHeat[i];
                    if (potHeat[i] < 0)
                    {
                        potHeat[i] = 0;
                    }
                    flameHeat[i] -= 0.06f * 0.01f;

                    if (rnd.NextFloat() <= 0.005f)
                    {
                        flameHeat[i] = 1.5f * 0.01f;
                    }

                    // Output the pixel
                    float col = 2 * soupHeat[i];
                    col = col < 0 ? 0 : col;
                    col = col > 1 ? 1 : col;

                    float r   = col * 100 + 155;
                    float g   = col * col * 255;
                    float b   = col * col * col * col * 128;
                    *     ptr = 255 << 24 | (byte)r << 16 | (byte)g << 8 | (byte)b;

                    ptr++; i++;
                }
            }
        }