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); } } }
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; } } }
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; } } }
public float GetBearing(Vessel vessel) { return(VesselUtils.AngleDelta(VesselUtils.GetHeading(vessel), GetHeadingFromVessel(vessel))); }
public override void AddTo(BindingManager manager) { manager.AddGetter("VESSELNAME", delegate(CPU cpu) { return(cpu.Vessel.vesselName); }); manager.AddSetter("VESSELNAME", delegate(CPU cpu, object value) { cpu.Vessel.vesselName = value.ToString(); }); manager.AddGetter("ALTITUDE", delegate(CPU cpu) { return((float)cpu.Vessel.altitude); }); manager.AddGetter("ALT:RADAR", delegate(CPU cpu) { return((float)cpu.Vessel.heightFromTerrain); }); manager.AddGetter("MISSIONTIME", delegate(CPU cpu) { return((float)cpu.Vessel.missionTime); }); manager.AddGetter("STATUS", delegate(CPU cpu) { return(cpu.Vessel.situation.ToString().Replace("_", " ")); }); manager.AddGetter("APOAPSIS", delegate(CPU cpu) { return((float)cpu.Vessel.orbit.ApA); }); manager.AddGetter("PERIAPSIS", delegate(CPU cpu) { return((float)cpu.Vessel.orbit.PeA); }); manager.AddGetter("ALT:APOAPSIS", delegate(CPU cpu) { return((float)cpu.Vessel.orbit.ApA); }); manager.AddGetter("ALT:PERIAPSIS", delegate(CPU cpu) { return((float)cpu.Vessel.orbit.PeA); }); manager.AddGetter("ETA:APOAPSIS", delegate(CPU cpu) { return((float)cpu.Vessel.orbit.timeToAp); }); manager.AddGetter("ETA:PERIAPSIS", delegate(CPU cpu) { return((float)cpu.Vessel.orbit.timeToPe); }); manager.AddGetter("VELOCITY", delegate(CPU cpu) { return(cpu.Vessel.obt_velocity); }); manager.AddGetter("ANGULARMOMENTUM", delegate(CPU cpu) { return(new Direction(cpu.Vessel.angularMomentum, true)); }); manager.AddGetter("ANGULARVEL", delegate(CPU cpu) { return(new Direction(cpu.Vessel.angularVelocity, true)); }); manager.AddGetter("MASS", delegate(CPU cpu) { return(cpu.Vessel.GetTotalMass()); }); manager.AddGetter("VERTICALSPEED", delegate(CPU cpu) { return((float)cpu.Vessel.verticalSpeed); }); manager.AddGetter("SURFACESPEED", delegate(CPU cpu) { return((float)cpu.Vessel.horizontalSrfSpeed); }); manager.AddGetter("BODY", delegate(CPU cpu) { return(cpu.Vessel.mainBody.bodyName); }); manager.AddGetter("LATITUDE", delegate(CPU cpu) { return((float)cpu.Vessel.latitude); }); manager.AddGetter("LONGITUDE", delegate(CPU cpu) { return((float)cpu.Vessel.longitude); }); manager.AddGetter("HEADING", delegate(CPU cpu) { return(VesselUtils.GetHeading(cpu.Vessel)); }); manager.AddGetter("NORTH", delegate(CPU cpu) { return(new Direction(VesselUtils.GetNorthVector(cpu.Vessel), false)); }); manager.AddGetter("UP", delegate(CPU cpu) { return(new Direction(cpu.Vessel.upAxis, false)); }); manager.AddGetter("NODE", delegate(CPU cpu) { var vessel = cpu.Vessel; if (!vessel.patchedConicSolver.maneuverNodes.Any()) { throw new kOSException("No maneuver nodes present!"); } var up = (vessel.findLocalMOI(vessel.findWorldCenterOfMass()) - vessel.mainBody.position).normalized; var fwd = vessel.patchedConicSolver.maneuverNodes[0].GetBurnVector(cpu.Vessel.orbit); var rotRef = Quaternion.LookRotation(fwd, up); Direction d = new Direction(); d.Rotation = rotRef; return(d); }); manager.AddGetter("MAG:NODE", delegate(CPU cpu) { var vessel = cpu.Vessel; var orbit = vessel.orbit; if (!vessel.patchedConicSolver.maneuverNodes.Any()) { throw new kOSException("No maneuver nodes present!"); } var mag = vessel.patchedConicSolver.maneuverNodes[0].GetBurnVector(orbit).magnitude; return((float)mag); }); manager.AddGetter("ETA:NODE", delegate(CPU cpu) { var vessel = cpu.Vessel; if (!vessel.patchedConicSolver.maneuverNodes.Any()) { throw new kOSException("No maneuver nodes present!"); } var time = vessel.patchedConicSolver.maneuverNodes[0].UT; var currTime = Planetarium.GetUniversalTime(); return((float)(time - currTime)); }); manager.AddGetter("PROGRADE", delegate(CPU cpu) { var vessel = cpu.Vessel; var up = (vessel.findLocalMOI(vessel.findWorldCenterOfMass()) - vessel.mainBody.position).normalized; Direction d = new Direction(); d.Rotation = Quaternion.LookRotation(cpu.Vessel.orbit.GetVel().normalized, up); return(d); }); manager.AddGetter("RETROGRADE", delegate(CPU cpu) { var vessel = cpu.Vessel; var up = (vessel.findLocalMOI(vessel.findWorldCenterOfMass()) - vessel.mainBody.position).normalized; Direction d = new Direction(); var vesselRoll = cpu.Vessel.GetTransform().eulerAngles.y; d.Rotation = Quaternion.LookRotation(cpu.Vessel.orbit.GetVel().normalized * -1, up); return(d); }); manager.AddGetter("FACING", delegate(CPU cpu) { var facing = cpu.Vessel.transform.up; return(new Direction(new Vector3d(facing.x, facing.y, facing.z).normalized, false)); }); manager.AddGetter("MAXTHRUST", delegate(CPU cpu) { return(VesselUtils.GetMaxThrust(cpu.Vessel)); }); manager.AddGetter("AV", delegate(CPU cpu) { return(cpu.Vessel.transform.InverseTransformDirection(cpu.Vessel.rigidbody.angularVelocity)); }); manager.AddGetter("STAGE", delegate(CPU cpu) { return(new StageValues(cpu.Vessel)); }); }