GetTargetBearing() public static method

public static GetTargetBearing ( Vessel vessel, Vessel target ) : float
vessel Vessel
target Vessel
return float
Ejemplo n.º 1
0
            private void UpdateWheelSteering(ref FlightCtrlState c)
            {
                float bearing = 0;

                if (_value is VesselTarget)
                {
                    bearing = VesselUtils.GetTargetBearing(_shared.Vessel, ((VesselTarget)_value).target);
                }
                else if (_value is GeoCoordinates)
                {
                    bearing = ((GeoCoordinates)_value).GetBearing(_shared.Vessel);
                }
                else if (_value is double)
                {
                    bearing = (float)(Math.Round((double)_value) - Mathf.Round(FlightGlobals.ship_heading));
                }

                if (_shared.Vessel.horizontalSrfSpeed > 0.1f)
                {
                    if (Mathf.Abs(VesselUtils.AngleDelta(VesselUtils.GetHeading(_shared.Vessel), VesselUtils.GetVelocityHeading(_shared.Vessel))) <= 90)
                    {
                        c.wheelSteer = Mathf.Clamp(bearing / -10, -1, 1);
                    }
                    else
                    {
                        c.wheelSteer = -Mathf.Clamp(bearing / -10, -1, 1);
                    }
                }
            }
Ejemplo n.º 2
0
            public void OnFlyByWire(ref FlightCtrlState c)
            {
                Expression e = cpu.GetDeepestChildContext().GetLock(propertyName);

                if (e != null)
                {
                    this.Value = e.GetValue();

                    if (propertyName == "throttle")
                    {
                        c.mainThrottle = (float)Value;
                    }

                    if (propertyName == "wheelthrottle")
                    {
                        c.wheelThrottle = (float)Value;
                    }

                    if (propertyName == "steering")
                    {
                        if (Value is String && ((string)Value).ToUpper() == "KILL")
                        {
                            SteeringHelper.KillRotation(c, vessel);
                        }
                        else if (Value is Direction)
                        {
                            SteeringHelper.SteerShipToward((Direction)Value, c, vessel);
                        }
                    }

                    if (propertyName == "wheelsteering")
                    {
                        if (Value is VesselTarget)
                        {
                            var bearing = VesselUtils.GetTargetBearing(vessel, ((VesselTarget)Value).target);

                            if (vessel.horizontalSrfSpeed > 0.1f)
                            {
                                if (Mathf.Abs(VesselUtils.AngleDelta(VesselUtils.GetHeading(vessel), VesselUtils.GetVelocityHeading(vessel))) <= 90)
                                {
                                    c.wheelSteer = Mathf.Clamp(bearing / -10, -1, 1);
                                }
                                else
                                {
                                    c.wheelSteer = -Mathf.Clamp(bearing / -10, -1, 1);
                                }
                            }
                        }
                    }

                    if (cpu.GetLock(name) == null)
                    {
                        locked = false;
                    }
                }
            }
Ejemplo n.º 3
0
        public override object GetSuffix(string suffixName)
        {
            if (suffixName == "DISTANCE")
            {
                return((float)GetDistance());
            }
            if (suffixName == "DIRECTION")
            {
                var vector = (target.GetWorldPos3D() - context.Vessel.GetWorldPos3D());
                return(new Direction(vector, false));
            }

            if (suffixName == "BEARING")
            {
                return(VesselUtils.GetTargetBearing(context.Vessel, target));
            }

            if (suffixName == "HEADING")
            {
                return(VesselUtils.GetTargetHeading(context.Vessel, target));
            }

            return(base.GetSuffix(suffixName));
        }
