예제 #1
0
        public void OnUpdate()
        {
            FrameDelta         = Clock.GetFrameDelta();
            _frameAccumulator += FrameDelta;
            if (_frameAccumulator >= 1.0f)
            {
                FramesPerSecond = Clock.FrameCount / _frameAccumulator;
                SetInfoText();

                _frameAccumulator = 0.0f;
                Clock.Reset();
            }

            if (_updateReceiver != null)
            {
                _updateReceiver.Update(this);
            }
            HandleKeyboardInput();
            _bodyPicker.Update();

            Clock.StartPhysics();
            int substepsPassed = Simulation.World.StepSimulation(FrameDelta);

            Clock.StopPhysics(substepsPassed);

            if (FreeLook.Update(FrameDelta))
            {
                Graphics.UpdateView();
            }

            Input.ClearKeyCache();
        }
예제 #2
0
        public void Run()
        {
            using (Graphics = GraphicsLibraryManager.GetGraphics(this))
            {
                if (Graphics == null)
                {
                    return;
                }

                Graphics.Initialize();
                Graphics.CullingEnabled = true;

                Input    = new Input(Graphics.Form);
                FreeLook = new FreeLook(Input);

                InitializePhysics();
                if (_isDebugDrawEnabled)
                {
                    InitializeDebugDrawer();
                }

                Graphics.UpdateView();
                SetInfoText();

                Graphics.Run();
            }
            Graphics = null;

            UninitializeDebugDrawer();
            UninitializePhysics();
        }
예제 #3
0
파일: DemoGame.cs 프로젝트: diqost/bullet
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            base.Initialize();

            Input          = new Input();
            FreeLook       = new FreeLook(Input);
            IsMouseVisible = true;
        }
예제 #4
0
        public void Run()
        {
            using (Graphics = GraphicsLibraryManager.GetGraphics(this))
            {
                Input    = new Input(Graphics.Form);
                Freelook = new FreeLook(Input);

                Graphics.Initialize();
                Graphics.CullingEnabled = isCullingEnabled;
                OnInitialize();

                if (World == null)
                {
                    OnInitializePhysics();
                    BulletExampleRunner.Get().PostOnInitializePhysics();
                }

                if (_isDebugDrawEnabled)
                {
                    if (_debugDrawer == null)
                    {
                        _debugDrawer           = Graphics.GetPhysicsDebugDrawer();
                        _debugDrawer.DebugMode = DebugDrawMode;
                    }
                    if (World != null)
                    {
                        World.DebugDrawer = _debugDrawer;
                    }
                }

                Graphics.UpdateView();

                clock.Start();

                Graphics.Run();

                /*
                 * if (_debugDrawer != null)
                 * {
                 * if (World != null)
                 * {
                 * World.DebugDrawer = null;
                 * }
                 * if (_debugDrawer is IDisposable)
                 * {
                 * (_debugDrawer as IDisposable).Dispose();
                 * }
                 * _debugDrawer = null;
                 * }
                 */
            }
            //Graphics = null;
        }
예제 #5
0
        public void Run()
        {
            using (Graphics = GraphicsLibraryManager.GetGraphics(this))
            {
                Input    = new Input(Graphics.Form);
                Freelook = new FreeLook(Input);

                _bodyPicker = new BodyPicker(this);

                Graphics.Initialize();
                Graphics.CullingEnabled = isCullingEnabled;
                OnInitialize();
                if (World == null)
                {
                    OnInitializePhysics();
                }
                if (_isDebugDrawEnabled)
                {
                    if (_debugDrawer == null)
                    {
                        _debugDrawer           = Graphics.GetPhysicsDebugDrawer();
                        _debugDrawer.DebugMode = DebugDrawMode;
                    }
                    if (World != null)
                    {
                        World.DebugDrawer = _debugDrawer;
                    }
                }
                Graphics.UpdateView();
                SetInfoText();

                Graphics.Run();

                if (_debugDrawer != null)
                {
                    if (World != null)
                    {
                        World.DebugDrawer = null;
                    }
                    if (_debugDrawer is IDisposable)
                    {
                        (_debugDrawer as IDisposable).Dispose();
                    }
                    _debugDrawer = null;
                }
            }
            Graphics = null;
        }
