protected bool lineOfSightTo(Vessel vess) { Vector3d a = vessel.transform.position; Vector3d b = PluginHelper.getVesselPos(vess); if (Vector3d.Distance(a, b) < 2500.0) // if both vessels are active { return(true); } foreach (CelestialBody referenceBody in FlightGlobals.Bodies) { Vector3d refminusa = referenceBody.position - a; Vector3d bminusa = b - a; if (Vector3d.Dot(refminusa, bminusa) > 0 && (bminusa.magnitude > refminusa.magnitude - referenceBody.Radius)) { Vector3d tang = refminusa - Vector3d.Dot(refminusa, bminusa.normalized) * bminusa.normalized; Vector3d tang_knot = referenceBody.position - tang; Vector3d intersection_vector = (a - tang_knot).normalized * Math.Sqrt(referenceBody.Radius * referenceBody.Radius - tang.sqrMagnitude); if (intersection_vector.sqrMagnitude > (b - tang_knot).sqrMagnitude) { return(false); } } } return(true); }
protected double ComputeFacingFactor(Vessel powerVessel) { double facingFactor; Vector3d powerv = PluginHelper.getVesselPos(powerVessel); Vector3d directionVector = (powerv - vessel.transform.position).normalized; if (receiverType == 2) { // get the best result of inline and directed reciever var facingFactorA = Math.Min(1.0 - Math.Abs(Vector3d.Dot(part.transform.up, directionVector)), 1); var facingFactorB = Math.Max(0, Vector3d.Dot(part.transform.up, directionVector)); facingFactor = Math.Max(facingFactorA, facingFactorB); } else if (isInlineReceiver || receiverType == 1) { // recieve facingFactor = Math.Min(1.0 - Math.Abs(Vector3d.Dot(part.transform.up, directionVector)), 1); } else { //Scale energy reception based on angle of reciever to transmitter facingFactor = Math.Max(0, Vector3d.Dot(part.transform.up, directionVector)); } return(facingFactor); }
public static bool lineOfSightToSun(Vessel vess) { Vector3d a = PluginHelper.getVesselPos(vess); Vector3d b = FlightGlobals.Bodies[0].transform.position; foreach (CelestialBody referenceBody in FlightGlobals.Bodies) { if (referenceBody.flightGlobalsIndex == 0) { // the sun should not block line of sight to the sun continue; } Vector3d refminusa = referenceBody.position - a; Vector3d bminusa = b - a; if (Vector3d.Dot(refminusa, bminusa) > 0) { if (Vector3d.Dot(refminusa, bminusa.normalized) < bminusa.magnitude) { Vector3d tang = refminusa - Vector3d.Dot(refminusa, bminusa.normalized) * bminusa.normalized; if (tang.magnitude < referenceBody.Radius) { return(false); } } } } return(true); }
protected double ComputeVisibilityAndDistance(VesselRelayPersistence r, Vessel v) { //return r.lineOfSightTo(v) ? Vector3d.Distance(PluginHelper.getVesselPos(r.getVessel()), PluginHelper.getVesselPos(v)) : -1; return(PluginHelper.HasLineOfSightWith(r.getVessel(), v, 0) ? Vector3d.Distance(PluginHelper.getVesselPos(r.getVessel()), PluginHelper.getVesselPos(v)) : -1); }
public double getAvailablePower() { Vector3d vessel_pos = PluginHelper.getVesselPos(vessel); double power = 0; if (PluginHelper.lineOfSightToSun(vessel) && solar_power > 0) { double inv_square_mult = Math.Pow(Vector3d.Distance(vessel_pos, FlightGlobals.Bodies[PluginHelper.REF_BODY_KERBOL].transform.position), 2) / Math.Pow(Vector3d.Distance(FlightGlobals.Bodies[PluginHelper.REF_BODY_KERBIN].transform.position, FlightGlobals.Bodies[PluginHelper.REF_BODY_KERBOL].transform.position), 2); power = nuclear_power + solar_power / inv_square_mult; } else { power = nuclear_power; } return(power); }
protected double ComputeFacingFactor(Vessel powerVessel) { double facingFactor = 1; Vector3d powerv = PluginHelper.getVesselPos(powerVessel); Vector3d directionVector = (powerv - vessel.transform.position).normalized; if (!isInlineReceiver) { //Scale energy reception based on angle of reciever to transmitter facingFactor = Vector3d.Dot(part.transform.up, directionVector); facingFactor = Math.Max(0, facingFactor); } else { facingFactor = 1.0 - Math.Abs(Vector3d.Dot(part.transform.up, directionVector)); facingFactor = Math.Min(facingFactor, 1); } return(facingFactor); }
public bool lineOfSightTo(Vessel vess) { Vector3d a = PluginHelper.getVesselPos(vessel); Vector3d b = PluginHelper.getVesselPos(vess); foreach (CelestialBody referenceBody in FlightGlobals.Bodies) { Vector3d refminusa = referenceBody.position - a; Vector3d bminusa = b - a; if (Vector3d.Dot(refminusa, bminusa) > 0) { if (Vector3d.Dot(refminusa, bminusa.normalized) < bminusa.magnitude) { Vector3d tang = refminusa - Vector3d.Dot(refminusa, bminusa.normalized) * bminusa.normalized; if (tang.magnitude < referenceBody.Radius) { return(false); } } } } return(true); }
protected double ComputeDistance(Vessel v1, Vessel v2) { return(Vector3d.Distance(PluginHelper.getVesselPos(v1), PluginHelper.getVesselPos(v2))); }