Ejemplo n.º 4
0
        public override object GetSuffix(string suffixName)
        {
            if (suffixName == "DIRECTION")
            {
                var vector = (target.GetWorldPos3D() - context.Vessel.GetWorldPos3D());
                return(new Direction(vector, false));
            }

            if (suffixName == "DISTANCE")
            {
                return((float)GetDistance());
            }
            if (suffixName == "BEARING")
            {
                return(VesselUtils.GetTargetBearing(context.Vessel, target));
            }
            if (suffixName == "HEADING")
            {
                return(VesselUtils.GetTargetHeading(context.Vessel, target));
            }
            if (suffixName == "PROGRADE")
            {
                return(GetPrograde());
            }
            if (suffixName == "RETROGRADE")
            {
                return(GetRetrograde());
            }
            if (suffixName == "MAXTHRUST")
            {
                return(VesselUtils.GetMaxThrust(target));
            }
            if (suffixName == "VELOCITY")
            {
                return(new VesselVelocity(target));
            }
            if (suffixName == "GEOPOSITION")
            {
                return(new GeoCoordinates(target));
            }
            if (suffixName == "LATITUDE")
            {
                return(VesselUtils.GetVesselLattitude(target));
            }
            if (suffixName == "LONGITUDE")
            {
                return(VesselUtils.GetVesselLongitude(target));
            }
            if (suffixName == "FACING")
            {
                return(GetFacing());
            }
            if (suffixName == "UP")
            {
                return(new Direction(target.upAxis, false));
            }
            if (suffixName == "NORTH")
            {
                return(new Direction(VesselUtils.GetNorthVector(target), false));
            }
            if (suffixName == "BODY")
            {
                return(target.mainBody.bodyName);
            }
            if (suffixName == "ANGULARMOMENTUM")
            {
                return(new Direction(target.angularMomentum, true));
            }
            if (suffixName == "ANGULARVEL")
            {
                return(new Direction(target.angularVelocity, true));
            }
            if (suffixName == "MASS")
            {
                return(target.GetTotalMass());
            }
            if (suffixName == "VERTICALSPEED")
            {
                return(target.verticalSpeed);
            }
            if (suffixName == "SURFACESPEED")
            {
                return(target.horizontalSrfSpeed);
            }
            if (suffixName == "AIRSPEED")
            {
                return((target.orbit.GetVel() - FlightGlobals.currentMainBody.getRFrmVel(target.GetWorldPos3D())).magnitude);                          //the velocity of the vessel relative to the air);
            }
            if (suffixName == "VESSELNAME")
            {
                return(target.vesselName);
            }
            if (suffixName == "ALTITUDE")
            {
                return(target.altitude);
            }
            if (suffixName == "APOAPSIS")
            {
                return(target.orbit.ApA);
            }
            if (suffixName == "PERIAPSIS")
            {
                return(target.orbit.PeA);
            }
            if (suffixName == "SENSOR")
            {
                return(new VesselSensors(target));
            }
            if (suffixName == "TERMVELOCITY")
            {
                return(VesselUtils.GetTerminalVelocity(target));
            }

            // Is this a resource?
            double dblValue;

            if (VesselUtils.TryGetResource(target, suffixName, out dblValue))
            {
                return(dblValue);
            }

            return(base.GetSuffix(suffixName));
        }
Ejemplo n.º 5
0
            public void OnFlyByWire(ref FlightCtrlState c)
            {
                Expression e = cpu.GetDeepestChildContext().GetLock(propertyName);

                if (e != null)
                {
                    Value = e.GetValue();

                    if (propertyName == "throttle")
                    {
                        c.mainThrottle = (float)e.Double();
                    }

                    if (propertyName == "wheelthrottle")
                    {
                        c.wheelThrottle = (float)Utils.Clamp(e.Double(), -1, 1);
                    }

                    if (propertyName == "steering")
                    {
                        if (Value is String && ((string)Value).ToUpper() == "KILL")
                        {
                            SteeringHelper.KillRotation(c, vessel);
                        }
                        else if (Value is Direction)
                        {
                            SteeringHelper.SteerShipToward((Direction)Value, c, vessel);
                        }
                        else if (Value is Vector)
                        {
                            SteeringHelper.SteerShipToward(((Vector)Value).ToDirection(), c, vessel);
                        }
                        else if (Value is Node)
                        {
                            SteeringHelper.SteerShipToward(((Node)Value).GetBurnVector().ToDirection(), c, vessel);
                        }
                    }

                    if (propertyName == "wheelsteering")
                    {
                        float bearing = 0;

                        if (Value is VesselTarget)
                        {
                            bearing = VesselUtils.GetTargetBearing(vessel, ((VesselTarget)Value).target);
                        }
                        else if (Value is GeoCoordinates)
                        {
                            bearing = ((GeoCoordinates)Value).GetBearing(vessel);
                        }
                        else if (Value is double)
                        {
                            bearing = (float)(Math.Round((double)Value) - Mathf.Round(FlightGlobals.ship_heading));
                        }

                        if (vessel.horizontalSrfSpeed > 0.1f)
                        {
                            if (Mathf.Abs(VesselUtils.AngleDelta(VesselUtils.GetHeading(vessel), VesselUtils.GetVelocityHeading(vessel))) <= 90)
                            {
                                c.wheelSteer = Mathf.Clamp(bearing / -10, -1, 1);
                            }
                            else
                            {
                                c.wheelSteer = -Mathf.Clamp(bearing / -10, -1, 1);
                            }
                        }
                    }

                    if (cpu.GetLock(name) == null)
                    {
                        locked = false;
                    }
                }
            }