public static Bounds BoundsWithExhaust(this Vessel vessel, Transform refT) { var b = vessel.Bounds(refT); b.Encapsulate(vessel.EnginesExhaust(refT)); return(b); }
bool ComputeManeuver(Vessel v, out Vector3d maneuver) { maneuver = Vector3d.zero; //calculate distance var dir = (v.CurrentCoM - VSL.Physics.wCoM); var dist = dir.magnitude; dir /= dist; //first try to get TCA from other vessel and get vessel's R and Exhaust var vR = 0f; var vB = new Bounds(); Transform vT = null; var tca = ModuleTCA.EnabledTCA(v); if (tca != null) { // if(tca.CPS != null && // tca.CPS.IsActive && // VSL.Physics.M > tca.VSL.Physics.M && // VSL.vessel.srfSpeed > v.srfSpeed) //test // return false; vR = tca.VSL.Geometry.R; vB = tca.VSL.Geometry.B; vT = tca.VSL.refT; } else //do a raycast { RaycastHit raycastHit; if (Physics.SphereCast(VSL.Geometry.C + dir * (VSL.Geometry.R + 0.1f), VSL.Geometry.R, dir, out raycastHit, dist, RadarMask)) { vR = (raycastHit.point - v.CurrentCoM).magnitude; } vT = v.ReferenceTransform; vB = v.Bounds(vT); vB.Encapsulate(v.EnginesExhaust()); } //compute course correction var dV = VSL.vessel.srf_velocity - v.srf_velocity + (VSL.vessel.acceleration - v.acceleration) * CPS.LookAheadTime; var thrershold = -1f; if (v.LandedOrSplashed) { thrershold = 0; } else if (Dangerous.Contains(v.id)) { thrershold = CPS.SafeDistance; } if (AvoideVessel(VSL, dir, dist, dV, vR, vB, vT, out maneuver, thrershold)) { Dangerous.Add(v.id); } else { Dangerous.Remove(v.id); } return(!maneuver.IsZero()); }
public static float Radius(this Vessel vessel) { if (!vessel.loaded) { return((float)Math.Pow(vessel.GetTotalMass(), 1 / 3.0)); } var bounds = vessel.Bounds(vessel.ReferenceTransform); return(bounds.size.magnitude + bounds.center.magnitude); }
bool ComputeManeuver(Vessel v, out Vector3d maneuver) { maneuver = Vector3d.zero; //calculate distance var dir = (v.CurrentCoM-VSL.Physics.wCoM); var dist = dir.magnitude; dir /= dist; //first try to get TCA from other vessel and get vessel's R and Exhaust var vR = 0f; var vB = new Bounds(); Transform vT = null; var tca = ModuleTCA.EnabledTCA(v); if(tca != null) { // if(tca.CPS != null && // tca.CPS.IsActive && // VSL.Physics.M > tca.VSL.Physics.M && // VSL.vessel.srfSpeed > v.srfSpeed) //test // return false; vR = tca.VSL.Geometry.R; vB = tca.VSL.Geometry.B; vT = tca.VSL.refT; } else //do a raycast { RaycastHit raycastHit; if(Physics.SphereCast(VSL.Geometry.C+dir*(VSL.Geometry.R+0.1f), VSL.Geometry.R, dir, out raycastHit, dist, RadarMask)) vR = (raycastHit.point-v.CurrentCoM).magnitude; vT = v.ReferenceTransform; vB = v.Bounds(vT); vB.Encapsulate(v.EnginesExhaust()); } //compute course correction var dV = VSL.vessel.srf_velocity-v.srf_velocity+(VSL.vessel.acceleration-v.acceleration)*CPS.LookAheadTime; var thrershold = -1f; if(v.LandedOrSplashed) thrershold = 0; else if(Dangerous.Contains(v.id)) thrershold = CPS.SafeDistance; if(AvoideVessel(VSL, dir, dist, dV, vR, vB, vT, out maneuver, thrershold)) Dangerous.Add(v.id); else Dangerous.Remove(v.id); return !maneuver.IsZero(); }