コード例 #1
0
        //--------------------------------------------------------------------------------------------------------------

        /// <summary>
        /// Calculates the new thrust value based on the averaged <see cref="AIMContext.DecidedDirection"/>.
        /// </summary>
        protected override void CalculateForce()
        {
            Vector3 velocity     = Body.velocity;
            Vector3 targetGlobal = Context.DecidedDirection;
            float   deltaAngle   = Vector3.Angle(velocity, targetGlobal) * Mathf.Deg2Rad;

            deltaAngle = Mathf.Clamp(deltaAngle, 0, 1);

            // calculate up/downward force
            float thrust = (ThrustFactor * Mathf.Cos(deltaAngle) * targetGlobal.y - velocity.y);

            angleToUp = Vector3.Angle(transform.up, Vector3.up) * Mathf.Deg2Rad;
            thrust    = thrust / Mathf.Cos(angleToUp);

            if (UsePidController)
            {
                thrust = ThrustController.GetOutput(thrust);
            }

            // compensate gravity
            float nominalThrottle = -Physics.gravity.y * Body.mass;

            thrust = Mathf.Clamp(thrust, -nominalThrottle / 2, nominalThrottle / 2);
            thrust = thrust + nominalThrottle / Mathf.Cos(angleToUp);

            // no downward acceleration
            if (thrust < 0)
            {
                thrust = 0.0f;
            }

            force = thrust * transform.up;
        }
コード例 #2
0
 public WaypointFollower(List<Waypoint> waypointsToFollow, IMyShipController shipController, ThrustController oof) {
     waypoints = waypointsToFollow;
     controller = shipController;
     thrustController = oof;
     currentWaypointIndex = 0;
 }
コード例 #3
0
        WaterfallController CreateNewController()
        {
            if (controllerTypes[controllerFlag] == "atmosphere_density")
            {
                AtmosphereDensityController newCtrl = new AtmosphereDensityController();
                newCtrl.name     = newControllerName;
                newCtrl.linkedTo = controllerTypes[controllerFlag];
                return(newCtrl);
            }
            else if (controllerTypes[controllerFlag] == "custom")
            {
                CustomController newCtrl = new CustomController();
                newCtrl.name     = newControllerName;
                newCtrl.linkedTo = controllerTypes[controllerFlag];
                return(newCtrl);
            }
            else if (controllerTypes[controllerFlag] == "engineEvent")
            {
                EngineEventController newCtrl = new EngineEventController();
                newCtrl.name          = newControllerName;
                newCtrl.linkedTo      = controllerTypes[controllerFlag];
                newCtrl.eventName     = eventTypes[eventFlag];
                newCtrl.eventCurve    = eventCurve;
                newCtrl.eventDuration = eventDuration;
                return(newCtrl);
            }
            else if (controllerTypes[controllerFlag] == "gimbal")
            {
                GimbalController newCtrl = new GimbalController();
                newCtrl.name     = newControllerName;
                newCtrl.axis     = axisTypes[axisFlag];
                newCtrl.linkedTo = controllerTypes[controllerFlag];
                return(newCtrl);
            }
            else if (controllerTypes[controllerFlag] == "light")
            {
                LightController newCtrl = new LightController();
                newCtrl.name     = newControllerName;
                newCtrl.linkedTo = controllerTypes[controllerFlag];
                return(newCtrl);
            }
            else if (controllerTypes[controllerFlag] == "mach")
            {
                MachController newCtrl = new MachController();
                newCtrl.name     = newControllerName;
                newCtrl.linkedTo = controllerTypes[controllerFlag];
                return(newCtrl);
            }
            else if (controllerTypes[controllerFlag] == "random")
            {
                RandomnessController newCtrl = new RandomnessController();
                newCtrl.name      = newControllerName;
                newCtrl.range     = randomRange;
                newCtrl.scale     = perlinScale;
                newCtrl.minimum   = perlinMin;
                newCtrl.seed      = perlinSeed;
                newCtrl.speed     = perlinSpeed;
                newCtrl.noiseType = randTypes[randFlag];
                newCtrl.linkedTo  = controllerTypes[controllerFlag];
                return(newCtrl);
            }
            else if (controllerTypes[controllerFlag] == "rcs")
            {
                RCSController newCtrl = new RCSController();
                newCtrl.name             = newControllerName;
                newCtrl.linkedTo         = controllerTypes[controllerFlag];
                newCtrl.responseRateUp   = rampRateUp;
                newCtrl.responseRateDown = rampRateDown;
                return(newCtrl);
            }
            else if (controllerTypes[controllerFlag] == "throttle")
            {
                ThrottleController newCtrl = new ThrottleController();
                newCtrl.name     = newControllerName;
                newCtrl.linkedTo = controllerTypes[controllerFlag];

                newCtrl.responseRateUp   = rampRateUp;
                newCtrl.responseRateDown = rampRateDown;
                return(newCtrl);
            }
            else if (controllerTypes[controllerFlag] == "thrust")
            {
                ThrustController newCtrl = new ThrustController();
                newCtrl.name     = newControllerName;
                newCtrl.linkedTo = controllerTypes[controllerFlag];
                return(newCtrl);
            }
            else
            {
                return(null);
            }
        }
