예제 #1
0
 public override void FixedUpdate(TimeSpan time)
 {
     if (physics == null)
     {
         physics = Parent.GetComponent <ShipPhysicsComponent>();
     }
     if (Camera == null)
     {
         return;
     }
     if (physics == null)
     {
         return;
     }
     physics.EnginePower = Throttle;
     if (MouseFlight)
     {
         //Calculate turning direction
         var ep      = VectorMath.UnProject(new Vector3(MousePosition.X, MousePosition.Y, 0.25f), Camera.Projection, Camera.View, Viewport);
         var tgt     = VectorMath.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.TotalSeconds);
         BankShip(Camera.CameraUp, time.TotalSeconds);
     }
     else
     {
         physics.PlayerYaw = physics.PlayerPitch = 0;
         physics.Roll      = 0;
     }
     if (Rolling == -1)
     {
         physics.Roll = -1;
     }
     else if (Rolling == 1)
     {
         physics.Roll = 1;
     }
 }
예제 #2
0
        GameObject GetSelection(float x, float y)
        {
            var vp = new Vector2(Game.Width, Game.Height);

            var start = VectorMath.UnProject(new Vector3(x, y, 0f), camera.Projection, camera.View, vp);
            var end   = VectorMath.UnProject(new Vector3(x, y, 1f), camera.Projection, camera.View, vp);
            var dir   = end;

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

            if (result && rb.Tag is GameObject)
            {
                return((GameObject)rb.Tag);
            }
            return(null);
        }
예제 #3
0
        void ProcessInput(TimeSpan delta)
        {
            input.Update();

            if (!hud.TextEntry)
            {
                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 (!hud.TextEntry)
            {
                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   = VectorMath.UnProject(new Vector3(Game.Mouse.X, Game.Mouse.Y, 0.25f), camera.Projection, camera.View, new Vector2(Game.Width, Game.Height));
            var tgt  = VectorMath.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();
            var dir2 = new Matrix3(player.PhysicsComponent.Body.Transform.ClearTranslation()) * Vector3.UnitZ;

            tgt += dir * 750;
            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();
            }
        }