public FreeLook(Input input)
 {
     Target = Vector3.UnitX;
     Up = Vector3.UnitY;
     this.input = input;
     mouseController = new MouseController(input);
 }
Beispiel #2
0
        public FreeLook(Input input)
        {
            Up = Vector3.UnitY;
            this.input = input;
            mouseController = new MouseController(input);

            SetEyeTarget(Vector3.Zero, Vector3.UnitX);
        }
        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;
        }
Beispiel #4
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();
        }
Beispiel #5
0
        public void HandleKeys(Input input, float elapsedTime)
        {
            if (input.KeysDown.Contains(Keys.Right))
            {
                gVehicleSteering += elapsedTime * steeringIncrement;
                if (gVehicleSteering > steeringClamp)
                    gVehicleSteering = steeringClamp;
            }
            else if ((gVehicleSteering - float.Epsilon) > 0)
            {
                gVehicleSteering -= elapsedTime * steeringIncrement;
            }

            if (input.KeysDown.Contains(Keys.Left))
            {
                gVehicleSteering -= elapsedTime * steeringIncrement;
                if (gVehicleSteering < -steeringClamp)
                    gVehicleSteering = -steeringClamp;
            }
            else if ((gVehicleSteering + float.Epsilon) < 0)
            {
                gVehicleSteering += elapsedTime * steeringIncrement;
            }

            if (input.KeysDown.Contains(Keys.Up))
            {
                gEngineForce = maxEngineForce;
            }

            if (input.KeysDown.Contains(Keys.Down))
            {
                gEngineForce = -maxEngineForce;
            }

            if (input.KeysDown.Contains(Keys.Space))
            {
                gBreakingForce = maxBreakingForce;
            }

            if (input.KeysReleased.Contains(Keys.Space))
            {
                gBreakingForce = 0;
            }
        }
 public MouseController(Input input)
 {
     this.input = input;
     Sensitivity = 0.005f;
     SetByAngles(0, 0);
 }
Beispiel #7
0
        public void HandleInput(Input input, float elapsedTime)
        {
            if (input.KeysPressed.Contains(Keys.B))
            {
                PreviousDemo();
            }
            else if (input.KeysPressed.Contains(Keys.N))
            {
                NextDemo();
            }

            if (input.KeysDown.Count == 0)
                return;

            if (demos[demo] == Init_ClusterCombine || demos[demo] == Init_ClusterCar)
            {
                if (input.KeysDown.Contains(Keys.Up))
                {
                    motorControl.MaxTorque = 1;
                    motorControl.Goal += elapsedTime * 2;
                }
                else if (input.KeysDown.Contains(Keys.Down))
                {
                    motorControl.MaxTorque = 1;
                    motorControl.Goal -= elapsedTime * 2;
                }
                else if (input.KeysDown.Contains(Keys.Left))
                {
                    steerControlF.Angle += elapsedTime;
                    steerControlR.Angle += elapsedTime;
                }
                else if (input.KeysDown.Contains(Keys.Right))
                {
                    steerControlF.Angle -= elapsedTime;
                    steerControlR.Angle -= elapsedTime;
                }
            }
        }
Beispiel #8
0
        /// <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();
        }
Beispiel #9
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();
            });
        }
Beispiel #10
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();
                }
            });
        }