コード例 #1
0
ファイル: FlightScene.cs プロジェクト: 0000duck/MiniRTS
        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);
                    }
                }
            }
        }
コード例 #2
0
ファイル: FlightScene.cs プロジェクト: 0000duck/MiniRTS
        public void RenderUI()
        {
            if (ImGui.Begin("Scene"))
            {
                if (ImGui.BeginTabBar("SceneTabs"))
                {
                    if (ImGui.BeginTabItem("Geometry"))
                    {
                        this.AsteroidEditorTab.Edit();
                        ImGui.EndTabItem();
                    }

                    if (ImGui.BeginTabItem("Fighters"))
                    {
                        ImGui.ListBox("Selection", ref this.selectedFighter, this.fighterNames.ToArray(), this.fighterNames.Count);
                        ImGui.EndTabItem();

                        if (ImGui.Button("Build Fighter"))
                        {
                            var command = new BuildFighterCommand
                            {
                                Position = Vector3.Zero,
                                Scale    = Vector3.One
                            };

                            var entity = command.Execute(this.Content, this.EntityController, this.Factories);
                            this.fighters.Add(entity);

                            this.fighterNames.Add($"Fighter {this.fighters.Count}");
                        }

                        if (ImGui.Button("Build Space Ship"))
                        {
                            this.BuildSpaceShip();
                        }

                        if (ImGui.Button("Move"))
                        {
                            var entity    = this.fighters[this.selectedFighter];
                            var pose      = this.Containers.Get <ComponentContainer <Pose> >().Get(entity);
                            var maneuvers = new Queue <IManeuver>();
                            ManeuverPlanner.PlanMoveTo(maneuvers, pose.Position, pose.Yaw, pose.Pitch, this.targetPose.Position, this.linearAcceleration, this.angularAcceleration);
                            this.Factories.Get <FlightPlanFactory>().Construct(entity, maneuvers);
                        }
                    }


                    if (ImGui.BeginTabItem("Debug"))
                    {
                        ImGui.DragFloat("Radius", ref this.radius);
                        ImGui.SliderFloat("Yaw", ref this.yaw, -MathHelper.Pi, MathHelper.Pi);
                        ImGui.SliderFloat("Pitch", ref this.pitch, -MathHelper.PiOver2 + 0.001f, MathHelper.PiOver2 - 0.001f);

                        ImGui.Spacing();

                        ImGui.SliderFloat("Linear Acceleration", ref this.linearAcceleration, 0.1f, 10.0f);
                        ImGui.SliderFloat("Angular Acceleration", ref this.angularAcceleration, 0.1f, 10.0f);

                        ImGui.Spacing();

                        if (ImGui.Button("Invert"))
                        {
                            this.yaw   = MathHelper.WrapAngle(this.yaw + MathHelper.Pi);
                            this.pitch = MathHelper.WrapAngle(-this.pitch);
                        }

                        ImGui.EndTabItem();
                    }

                    ImGui.EndTabBar();
                }

                ImGui.End();
            }
        }