Esempio n. 1
0
 public override void FixedUpdate(double time)
 {
     if (physics == null)
     {
         physics = Parent.GetComponent <ShipPhysicsComponent>();
     }
     if (Camera == null)
     {
         return;
     }
     if (physics == null)
     {
         return;
     }
     physics.EnginePower = AutopilotThrottle > 0 ? AutopilotThrottle : Throttle;
     if (MouseFlight)
     {
         //Calculate turning direction
         var ep      = Vector3Ex.UnProject(new Vector3(MousePosition.X, MousePosition.Y, 0.25f), Camera.Projection, Camera.View, Viewport);
         var tgt     = Vector3Ex.UnProject(new Vector3(MousePosition.X, MousePosition.Y, 0f), Camera.Projection, Camera.View, Viewport);
         var dir     = (tgt - ep).Normalized();
         var gotoPos = Camera.Position + (dir * 1000);
         //Turn
         TurnTowards(gotoPos, time);
         BankShip(Camera.CameraUp, time);
     }
     else
     {
         physics.PlayerYaw = physics.PlayerPitch = 0;
         physics.Roll      = 0;
     }
     if (Rolling == -1)
     {
         physics.Roll = -1;
     }
     else if (Rolling == 1)
     {
         physics.Roll = 1;
     }
 }
Esempio n. 2
0
        GameObject GetSelection(float x, float y)
        {
            var vp    = new Vector2(Game.Width, Game.Height);
            var start = Vector3Ex.UnProject(new Vector3(x, y, 0f), camera.Projection, camera.View, vp);
            var end   = Vector3Ex.UnProject(new Vector3(x, y, 1f), camera.Projection, camera.View, vp);
            var dir   = (end - start).Normalized();

            PhysicsObject rb;

            var result = SelectionCast(
                start,
                dir,
                50000,
                out rb
                );

            if (result && rb.Tag is GameObject)
            {
                return((GameObject)rb.Tag);
            }
            return(null);
        }
Esempio n. 3
0
        void ProcessInput(double delta)
        {
            if (paused)
            {
                return;
            }
            input.Update();

            if (!ui.KeyboardGrabbed)
            {
                if (input.ActionDown(InputAction.ID_THROTTLEUP))
                {
                    shipInput.Throttle += (float)(delta);
                    shipInput.Throttle  = MathHelper.Clamp(shipInput.Throttle, 0, 1);
                }

                else if (input.ActionDown(InputAction.ID_THROTTLEDOWN))
                {
                    shipInput.Throttle -= (float)(delta);
                    shipInput.Throttle  = MathHelper.Clamp(shipInput.Throttle, 0, 1);
                }
            }

            StrafeControls strafe = StrafeControls.None;

            if (!ui.KeyboardGrabbed)
            {
                if (input.ActionDown(InputAction.ID_STRAFELEFT))
                {
                    strafe |= StrafeControls.Left;
                }
                if (input.ActionDown(InputAction.ID_STRAFERIGHT))
                {
                    strafe |= StrafeControls.Right;
                }
                if (input.ActionDown(InputAction.ID_STRAFEUP))
                {
                    strafe |= StrafeControls.Up;
                }
                if (input.ActionDown(InputAction.ID_STRAFEDOWN))
                {
                    strafe |= StrafeControls.Down;
                }
            }

            var pc = player.PhysicsComponent;

            shipInput.Viewport = new Vector2(Game.Width, Game.Height);
            shipInput.Camera   = camera;
            if (isLeftDown || mouseFlight)
            {
                var mX = Game.Mouse.X;
                var mY = Game.Mouse.Y;
                camera.MousePosition = new Vector2(
                    mX, Game.Height - mY
                    );
                shipInput.MouseFlight   = true;
                shipInput.MousePosition = new Vector2(mX, mY);
                camera.MouseFlight      = true;
            }
            else
            {
                shipInput.MouseFlight = false;
                camera.MouseFlight    = false;
            }
            control.CurrentStrafe = strafe;
            var obj = GetSelection(Game.Mouse.X, Game.Mouse.Y);

            if (ui.MouseWanted(Game.Mouse.X, Game.Mouse.Y))
            {
                current_cur = cur_arrow;
            }
            else
            {
                current_cur = obj == null ? cur_cross : cur_reticle;
            }
            var end   = Vector3Ex.UnProject(new Vector3(Game.Mouse.X, Game.Mouse.Y, 1f), camera.Projection, camera.View, new Vector2(Game.Width, Game.Height));
            var start = Vector3Ex.UnProject(new Vector3(Game.Mouse.X, Game.Mouse.Y, 0), camera.Projection, camera.View, new Vector2(Game.Width, Game.Height));
            var dir   = (end - start).Normalized();
            var tgt   = start + (dir * 400);

            weapons.AimPoint = tgt;

            if (world.Physics.PointRaycast(player.PhysicsComponent.Body, start, dir, 1000, out var contactPoint, out var po))
            {
                weapons.AimPoint = contactPoint;
            }


            if (Game.Mouse.IsButtonDown(MouseButtons.Right))
            {
                weapons.FireAll();
            }
            if (world.Projectiles.HasQueued)
            {
                session.RpcServer.FireProjectiles(world.Projectiles.GetQueue());
            }
        }