コード例 #4
0
        private void ClearCurrent()
        {
            ClearBalanceVisualizer();

            foreach (Visual3D visual in _currentVisuals)
            {
                _viewport.Children.Remove(visual);
            }
            _currentVisuals.Clear();

            if (_currentBody != null)
            {
                _currentBody.Dispose();
                _currentBody = null;
            }

            if (_bot != null)
            {
                _map.RemoveItem(_bot, true);
                _bot.Dispose();
                _bot = null;
            }

            _shipDNA = null;

            if (_thrustController != null)
            {
                _thrustController.Dispose();
                _thrustController = null;
            }
        }
コード例 #5
0
        private async void btnLoadShip_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                string errMsg;
                ShipDNA shipDNA = ShipEditorWindow.LoadShip(out errMsg);
                if (shipDNA == null)
                {
                    if (!string.IsNullOrEmpty(errMsg))
                    {
                        MessageBox.Show(errMsg, this.Title, MessageBoxButton.OK, MessageBoxImage.Warning);
                    }
                    return;
                }

                EnsureWorldStarted();

                ShipCoreArgs core = new ShipCoreArgs()
                {
                    Map = _map,
                    Material_Ship = _material_Bot,
                    World = _world,
                };

                ShipExtraArgs extra = new ShipExtraArgs()
                {
                    Options = _editorOptions,
                    ItemOptions = _itemOptions,
                    Material_Projectile = _material_Bot,
                    Radiation = _radiation,
                    Gravity = _gravity,
                    RunNeural = false,
                    RepairPartPositions = chkLoadRepairPositions.IsChecked.Value,
                };

                //Ship ship = await Ship.GetNewShipAsync(shipDNA, _world, _material_Bot, _map, extra);
                Bot bot = new Bot(BotConstructor.ConstructBot(shipDNA, core, extra));

                ClearCurrent();

                _shipDNA = shipDNA;
                _bot = bot;

                _bot.PhysicsBody.ApplyForceAndTorque += new EventHandler<BodyApplyForceAndTorqueArgs>(Ship_ApplyForceAndTorque);

                _thrustController = new ThrustController(_bot, _viewport, _itemOptions);

                if (_bot.Fuel != null)
                {
                    _bot.Fuel.QuantityCurrent = _bot.Fuel.QuantityMax;
                }
                _bot.RecalculateMass();
                _thrustController.MassChanged(chkShipSimple.IsChecked.Value);

                if (chkShipDebugVisuals.IsChecked.Value)
                {
                    _thrustController.DrawDebugVisuals_Pre();
                }

                _map.AddItem(_bot);

                grdViewPort.Focus();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), this.Title, MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
