예제 #1
0
        /// <summary>
        /// Call this to start the demo
        /// (Entry Point)
        /// </summary>
        public static void Run()
        {
            //do this becuase .Net has been erroring with file permissions
            //just leave this line it.
            string dir = Settings.DataDir;


            //create a new window to display stuff
            Window window = new Window(new System.Drawing.Size(1000, 750));
            window.Title = "Physics2D.Net Demo";


            //Create a new Scene 
            Scene scene = new Scene();

            //Get the scene's physics engine
            PhysicsEngine physicsEngine = scene.Engine;
            //initialize the engine 
            physicsEngine.BroadPhase = new Physics2DDotNet.Detectors.SweepAndPruneDetector();
            //physicsEngine.BroadPhase = new Physics2DDotNet.Detectors.SpatialHashDetector();
            Physics2DDotNet.Solvers.SequentialImpulsesSolver solver= new Physics2DDotNet.Solvers.SequentialImpulsesSolver();
            //solver.Iterations = 3;
            solver.Freezing = true;
            physicsEngine.Solver = solver;
            //physicsEngine.Solver = new Physics2DDotNet.Solvers.Box2DSolver();



            Viewport viewport = new Viewport(
                new Rectangle(0, 0, window.Size.Width, window.Size.Height), //where
                Matrix2x3.Identity, //how
                scene, //who
                new Lifespan()); // how long 
            window.AddViewport(viewport);

            // you can change the veiwport via this 
            viewport.ToScreen = Matrix2x3.FromTransformation(.09f, new Vector2D(40, 0));

            //make it so the veiwport will be resized whn the window is
            window.Resized += delegate(object sender, SizeEventArgs e)
            {
                viewport.Width = e.Width;
                viewport.Height = e.Height;
            };
            System.Windows.Forms.Application.EnableVisualStyles();
            //create the GUI
            DemoSelector selector = new DemoSelector();
            //initialize the GUI
            selector.Initialize(window, viewport, scene);
            //Create the window
            window.Intialize();
            window.DrawingInterval = .02f;
            //Add some intro text
            AddIntroText(window, viewport, scene);

            SetupStatus(window, scene);


            //Show the GUI
            selector.Show();
            //start the physicstimer for Layer.PhysicsEngine
            scene.Timer.IsRunning = true;
            //Begin the rendering loop. 
            window.Run();
            return;
        }
예제 #2
0
        /// <summary>
        /// Call this to start the demo
        /// (Entry Point)
        /// </summary>
        public static void Run()
        {
            //do this becuase .Net has been erroring with file permissions
            //just leave this line it.
            string dir = Settings.DataDir;


            //create a new window to display stuff
            Window window = new Window(new System.Drawing.Size(1000, 750));

            window.Title = "Physics2D.Net Demo";


            //Create a new Scene
            Scene scene = new Scene();

            //Get the scene's physics engine
            PhysicsEngine physicsEngine = scene.Engine;

            //initialize the engine
            physicsEngine.BroadPhase = new Physics2DDotNet.Detectors.SweepAndPruneDetector();
            //physicsEngine.BroadPhase = new Physics2DDotNet.Detectors.SpatialHashDetector();
            Physics2DDotNet.Solvers.SequentialImpulsesSolver solver = new Physics2DDotNet.Solvers.SequentialImpulsesSolver();
            //solver.Iterations = 3;
            solver.Freezing      = true;
            physicsEngine.Solver = solver;
            //physicsEngine.Solver = new Physics2DDotNet.Solvers.Box2DSolver();



            Viewport viewport = new Viewport(
                new Rectangle(0, 0, window.Size.Width, window.Size.Height), //where
                Matrix2x3.Identity,                                         //how
                scene,                                                      //who
                new Lifespan());                                            // how long

            window.AddViewport(viewport);

            // you can change the veiwport via this
            viewport.ToScreen = Matrix2x3.FromTransformation(.09f, new Vector2D(40, 0));

            //make it so the veiwport will be resized whn the window is
            window.Resized += delegate(object sender, SizeEventArgs e)
            {
                viewport.Width  = e.Width;
                viewport.Height = e.Height;
            };
            System.Windows.Forms.Application.EnableVisualStyles();
            //create the GUI
            DemoSelector selector = new DemoSelector();

            //initialize the GUI
            selector.Initialize(window, viewport, scene);
            //Create the window
            window.Intialize();
            window.DrawingInterval = .02f;
            //Add some intro text
            AddIntroText(window, viewport, scene);

            SetupStatus(window, scene);


            //Show the GUI
            selector.Show();
            //start the physicstimer for Layer.PhysicsEngine
            scene.Timer.IsRunning = true;
            //Begin the rendering loop.
            window.Run();
            return;
        }