public Vector3 getBuoyancyForce() { float buoyancyMultiplicator = ProcAirships.Instance.buoyancyMultiplicator; if (util.editorActive()) { //double geeForce = Athmosphere.fetch().CurrentBody.GeeASL; double alt = EditorController.altitude; double geeAcc = util.GetGeeAcc( Athmosphere.fetch().CurrentBody.Radius, alt, Athmosphere.fetch().CurrentBody.gravParameter); Log.post(geeAcc + "m/s²"); //float airDensity = (float)athmosphere.getAirDensity(); float airDensity = (float)Athmosphere.fetch().getAirDensity(alt); return((-Vector3.down * (float)geeAcc * airDensity * tankVolume) * buoyancyMultiplicator / 1000.0f); } else { //float airDensity = (float)athmosphere.getAirDensity(); float airDensity = (float)Athmosphere.fetch().getAirDensity(part.rigidbody.worldCenterOfMass); return((-FlightGlobals.getGeeForceAtPosition(part.rigidbody.worldCenterOfMass) * airDensity * tankVolume) * buoyancyMultiplicator / 1000.0f); } }
public void updateBuoyancyEditor() { if (tankVolume > 0.0f) { buoyantForce = getBuoyancyForce(); } else { buoyantForce = Vector3.zero; } double r = Athmosphere.fetch().CurrentBody.Radius; double h = EditorController.altitude; double mu = Athmosphere.fetch().CurrentBody.gravParameter; double geeForce = util.GetGeeAcc(r, h, mu); //double geeForce = Athmosphere.fetch().CurrentBody.GeeASL; Vector3 GravForce = Vector3.down * (float)geeForce * (part.mass + part.GetResourceMass());//this.vessel.GetTotalMass(); guiGravPull = GravForce.magnitude; guiBuoyancy = buoyantForce.magnitude - GravForce.magnitude; }
void Update() { if (!util.editorActive()) { //if (!(HighLogic.LoadedScene == GameScenes.EDITOR || HighLogic.LoadedScene == GameScenes.SPH)) return; } vesselBuoyancy = 0; vesselMass = 0; foreach (Part p in EditorLogic.fetch.ship.parts) { foreach (Buoyancy module in p.Modules.OfType <Buoyancy>()) { vesselBuoyancy += module.getBuoyancyForce().magnitude; } //if (p.GetComponent<LaunchClamp>() == null && part.has /* && p.physicalSignificance == Part.PhysicalSignificance.FULL*/) if (p.hasPhysicsEnabled()) { vesselMass += (p.GetTotalMass()); } } //vesselNetBuoyancy = (float)(vesselBuoyancy - 9.8f * vesselMass); //vesselNetBuoyancy = (float)(vesselBuoyancy - Athmosphere.fetch().CurrentBody.GeeASL * vesselMass); vesselNetBuoyancy = (float)(vesselBuoyancy - (util.GetGeeAcc( Athmosphere.fetch().CurrentBody.Radius, EditorController.altitude, Athmosphere.fetch().CurrentBody.gravParameter) * vesselMass) ); }
public static Athmosphere fetch() { if (instance == null) { instance = new Athmosphere(); instance.updateBody(); } return(instance); }
void autoFill() { //liftingGasAmount = (float)getGasAmount(athmosphere.getAirPressure() + idealRelPressure); liftingGasAmount = (float)getGasAmount(Athmosphere.fetch().getAirPressure(EditorController.altitude) + idealRelPressure); }
private void updateEnvelope() { if (!updateFlag) // do this once per update cycle, and before any envelopes gets updated { List <AirshipEnvelope> connectedEnvelopes = getConnectedEnvelopes(); if (null == connectedEnvelopes) { Log.post("Error getting connected envelopes", LogLevel.LOG_ERROR, this); return; } double connectedVolume = 0.0; double connectedGas = 0.0; double connectedTemperature = 0.0; foreach (AirshipEnvelope envelope in connectedEnvelopes) { envelope.updateVolume(); connectedVolume += envelope.envelopeVolumeNet; connectedGas += envelope.liftingGasAmount; connectedTemperature += envelope.getTemperature(); } connectedTemperature /= connectedEnvelopes.Count; double pressure = util.getPressure(connectedGas, getCurrentLiftingGas().molarMass, util.celsiusToKelvin(connectedTemperature), connectedVolume); foreach (AirshipEnvelope envelope in connectedEnvelopes) { //envelope.absolutePressure = (float)pressure; envelope.liftingGasAmount = (float)util.getGasAmount(pressure, getCurrentLiftingGas().molarMass, util.celsiusToKelvin(connectedTemperature), envelope.envelopeVolumeNet); envelope.absolutePressure = (float)pressure; envelope.updateFlag = true; } } temperature = (float)getTemperature(); //absolutePressure = (float)getAbsolutePressure(); //relativePressure = (float)(absolutePressure - athmosphere.getAirPressure()); double airPressure = util.editorActive() ? Athmosphere.fetch().getAirPressure(EditorController.altitude) : Athmosphere.fetch().getAirPressure(part.rigidbody.worldCenterOfMass); relativePressure = (float)(absolutePressure - airPressure); pStatus = (relativePressure - idealRelPressure).Clamp(-pressureTolerance, pressureTolerance); part.mass = (dryMassPerQubicMeter * envelopeVolume) + (liftingGasAmount / 1000.0f); if (util.editorActive() && (autofill || EditorController.AutoFill)) { autoFill(); } if (ventGas && isControllable) { LiftingGasAmount -= ventingRate * TimeWarp.fixedDeltaTime; } if (!util.editorActive()) { updatePressureDamage(); } if (util.editorActive() && liftingGasAmount != prevLiftingGasAmount) { prevLiftingGasAmount = liftingGasAmount; GameEvents.onEditorShipModified.Fire(EditorLogic.fetch.ship); } }