コード例 #6
0
        private async void btnShipChallenge2_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                EnsureWorldStarted();
                ClearCurrent();

                List<ShipPartDNA> parts = new List<ShipPartDNA>();
                parts.Add(new ShipPartDNA() { PartType = FuelTank.PARTTYPE, Position = new Point3D(0.611527511599856, 0, 0.0153375982352619), Orientation = new Quaternion(0, -0.706493084706277, 0, 0.707719945502605), Scale = new Vector3D(4.70545346938791, 4.70545346938791, 1.04748080326409) });
                parts.Add(new ThrusterDNA() { PartType = Thruster.PARTTYPE, Position = new Point3D(-1.48216852903668, 0, 0), Orientation = Quaternion.Identity, Scale = new Vector3D(1.65021551755816, 1.65021551755816, 1.65021551755816), ThrusterDirections = ThrusterDesign.GetThrusterDirections(ThrusterType.Two), ThrusterType = ThrusterType.Two });
                parts.Add(new ThrusterDNA() { PartType = Thruster.PARTTYPE, Position = new Point3D(-2.60730396412872, 1.18811621237628, -0.0147591913688635), Orientation = new Quaternion(0, 0, -0.846976393198269, 0.531630500784946), Scale = new Vector3D(0.71390056433019, 0.71390056433019, 0.71390056433019), ThrusterDirections = ThrusterDesign.GetThrusterDirections(ThrusterType.Two_Two_One), ThrusterType = ThrusterType.Two_Two_One });
                parts.Add(new ThrusterDNA() { PartType = Thruster.PARTTYPE, Position = new Point3D(-2.60721450068017, -1.18828382189838, -0.0147591913688617), Orientation = new Quaternion(0, 0, -0.496864090131338, 0.867828367788216), Scale = new Vector3D(0.71390056433019, 0.71390056433019, 0.71390056433019), ThrusterDirections = ThrusterDesign.GetThrusterDirections(ThrusterType.Two_Two_One), ThrusterType = ThrusterType.Two_Two_One });

                ShipDNA shipDNA = ShipDNA.Create(parts);

                ShipCoreArgs core = new ShipCoreArgs()
                {
                    Map = _map,
                    Material_Ship = _material_Bot,
                    World = _world,
                };

                ShipExtraArgs extra = new ShipExtraArgs()
                {
                    Options = _editorOptions,
                    ItemOptions = _itemOptions,
                    Material_Projectile = _material_Bot,
                    Radiation = _radiation,
                    Gravity = _gravity,
                    RunNeural = false,
                    RepairPartPositions = false,
                };

                //Ship ship = await Ship.GetNewShipAsync(shipDNA, _world, _material_Bot, _map, extra);
                Bot bot = new Bot(BotConstructor.ConstructBot(shipDNA, core, extra));

                ClearCurrent();

                _shipDNA = shipDNA;
                _bot = bot;

                _bot.PhysicsBody.ApplyForceAndTorque += new EventHandler<BodyApplyForceAndTorqueArgs>(Ship_ApplyForceAndTorque);

                _thrustController = new ThrustController(_bot, _viewport, _itemOptions);

                //double mass = _ship.PhysicsBody.Mass;

                _bot.Fuel.QuantityCurrent = _bot.Fuel.QuantityMax;
                _bot.RecalculateMass();
                _thrustController.MassChanged(chkShipSimple.IsChecked.Value);

                if (chkShipDebugVisuals.IsChecked.Value)
                {
                    _thrustController.DrawDebugVisuals_Pre();
                }

                //mass = _ship.PhysicsBody.Mass;

                _map.AddItem(_bot);

                grdViewPort.Focus();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), this.Title, MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