예제 #6
0
        public void Run()
        {
            if (_graphics != null)
            {
                _graphics.Form.Close();
            }
            _graphics = LibraryManager.GetGraphics(this);

            _input   = new Input(Graphics.Form);
            Freelook = new FreeLook(_input);

            _graphics.Initialize();
            OnInitialize();
            OnInitializePhysics();
            _graphics.UpdateView();

            clock.Start();
            _graphics.Run();
        }
예제 #7
0
파일: Demo.cs 프로젝트: diqost/bullet
        public void Run()
        {
            Input    = new Input(Form);
            Freelook = new FreeLook(Input);

            Initialize();
            CullingEnabled = isCullingEnabled;
            OnInitialize();
            if (PhysicsContext.World == null)
            {
                PhysicsContext.InitPhysics();
            }

            /*
             * if (_isDebugDrawEnabled)
             * {
             *  if (_debugDrawer == null)
             *  {
             *      _debugDrawer = new PhysicsDebugDraw(this);
             *      _debugDrawer.DebugMode = DebugDrawMode;
             *  }
             *  if (PhysicsContext.World != null)
             *  {
             *      PhysicsContext.World.DebugDrawer = _debugDrawer;
             *  }
             * }
             */
            UpdateView();
            SetInfoText();

            RenderLoop.Run(Form, () =>
            {
                OnHandleInput();
                OnUpdate();
                if (Form.WindowState != FormWindowState.Minimized)
                {
                    clock.StartRender();
                    Render();
                    clock.StopRender();
                }
            });
        }
예제 #8
0
        /// <summary>
        /// Runs the demo.
        /// </summary>
        public void Run()
        {
            bool isFormClosed   = false;
            bool formIsResizing = false;

            Form = new RenderForm();

            /*
             * currentFormWindowState = Form.WindowState;
             * Form.Resize += (o, args) =>
             * {
             *  if (Form.WindowState != currentFormWindowState)
             *  {
             *      if (togglingFullScreen == false)
             *          HandleResize(o, args);
             *  }
             *
             *  currentFormWindowState = Form.WindowState;
             * };
             */
            Form.ResizeBegin += (o, args) => { formIsResizing = true; };
            Form.ResizeEnd   += (o, args) =>
            {
                Width  = Form.ClientSize.Width;
                Height = Form.ClientSize.Height;

                renderView.Dispose();
                depthView.Dispose();
                _swapChain.ResizeBuffers(_swapChain.Description.BufferCount, Width, Height, _swapChain.Description.ModeDescription.Format, _swapChain.Description.Flags);

                CreateBuffers();

                SetSceneConstants();
                formIsResizing = false;
            };

            //Form.Closed += (o, args) => { isFormClosed = true; };

            Input = new Input(Form);

            Width            = 1024;
            Height           = 768;
            FullScreenWidth  = Screen.PrimaryScreen.Bounds.Width;
            FullScreenHeight = Screen.PrimaryScreen.Bounds.Height;
            NearPlane        = 1.0f;
            FarPlane         = 200.0f;

            FieldOfView = (float)Math.PI / 4;
            Freelook    = new FreeLook(Input);
            ambient     = new Color4(Color.Gray.ToArgb());

            try
            {
                OnInitializeDevice();
            }
            catch (Exception e)
            {
                MessageBox.Show(e.ToString(), "Could not create DirectX 10 device.");
                return;
            }

            Initialize();

            clock.Start();
            RenderLoop.Run(Form, () =>
            {
                OnHandleInput();
                Update();
                Render();
                Input.ClearKeyCache();
            });
        }
