Beispiel #1
0
        /// <summary>
        /// Constructs a new demo.
        /// </summary>
        /// <param name="game">Game owning this demo.</param>
        public PlanetDemo(DemosGame game)
            : base(game)
        {
            Space.ForceUpdater.Gravity = Vector3.Zero;

            //By pre-allocating a bunch of box-box pair handlers, the simulation will avoid having to allocate new ones at runtime.
            NarrowPhaseHelper.Factories.BoxBox.EnsureCount(1000);

            var planet = new Sphere(new Vector3(0, 0, 0), 30);
            Space.Add(planet);

            var field = new GravitationalField(new InfiniteForceFieldShape(), planet.Position, 66730 / 2f, 100);
            Space.Add(field);

            //Drop the "meteorites" on the planet.
            Entity toAdd;
            int numColumns = 10;
            int numRows = 10;
            int numHigh = 10;
            float separation = 5;
            for (int i = 0; i < numRows; i++)
                for (int j = 0; j < numColumns; j++)
                    for (int k = 0; k < numHigh; k++)
                    {
                        toAdd = new Box(new Vector3(separation * i - numRows * separation / 2, 40 + k * separation, separation * j - numColumns * separation / 2), 1f, 1f, 1f, 5);
                        toAdd.LinearVelocity = new Vector3(30, 0, 0);
                        toAdd.LinearDamping = 0;
                        toAdd.AngularDamping = 0;
                        Space.Add(toAdd);
                    }
            game.Camera.Position = new Vector3(0, 0, 150);
        }
        int BuildPlanetSimulation(Space space)
        {
            space.ForceUpdater.Gravity = Vector3.Zero;


            var planet = new Sphere(new Vector3(0, 0, 0), 30);
            space.Add(planet);

            var field = new GravitationalField(new InfiniteForceFieldShape(), planet.Position, 66730 / 2f, 100);
            space.Add(field);

            //Drop the "meteorites" on the planet.
            Entity toAdd;
#if WINDOWS
            //By pre-allocating a bunch of box-box pair handlers, the simulation will avoid having to allocate new ones at runtime.
            NarrowPhaseHelper.Factories.BoxBox.EnsureCount(30000);

            int numColumns = 25;
            int numRows = 25;
            int numHigh = 25;
#else
            NarrowPhaseHelper.Factories.BoxBox.EnsureCount(2000);
            int numColumns = 10;
            int numRows = 10;
            int numHigh = 10;
#endif
            float separation = 5;
            for (int i = 0; i < numRows; i++)
                for (int j = 0; j < numColumns; j++)
                    for (int k = 0; k < numHigh; k++)
                    {
                        toAdd = new Box(new Vector3(separation * i - numRows * separation / 2, 40 + k * separation, separation * j - numColumns * separation / 2), 1f, 1f, 1f, 5);
                        toAdd.LinearVelocity = new Vector3(30, 0, 0);
                        toAdd.LinearDamping = 0;
                        toAdd.AngularDamping = 0;
                        space.Add(toAdd);
                    }
#if WINDOWS
            return 3000;
#else
            return 1000;
#endif
        }