Esempio n. 1
0
        public void HandleInput(PerspectiveCamera camera, KeyboardInput keyboard, MouseInput mouse)
        {
            if (mouse.JustPressed(MouseButtons.Left))
            {
                this.selecting = true;
                this.SelectionSystem.StartSelection(camera, mouse.Position);

                Debug.WriteLine("Selection started");
            }
            else if (this.selecting && !mouse.Hold(MouseButtons.Left))
            {
                this.selecting = false;
                var selected = new List <Entity>();
                this.SelectionSystem.EndSelection(camera, mouse.Position, selected);

                foreach (var entity in selected)
                {
                    Debug.WriteLine($"Selected {entity}");
                    this.selectedFighter = this.fighters.IndexOf(entity);
                }

                Debug.WriteLine("Selection finished");
            }


            if (mouse.Click(MouseButtons.Right))
            {
                var mouseWorldPosition = camera.Pick(mouse.Position, 0.0f);
                if (mouseWorldPosition.HasValue && this.selectedFighter < this.fighters.Count)
                {
                    var entity = this.fighters[this.selectedFighter];

                    if (this.FlightPlans.TryGet(entity, out var flightPlan))
                    {
                        var finalManeuver = (LerpManeuver)flightPlan.Maneuvers.Last();
                        ManeuverPlanner.PlanMoveTo(flightPlan.Maneuvers, finalManeuver.TargetPosition, finalManeuver.TargetYaw, finalManeuver.TargetPitch, mouseWorldPosition.Value, this.linearAcceleration, this.angularAcceleration);
                    }
                    else
                    {
                        var pose      = this.Containers.Get <ComponentContainer <Pose> >().Get(entity);
                        var maneuvers = new Queue <IManeuver>();
                        ManeuverPlanner.PlanMoveTo(maneuvers, pose.Position, pose.Yaw, pose.Pitch, mouseWorldPosition.Value, this.linearAcceleration, this.angularAcceleration);

                        this.Factories.Get <FlightPlanFactory>().Construct(entity, maneuvers);
                    }
                }
            }
        }
Esempio n. 2
0
        public void EndSelection(PerspectiveCamera camera, Point endPosition, List <Entity> selectedEntities)
        {
            var selectionEnd = camera.Pick(endPosition, 0.0f);

            if (this.selectionStart.HasValue && selectionEnd.HasValue)
            {
                var selectionBounds = BoundingBox.CreateFromPoints(
                    new Vector3[]
                {
                    this.selectionStart.Value + (Vector3.Up * LargeNumber),
                    selectionEnd.Value + (Vector3.Down * LargeNumber)
                });

                for (var i = 0; i < this.Hitboxes.Count; i++)
                {
                    var hitbox = this.Hitboxes[i];
                    var pose   = this.Poses.Get(hitbox.Entity);

                    var entityBounds = BoundingBox.CreateFromPoints(new Vector3[]
                    {
                        pose.Position + (Vector3.Left * hitbox.Width * 0.5f),
                        pose.Position + (Vector3.Right * hitbox.Width * 0.5f),

                        pose.Position + (Vector3.Up * hitbox.Height * 0.5f),
                        pose.Position + (Vector3.Down * hitbox.Height * 0.5f),

                        pose.Position + (Vector3.Forward * hitbox.Depth * 0.5f),
                        pose.Position + (Vector3.Backward * hitbox.Depth * 0.5f),
                    });

                    if (selectionBounds.Intersects(entityBounds))
                    {
                        selectedEntities.Add(hitbox.Entity);
                    }
                }
            }
        }
Esempio n. 3
0
 public void StartSelection(PerspectiveCamera camera, Point startPosition)
 => this.selectionStart = camera.Pick(startPosition, 0.0f);