예제 #1
0
        public Planet(Session session)
        {
            Session = session;

            Console.WriteLine("\nGenerating planet...");
            Stopwatch stopwatch = Stopwatch.StartNew();

            Icosphere icosphere = new Icosphere(7);

            initializeVertices(icosphere);
            initializeAdjacencies(icosphere.Triangles);
            createTiles();
            expandTiles();
            resetOuterVertices();
            createRegions();
            expandRegions();
            resetOuterTiles();
            randomizeElevation();
            simulateClimate();
            indices = icosphere.GetIndices().ToList();
            buildVertexBuffer();
            buildIndexBuffer();

            stopwatch.Stop();
            Console.WriteLine("Total: " + stopwatch.ElapsedMilliseconds + " ms");
        }
예제 #2
0
        void initializeVertices(Icosphere icosphere)
        {
            Console.Write("Initializing vertices... ");
            Stopwatch stopwatch = Stopwatch.StartNew();

            vertices = new List <PlanetVertex>(icosphere.Vertices.Count);
            float vertexSeparation = icosphere.GetVertexSeparation();

            for (int i = 0; i < icosphere.Vertices.Count; i++)
            {
                Vector3 position = icosphere.Vertices[i];
                float   xOffset  = (-0.5f + random.NextFloat()) * vertexSeparation / 2;
                float   yOffset  = (-0.5f + random.NextFloat()) * vertexSeparation / 2;
                float   zOffset  = (-0.5f + random.NextFloat()) * vertexSeparation / 2;
                position += new Vector3(xOffset, yOffset, zOffset);
                position.Normalize();

                PlanetVertex vertex = new PlanetVertex(position);
                vertices.Add(vertex);
            }

            stopwatch.Stop();
            Console.WriteLine("" + stopwatch.ElapsedMilliseconds + " ms");
        }