예제 #9
0
파일: Game.cs 프로젝트: diqost/bullet
        /// <summary>
        /// Runs the game.
        /// </summary>
        public void Run()
        {
            bool isFormClosed   = false;
            bool formIsResizing = false;

            Form = new RenderForm();

            currentFormWindowState = Form.WindowState;
            Form.Resize           += (o, args) =>
            {
                if (Form.WindowState != currentFormWindowState)
                {
                    if (togglingFullScreen == false)
                    {
                        HandleResize(o, args);
                    }
                }

                currentFormWindowState = Form.WindowState;
            };

            Form.ResizeBegin += (o, args) => { formIsResizing = true; };
            Form.ResizeEnd   += (o, args) =>
            {
                formIsResizing = false;
                HandleResize(o, args);
            };

            Form.Closed += (o, args) => { isFormClosed = true; };


            // initialize input
            SlimDX.RawInput.Device.RegisterDevice(UsagePage.Generic, UsageId.Keyboard, DeviceFlags.None);
            SlimDX.RawInput.Device.RegisterDevice(UsagePage.Generic, UsageId.Mouse, DeviceFlags.None);

            Input = new Input(Form);

            SlimDX.RawInput.Device.KeyboardInput += Input.Device_KeyboardInput;
            SlimDX.RawInput.Device.MouseInput    += Input.Device_MouseInput;


            Width            = 1024;
            Height           = 768;
            FullScreenWidth  = Screen.PrimaryScreen.Bounds.Width;
            FullScreenHeight = Screen.PrimaryScreen.Bounds.Height;
            NearPlane        = 0.1f;
            FarPlane         = 200f;
            FieldOfView      = (float)Math.PI / 4;
            Freelook         = new FreeLook(Input);
            Ambient          = Color.Gray.ToArgb();

            OnInitializeDevice();

            Fps         = new FpsDisplay(Device);
            MeshFactory = new GraphicObjectFactory(Device);

            OnInitialize();
            OnResetDevice();

            clock.Start();
            MessagePump.Run(Form, () =>
            {
                OnHandleInput();
                Update();
                Input.ClearKeyCache();

                if (isFormClosed)
                {
                    return;
                }

                if (!formIsResizing)
                {
                    Render();
                }
            });

            SlimDX.RawInput.Device.KeyboardInput -= Input.Device_KeyboardInput;
            SlimDX.RawInput.Device.MouseInput    -= Input.Device_MouseInput;

            OnLostDevice();
        }
예제 #10
0
        public void Run()
        {
            using (Graphics = GraphicsLibraryManager.GetGraphics(this))
            {
                Input = new Input(Graphics.Form);
                Freelook = new FreeLook(Input);

                Graphics.Initialize();
                Graphics.CullingEnabled = isCullingEnabled;
                OnInitialize();
                if (World == null)
                {
                    OnInitializePhysics();
                }
                if (_isDebugDrawEnabled)
                {
                    if (_debugDrawer == null)
                    {
                        _debugDrawer = Graphics.GetPhysicsDebugDrawer();
                        _debugDrawer.DebugMode = DebugDrawMode;
                    }
                    if (World != null)
                    {
                        World.DebugDrawer = _debugDrawer;
                    }
                }
                Graphics.UpdateView();
                SetInfoText();

                Graphics.Run();

                if (_debugDrawer != null)
                {
                    if (World != null)
                    {
                        World.DebugDrawer = null;
                    }
                    if (_debugDrawer is IDisposable)
                    {
                        (_debugDrawer as IDisposable).Dispose();
                    }
                    _debugDrawer = null;
                }
            }
            Graphics = null;
        }
예제 #11
0
파일: Demo.cs 프로젝트: raiker/BulletSharp
        public void Run()
        {
            if (_graphics != null)
            {
                _graphics.Form.Close();
            }
            _graphics = LibraryManager.GetGraphics(this);

            _input = new Input(Graphics.Form);
            Freelook = new FreeLook(_input);

            _graphics.Initialize();
            OnInitialize();
            OnInitializePhysics();
            _graphics.UpdateView();

            clock.Start();
            _graphics.Run();
        }
