private void LEGACY_UpdateWingAeroModels(bool updateWingInteractions) { List <Part> partsList = EditorLogic.SortedShipList; _wingAerodynamicModel.Clear(); for (int i = 0; i < partsList.Count; i++) { Part p = partsList[i]; if (p != null) { if (p.Modules.Contains <FARWingAerodynamicModel>()) { FARWingAerodynamicModel w = p.Modules.GetModule <FARWingAerodynamicModel>(); if (updateWingInteractions) { w.EditorUpdateWingInteractions(); } _wingAerodynamicModel.Add(w); } else if (p.Modules.Contains <FARControllableSurface>()) { FARControllableSurface c = p.Modules.GetModule <FARControllableSurface>(); if (updateWingInteractions) { c.EditorUpdateWingInteractions(); } _wingAerodynamicModel.Add(c); } } } }
private void LEGACY_UpdateWingAeroModels(bool updateWingInteractions) { List <Part> partsList = EditorLogic.SortedShipList; _wingAerodynamicModel.Clear(); foreach (Part p in partsList) { if (p == null) { continue; } if (p.Modules.Contains <FARWingAerodynamicModel>()) { FARWingAerodynamicModel w = p.Modules.GetModule <FARWingAerodynamicModel>(); if (updateWingInteractions) { w.EditorUpdateWingInteractions(); } _wingAerodynamicModel.Add(w); } else if (p.Modules.Contains <FARControllableSurface>()) { FARControllableSurface c = p.Modules.GetModule <FARControllableSurface>(); if (updateWingInteractions) { c.EditorUpdateWingInteractions(); } _wingAerodynamicModel.Add(c); } } }
/// <summary> /// Sets spoilers to a certain value on this vessel /// </summary> public static void VesselSetSpoilers(Vessel v, bool spoilerActive) { foreach (Part p in v.parts) { if (!p.Modules.Contains <FARControllableSurface>()) { continue; } FARControllableSurface surface = p.Modules.GetModule <FARControllableSurface>(); surface.brake = spoilerActive; } }
/// <summary> /// Decreases flap deflection level for all control surfaces on this vessel, down to min setting of 0 /// </summary> public static void VesselDecreaseFlapDeflection(Vessel v) { foreach (Part p in v.parts) { if (!p.Modules.Contains <FARControllableSurface>()) { continue; } FARControllableSurface surface = p.Modules.GetModule <FARControllableSurface>(); surface.SetDeflection(surface.flapDeflectionLevel - 1); } }
protected override void DI_Start(StartState state) { if (HighLogic.LoadedSceneIsFlight) { this.controlSurfaceModule = this.part.Modules.OfType <FARControllableSurface>().Single(); this.wasFlap = controlSurfaceModule.isFlap; this.AoAFromFlap = typeof(FARControllableSurface).GetField("AoAFromFlap", BindingFlags.NonPublic); this.AoAOffset = typeof(FARControllableSurface).GetField("AoAOffset", BindingFlags.NonPublic); if (AoAOffset == null || AoAFromFlap == null) { throw new Exception("Could not get the field info from FAR!"); } } }
/// <summary> /// Returns spoiler setting for this vessel /// </summary> /// <param name="v"></param> /// <returns>Spoiler setting; true indicates active spoilers, false indicates inactive or no spoilers in existence</returns> public static bool VesselSpoilerSetting(Vessel v) { foreach (Part p in v.parts) { if (!p.Modules.Contains <FARControllableSurface>()) { continue; } FARControllableSurface surface = p.Modules.GetModule <FARControllableSurface>(); if (surface.isSpoiler) { return(surface.brake); } } return(false); }
/// <summary> /// Returns flap setting for this vessel /// </summary> /// <param name="v"></param> /// <returns>Flap setting; 0 - 3 indicates no to full flap deflections; -1 indicates lack of any control surface parts</returns> public static int VesselFlapSetting(Vessel v) { foreach (Part p in v.parts) { if (!p.Modules.Contains <FARControllableSurface>()) { continue; } FARControllableSurface surface = p.Modules.GetModule <FARControllableSurface>(); if (surface.isFlap) { return(surface.flapDeflectionLevel); } } return(-1); }
private void partModuleUpdate(PartModule pm) { if (isFarLoaded && pm is FARControllableSurface) { FARControllableSurface fcs = (FARControllableSurface)pm; if (vessel.atmDensity > 0) { Vector3d forcePosition = fcs.AerodynamicCenter - vesselState.CoM; Vector3 velocity = fcs.GetVelocity(); double soundspeed, v_scalar = velocity.magnitude; double rho = FARAeroUtil.GetCurrentDensity(vessel, out soundspeed); if (rho <= 0.0 || v_scalar <= 0.1 || fcs.isShielded) { return; } // First we save the curent state of the part double YmaxForce = fcs.YmaxForce; double XZmaxForce = fcs.XZmaxForce; double AoAcurrentFlap = (double)(FieldAoAcurrentFlap.GetValue(fcs)); double MaxAoAdesiredControl = 0; if (fcs.pitchaxis != 0.0) { MaxAoAdesiredControl += (double)(FieldPitchLocation.GetValue(fcs)) * fcs.pitchaxis * 0.01; } if (fcs.yawaxis != 0.0) { MaxAoAdesiredControl += (double)(FieldYawLocation.GetValue(fcs)) * fcs.yawaxis * 0.01;; } if (fcs.rollaxis != 0.0) { MaxAoAdesiredControl += (double)(FieldRollLocation.GetValue(fcs)) * fcs.rollaxis * 0.01;; } MaxAoAdesiredControl *= fcs.maxdeflect; if (fcs.pitchaxisDueToAoA != 0.0) { double _AoA = (fcs as FARWingAerodynamicModel).CalculateAoA(velocity.normalized); _AoA = FARMathUtil.rad2deg * Math.Asin(_AoA); if (double.IsNaN(_AoA)) { _AoA = 0; } MaxAoAdesiredControl += _AoA * fcs.pitchaxisDueToAoA * 0.01; } MaxAoAdesiredControl = FARMathUtil.Clamp(MaxAoAdesiredControl, -Math.Abs(fcs.maxdeflect), Math.Abs(fcs.maxdeflect)); double MachNumber = v_scalar / soundspeed; fcs.YmaxForce = double.MaxValue; fcs.XZmaxForce = double.MaxValue; // Then we turn it one way double AoA = fcs.CalculateAoA(velocity, AoAcurrentFlap + MaxAoAdesiredControl); vesselState.ctrlTorqueAvailable.Add(vessel.GetTransform().InverseTransformDirection(Vector3.Cross(forcePosition, fcs.CalculateForces(velocity, MachNumber, AoA)))); // We restore it to the initial state AoA = fcs.CalculateAoA(velocity); fcs.CalculateForces(velocity, MachNumber, AoA); // And we turn it the other way AoA = fcs.CalculateAoA(velocity, AoAcurrentFlap - MaxAoAdesiredControl); vesselState.ctrlTorqueAvailable.Add(vessel.GetTransform().InverseTransformDirection(Vector3.Cross(forcePosition, fcs.CalculateForces(velocity, MachNumber, AoA)))); // And in the end we restore its initial state AoA = fcs.CalculateAoA(velocity); fcs.CalculateForces(velocity, MachNumber, AoA); fcs.YmaxForce = YmaxForce; fcs.XZmaxForce = XZmaxForce; } } }