Esempio n. 4
0
        void ProcessInput(TimeSpan delta)
        {
            input.Update();

            if (!ui.KeyboardGrabbed)
            {
                if (input.ActionDown(InputAction.ID_THROTTLEUP))
                {
                    shipInput.Throttle += (float)(delta.TotalSeconds);
                    shipInput.Throttle  = MathHelper.Clamp(shipInput.Throttle, 0, 1);
                }

                else if (input.ActionDown(InputAction.ID_THROTTLEDOWN))
                {
                    shipInput.Throttle -= (float)(delta.TotalSeconds);
                    shipInput.Throttle  = MathHelper.Clamp(shipInput.Throttle, 0, 1);
                }
            }

            StrafeControls strafe = StrafeControls.None;

            if (!ui.KeyboardGrabbed)
            {
                if (input.ActionDown(InputAction.ID_STRAFELEFT))
                {
                    strafe |= StrafeControls.Left;
                }
                if (input.ActionDown(InputAction.ID_STRAFERIGHT))
                {
                    strafe |= StrafeControls.Right;
                }
                if (input.ActionDown(InputAction.ID_STRAFEUP))
                {
                    strafe |= StrafeControls.Up;
                }
                if (input.ActionDown(InputAction.ID_STRAFEDOWN))
                {
                    strafe |= StrafeControls.Down;
                }
            }

            var pc = player.PhysicsComponent;

            shipInput.Viewport = new Vector2(Game.Width, Game.Height);
            shipInput.Camera   = camera;
            if (Game.Mouse.IsButtonDown(MouseButtons.Left) || mouseFlight)
            {
                var mX = Game.Mouse.X;
                var mY = Game.Mouse.Y;
                camera.MousePosition = new Vector2(
                    mX, Game.Height - mY
                    );
                shipInput.MouseFlight   = true;
                shipInput.MousePosition = new Vector2(mX, mY);
                camera.MouseFlight      = true;
            }
            else
            {
                shipInput.MouseFlight = false;
                camera.MouseFlight    = false;
            }
            control.CurrentStrafe = strafe;
            //control.EnginePower = Velocity / MAX_VELOCITY;
            var obj = GetSelection(Game.Mouse.X, Game.Mouse.Y);

            current_cur = obj == null ? cur_arrow : cur_reticle;

            var ep  = Vector3Ex.UnProject(new Vector3(Game.Mouse.X, Game.Mouse.Y, 0.25f), camera.Projection, camera.View, new Vector2(Game.Width, Game.Height));
            var tgt = Vector3Ex.UnProject(new Vector3(Game.Mouse.X, Game.Mouse.Y, 0f), camera.Projection, camera.View, new Vector2(Game.Width, Game.Height));
            var dir = (tgt - ep).Normalized();

            weapons.AimPoint = tgt;

            if (!Game.Mouse.IsButtonDown(MouseButtons.Left) && Game.TotalTime - lastDown < 0.25)
            {
                var newselected = GetSelection(Game.Mouse.X, Game.Mouse.Y);
                if (newselected != null)
                {
                    selected = newselected;
                }
            }
            if (Game.Mouse.IsButtonDown(MouseButtons.Right))
            {
                weapons.FireAll();
            }
        }