예제 #12
0
파일: Game.cs 프로젝트: raiker/BulletSharp
        /// <summary>
        /// Runs the game.
        /// </summary>
        public void Run()
        {
            bool isFormClosed = false;
            bool formIsResizing = false;

            Form = new RenderForm();

            currentFormWindowState = Form.WindowState;
            Form.Resize += (o, args) =>
            {
                if (Form.WindowState != currentFormWindowState)
                {
                    if (togglingFullScreen == false)
                        HandleResize(o, args);
                }

                currentFormWindowState = Form.WindowState;
            };

            Form.ResizeBegin += (o, args) => { formIsResizing = true; };
            Form.ResizeEnd += (o, args) =>
            {
                formIsResizing = false;
                HandleResize(o, args);
            };

            Form.Closed += (o, args) => { isFormClosed = true; };

            // initialize input
            SlimDX.RawInput.Device.RegisterDevice(UsagePage.Generic, UsageId.Keyboard, DeviceFlags.None);
            SlimDX.RawInput.Device.RegisterDevice(UsagePage.Generic, UsageId.Mouse, DeviceFlags.None);

            Input = new Input(Form);

            SlimDX.RawInput.Device.KeyboardInput += Input.Device_KeyboardInput;
            SlimDX.RawInput.Device.MouseInput += Input.Device_MouseInput;

            Width = 1024;
            Height = 768;
            FullScreenWidth = Screen.PrimaryScreen.Bounds.Width;
            FullScreenHeight = Screen.PrimaryScreen.Bounds.Height;
            NearPlane = 0.1f;
            FarPlane = 200f;
            FieldOfView = (float)Math.PI / 4;
            Freelook = new FreeLook(Input);
            Ambient = Color.Gray.ToArgb();

            OnInitializeDevice();

            Fps = new FpsDisplay(Device);
            MeshFactory = new GraphicObjectFactory(Device);

            OnInitialize();
            OnResetDevice();

            clock.Start();
            MessagePump.Run(Form, () =>
            {
                OnHandleInput();
                Update();
                Input.ClearKeyCache();

                if (isFormClosed)
                    return;

                if (!formIsResizing)
                    Render();
            });

            SlimDX.RawInput.Device.KeyboardInput -= Input.Device_KeyboardInput;
            SlimDX.RawInput.Device.MouseInput -= Input.Device_MouseInput;

            OnLostDevice();
        }
예제 #13
0
        /// <summary>
        /// Runs the demo.
        /// </summary>
        public void Run()
        {
            bool isFormClosed = false;
            bool formIsResizing = false;

            Form = new RenderForm();
            /*
            currentFormWindowState = Form.WindowState;
            Form.Resize += (o, args) =>
            {
                if (Form.WindowState != currentFormWindowState)
                {
                    if (togglingFullScreen == false)
                        HandleResize(o, args);
                }

                currentFormWindowState = Form.WindowState;
            };
            */
            Form.ResizeBegin += (o, args) => { formIsResizing = true; };
            Form.ResizeEnd += (o, args) =>
            {
                Width = Form.ClientSize.Width;
                Height = Form.ClientSize.Height;

                renderView.Dispose();
                depthView.Dispose();
                _swapChain.ResizeBuffers(_swapChain.Description.BufferCount, Width, Height, _swapChain.Description.ModeDescription.Format, _swapChain.Description.Flags);

                CreateBuffers();

                SetSceneConstants();
                formIsResizing = false;
            };

            //Form.Closed += (o, args) => { isFormClosed = true; };

            Input = new Input(Form);

            Width = 1024;
            Height = 768;
            FullScreenWidth = Screen.PrimaryScreen.Bounds.Width;
            FullScreenHeight = Screen.PrimaryScreen.Bounds.Height;
            NearPlane = 1.0f;
            FarPlane = 200.0f;

            FieldOfView = (float)Math.PI / 4;
            Freelook = new FreeLook(Input);
            ambient = new Color4(Color.Gray.ToArgb());

            try
            {
                OnInitializeDevice();
            }
            catch (Exception e)
            {
                MessageBox.Show(e.ToString(), "Could not create DirectX 10 device.");
                return;
            }

            Initialize();

            clock.Start();
            RenderLoop.Run(Form, () =>
            {
                OnHandleInput();
                Update();
                Render();
                Input.ClearKeyCache();
            });
        }
예제 #14
0
        public void Run()
        {
            Input = new Input(Form);
            Freelook = new FreeLook(Input);

            Initialize();
            CullingEnabled = isCullingEnabled;
            OnInitialize();
            if (PhysicsContext.World == null)
            {
                PhysicsContext.InitPhysics();
            }
            /*
            if (_isDebugDrawEnabled)
            {
                if (_debugDrawer == null)
                {
                    _debugDrawer = new PhysicsDebugDraw(this);
                    _debugDrawer.DebugMode = DebugDrawMode;
                }
                if (PhysicsContext.World != null)
                {
                    PhysicsContext.World.DebugDrawer = _debugDrawer;
                }
            }
            */
            UpdateView();
            SetInfoText();

            RenderLoop.Run(Form, () =>
            {
                OnHandleInput();
                OnUpdate();
                if (Form.WindowState != FormWindowState.Minimized)
                {
                    clock.StartRender();
                    Render();
                    clock.StopRender();
                }
            });
        }