コード例 #7
0
        private async void btnShipWackyFlyer_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                EnsureWorldStarted();
                ClearCurrent();

                List<ShipPartDNA> parts = new List<ShipPartDNA>();
                parts.Add(new ShipPartDNA() { PartType = FuelTank.PARTTYPE, Position = new Point3D(0, 0, 0), Orientation = Quaternion.Identity, Scale = new Vector3D(3, 3, 1) });

                ThrusterType thrustType = UtilityCore.GetRandomEnum<ThrusterType>(ThrusterType.Custom);
                parts.Add(new ThrusterDNA() { PartType = Thruster.PARTTYPE, Position = new Point3D(1, 0, 0), Orientation = Math3D.GetRandomRotation(), Scale = new Vector3D(.5d, .5d, .5d), ThrusterDirections = ThrusterDesign.GetThrusterDirections(thrustType), ThrusterType = thrustType });

                thrustType = UtilityCore.GetRandomEnum<ThrusterType>(ThrusterType.Custom);
                parts.Add(new ThrusterDNA() { PartType = Thruster.PARTTYPE, Position = new Point3D(-1, 0, 0), Orientation = Math3D.GetRandomRotation(), Scale = new Vector3D(.5d, .5d, .5d), ThrusterDirections = ThrusterDesign.GetThrusterDirections(thrustType), ThrusterType = thrustType });

                thrustType = UtilityCore.GetRandomEnum<ThrusterType>(ThrusterType.Custom);
                parts.Add(new ThrusterDNA() { PartType = Thruster.PARTTYPE, Position = new Point3D(0, 1, 0), Orientation = Math3D.GetRandomRotation(), Scale = new Vector3D(.5d, .5d, .5d), ThrusterDirections = ThrusterDesign.GetThrusterDirections(thrustType), ThrusterType = thrustType });

                thrustType = UtilityCore.GetRandomEnum<ThrusterType>(ThrusterType.Custom);
                parts.Add(new ThrusterDNA() { PartType = Thruster.PARTTYPE, Position = new Point3D(0, -1, 0), Orientation = Math3D.GetRandomRotation(), Scale = new Vector3D(.5d, .5d, .5d), ThrusterDirections = ThrusterDesign.GetThrusterDirections(thrustType), ThrusterType = thrustType });

                ShipDNA shipDNA = ShipDNA.Create(parts);

                ShipCoreArgs core = new ShipCoreArgs()
                {
                    Map = _map,
                    Material_Ship = _material_Bot,
                    World = _world,
                };

                ShipExtraArgs extra = new ShipExtraArgs()
                {
                    Options = _editorOptions,
                    ItemOptions = _itemOptions,
                    Material_Projectile = _material_Bot,
                    Radiation = _radiation,
                    Gravity = _gravity,
                    RunNeural = false,
                    RepairPartPositions = false,
                };

                //Ship ship = await Ship.GetNewShipAsync(shipDNA, _world, _material_Bot, _map, extra);
                Bot bot = new Bot(BotConstructor.ConstructBot(shipDNA, core, extra));

                ClearCurrent();

                _shipDNA = shipDNA;
                _bot = bot;

                _bot.PhysicsBody.ApplyForceAndTorque += new EventHandler<BodyApplyForceAndTorqueArgs>(Ship_ApplyForceAndTorque);

                _thrustController = new ThrustController(_bot, _viewport, _itemOptions);

                //double mass = _ship.PhysicsBody.Mass;

                _bot.Fuel.QuantityCurrent = _bot.Fuel.QuantityMax;
                _bot.RecalculateMass();
                _thrustController.MassChanged(chkShipSimple.IsChecked.Value);

                if (chkShipDebugVisuals.IsChecked.Value)
                {
                    _thrustController.DrawDebugVisuals_Pre();
                }

                //mass = _ship.PhysicsBody.Mass;

                _map.AddItem(_bot);

                grdViewPort.Focus();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), this.Title, MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }