/// <summary>
        /// Method to determine if the given vessel has been successfully voxelized nd currently has valid voxelization
        /// </summary>
        /// <param name="vessel"></param>
        /// <returns>True if vessel has valid voxelization currently, returns false if not or if the vessel is null and/or destroyed</returns>
        public static bool VesselVoxelizationCompletedAndValid(Vessel vessel)
        {
            if (vessel == null)
            {
                return(false);
            }

            FARVesselAero vesselAeroModule = null;

            for (int i = 0; i < vessel.vesselModules.Count; ++i)
            {
                VesselModule vM = vessel.vesselModules[i];
                if (vM is FARVesselAero)
                {
                    vesselAeroModule = (FARVesselAero)vM;
                    break;
                }
            }

            if ((object)vesselAeroModule == null)       //if this is true, then the vessel has not been initialized yet and so must be false
            {
                return(false);
            }

            return(vesselAeroModule.HasValidVoxelizationCurrently());
        }
Esempio n. 2
0
        /// <summary>
        ///     Calculates the forces and torque on a vessel at a given condition at the CoM
        /// </summary>
        /// <param name="vessel">Vessel in question</param>
        /// <param name="aeroForce">Total aerodynamic force at CoM, in kN</param>
        /// <param name="aeroTorque">Total aerodynamic torque at CoM, in kN * m</param>
        /// <param name="velocityWorldVector">
        ///     Velocity vector in world space relative to the atmosphere for CURRENT vessel
        ///     orientation, m/s
        /// </param>
        /// <param name="altitude">Vessel altitude, in m</param>
        public static void CalculateVesselAeroForces(
            Vessel vessel,
            out Vector3 aeroForce,
            out Vector3 aeroTorque,
            Vector3 velocityWorldVector,
            double altitude
            )
        {
            aeroForce = aeroTorque = Vector3.zero;
            if (vessel == null)
            {
                FARLogger.Error("API Error: attempted to simulate aerodynamics of null vessel");
                return;
            }

            FARVesselAero vesselAero = vessel.GetComponent <FARVesselAero>();

            if (vesselAero == null)
            {
                FARLogger.Error($"API Error: vessel {vessel} does not have FARVesselAero aerocomponent for simulation");
                return;
            }

            vesselAero.SimulateAeroProperties(out aeroForce, out aeroTorque, velocityWorldVector, altitude);
        }
        void Start()
        {
            if (!CompatibilityChecker.IsAllCompatible())
            {
                this.enabled = false;
                return;
            }

            _vessel                = GetComponent <Vessel>();
            _vesselAero            = GetComponent <FARVesselAero>();
            _physicsCalcs          = new PhysicsCalcs(_vessel, _vesselAero);
            _flightStatusGUI       = new FlightStatusGUI();
            _stabilityAugmentation = new StabilityAugmentation(_vessel);
            _flightDataGUI         = new FlightDataGUI();
            _aeroVizGUI            = new AeroVisualizationGUI();

            settingsWindow = new GUIDropDown <int>(new string[4] {
                "Flt Data", "Stab Aug", "Air Spd", "Aero Viz"
            }, new int[4] {
                0, 1, 2, 3
            }, 0);
            //boxStyle.padding = new RectOffset(4, 4, 4, 4);

            if (vesselFlightGUI.ContainsKey(_vessel))
            {
                vesselFlightGUI[_vessel] = this;
            }
            else
            {
                vesselFlightGUI.Add(_vessel, this);
            }

            this.enabled = true;

            if (FARDebugValues.useBlizzyToolbar)
            {
                GenerateBlizzyToolbarButton();
            }
            else
            {
                OnGUIAppLauncherReady();
            }

            activeFlightGUICount++;

            if (_vessel == FlightGlobals.ActiveVessel || FlightGlobals.ActiveVessel == null)
            {
                LoadConfigs();
            }

            GameEvents.onShowUI.Add(ShowUI);
            GameEvents.onHideUI.Add(HideUI);
        }
        public PhysicsCalcs(Vessel vessel, FARVesselAero vesselAerodynamics)
        {
            _vessel     = vessel;
            _vesselAero = vesselAerodynamics;

            PartResourceLibrary    resLibrary = PartResourceLibrary.Instance;
            PartResourceDefinition r          = resLibrary.resourceDefinitions["IntakeAir"];

            if (r != null)
            {
                intakeAirId      = r.id;
                intakeAirDensity = r.density;
            }
        }
        private void InstanceCalcVesselAeroForces(Vessel vessel, out Vector3 aeroForce, out Vector3 aeroTorque, Vector3 velocityWorldVector, double altitude)
        {
            aeroForce = aeroTorque = Vector3.zero;
            if (vessel == null)
            {
                Debug.LogError("FAR API Error: attempted to simulate aerodynamics of null vessel");
                return;
            }

            FARVesselAero vesselAero = vessel.GetComponent <FARVesselAero>();

            if (vesselAero == null)
            {
                Debug.LogError("FAR API Error: vessel does not have FARVesselAero aerocomponent for simulation");
                return;
            }

            vesselAero.SimulateAeroProperties(out aeroForce, out aeroTorque, velocityWorldVector, altitude);
        }
Esempio n. 6
0
        /// <summary>
        ///     Method to determine if the given vessel has been successfully voxelized nd currently has valid voxelization
        /// </summary>
        /// <param name="vessel"></param>
        /// <returns>
        ///     True if vessel has valid voxelization currently, returns false if not or if the vessel is null and/or
        ///     destroyed
        /// </returns>
        public static bool VesselVoxelizationCompletedAndValid(Vessel vessel)
        {
            if (vessel == null)
            {
                return(false);
            }

            FARVesselAero vesselAeroModule = null;

            foreach (VesselModule vM in vessel.vesselModules)
            {
                if (!(vM is FARVesselAero vesselAero))
                {
                    continue;
                }
                vesselAeroModule = vesselAero;
                break;
            }

            return(!(vesselAeroModule is null) && vesselAeroModule.HasValidVoxelizationCurrently());
        }
Esempio n. 7
0
        protected override void OnStart()
        {
            base.OnStart();

            if (!CompatibilityChecker.IsAllCompatible())
            {
                enabled = false;
                return;
            }

            showGUI = savedShowGUI;
            //since we're sharing the button, we need these shenanigans now
            if (FARDebugAndSettings.FARDebugButtonStock && HighLogic.LoadedSceneIsFlight)
            {
                if (showGUI)
                {
                    FARDebugAndSettings.FARDebugButtonStock.SetTrue(false);
                }
                else
                {
                    FARDebugAndSettings.FARDebugButtonStock.SetFalse(false);
                }
            }


            _vessel                = GetComponent <Vessel>();
            _vesselAero            = GetComponent <FARVesselAero>();
            _physicsCalcs          = new PhysicsCalcs(_vessel, _vesselAero);
            _flightStatusGUI       = new FlightStatusGUI();
            _stabilityAugmentation = new StabilityAugmentation(_vessel);
            _flightDataGUI         = new FlightDataGUI();
            AeroVizGUI             = new AeroVisualizationGUI();

            settingsWindow = new GUIDropDown <int>(new[]
            {
                Localizer.Format("FARFlightGUIWindowSelect0"),
                Localizer.Format("FARFlightGUIWindowSelect1"),
                Localizer.Format("FARFlightGUIWindowSelect2"),
                Localizer.Format("FARFlightGUIWindowSelect3")
            },
                                                   new[] { 0, 1, 2, 3 });

            if (vesselFlightGUI.ContainsKey(_vessel))
            {
                vesselFlightGUI[_vessel] = this;
            }
            else
            {
                vesselFlightGUI.Add(_vessel, this);
            }

            enabled = true;

            if (FARDebugValues.useBlizzyToolbar)
            {
                GenerateBlizzyToolbarButton();
            }

            activeFlightGUICount++;

            if (_vessel == FlightGlobals.ActiveVessel || FlightGlobals.ActiveVessel == null)
            {
                LoadConfigs();
            }

            GameEvents.onShowUI.Add(ShowUI);
            GameEvents.onHideUI.Add(HideUI);
        }