public VesselFlightInfo UpdatePhysicsParameters()
        {
            vesselInfo = new VesselFlightInfo();
            if (_vessel == null)
            {
                return(vesselInfo);
            }

            Vector3d velVector = _vessel.srf_velocity -
                                 FARWind.GetWind(_vessel.mainBody,
                                                 _vessel.rootPart,
                                                 _vessel.ReferenceTransform.position);
            Vector3d velVectorNorm = velVector.normalized;
            double   vesselSpeed   = velVector.magnitude;


            CalculateTotalAeroForce();
            CalculateForceBreakdown(velVectorNorm);
            CalculateVesselOrientation(velVectorNorm);
            CalculateEngineAndIntakeBasedParameters(vesselSpeed);
            CalculateBallisticCoefficientAndTermVel();
            CalculateStallFraction();

            return(vesselInfo);
        }
        public void UpdateVelocityAndAngVelocity(Vector3 frameVel)
        {
            if ((object)partTransform == null)
            {
                if (part != null)
                {
                    partTransform = part.partTransform;
                }
                else
                {
                    return;
                }
            }

            if (part == null)
            {
                return;
            }

            //Matrix4x4 matrix = partTransform.worldToLocalMatrix;
            Rigidbody rb = part.Rigidbody;

            //rb.drag = 0;
            partLocalVel = rb.velocity + frameVel
                           - FARWind.GetWind(FARAeroUtil.CurrentBody, part, rb.position);   //world velocity

            worldSpaceVelNorm = partLocalVel.normalized;
            partLocalVel      = partTransform.InverseTransformDirection(partLocalVel);

            partLocalVelNorm = partLocalVel.normalized;

            partLocalAngVel = rb.angularVelocity;
            partLocalAngVel = partTransform.InverseTransformDirection(partLocalAngVel);
        }
        public void UpdateVelocityAndAngVelocity(Vector3 frameVel)
        {
            if (partTransform == null)
            {
                if (part != null)
                {
                    partTransform = part.partTransform;
                }
                else
                {
                    return;
                }
            }
            if (part == null)
            {
                return;
            }

            Matrix4x4 matrix = partTransform.worldToLocalMatrix;
            Rigidbody rb     = part.Rigidbody;

            partLocalVel = rb.velocity + frameVel
                           - FARWind.GetWind(FARAeroUtil.CurrentBody, part, rb.position);
            partLocalVel = matrix.MultiplyVector(partLocalVel);

            partLocalVelNorm = partLocalVel.normalized;

            partLocalAngVel = rb.angularVelocity;
            partLocalAngVel = matrix.MultiplyVector(partLocalAngVel);
        }
        /*
         * Called after the scene is loaded.
         */
        void Awake()
        {
            //GUI id hashcodes
            mainGUIID         = Guid.NewGuid().GetHashCode();
            windGUIID         = Guid.NewGuid().GetHashCode();
            rainGUIID         = Guid.NewGuid().GetHashCode();
            cloudsGUIID       = Guid.NewGuid().GetHashCode();
            stormGUIID        = Guid.NewGuid().GetHashCode();
            snowGUIID         = Guid.NewGuid().GetHashCode();
            windSettingsGUIID = Guid.NewGuid().GetHashCode();
            windStormGUIID    = Guid.NewGuid().GetHashCode();
            weatherDataGUIID  = Guid.NewGuid().GetHashCode();
            cellDataTestGUIID = Guid.NewGuid().GetHashCode();

            Random.seed = (int)System.DateTime.Now.Ticks;   //helps with the random process
            RenderingManager.AddToPostDrawQueue(0, OnDraw); //Draw the stuffs
            //windDirectionNumb = Random.Range(1, 9); //Set wind direction
            windSpeed          = 1.0f;
            windDirectionLabel = Wind.WindDirectionLabel;
            windDirectionNumb  = Wind.windDirectionNumb;


            Debug.Log("WIND: setting wind function"); //Write to debug
            FARWind.SetWindFunction(windStuff);       //Set the WindFunction to the windStuff Function

            //Empty the strings so Unity won't throw a shit fit.
            windSpeedString         = string.Empty;
            WSMGSString             = string.Empty;
            WindGustTimeString      = string.Empty;
            WindGustDirectionString = string.Empty;
            CellIDLabel             = string.Empty;
        }
        /*
         * Called after the scene is loaded.
         */
        void Awake()
        {
            UnityEngine.Random.seed = (int)System.DateTime.Now.Ticks; //helps with the random process
            RenderingManager.AddToPostDrawQueue(0, OnDraw);           //Draw the stuffs
            windDirectionNumb = UnityEngine.Random.Range(1, 9);       //Set wind direction

            Debug.Log("WIND: setting wind function");                 //Write to debug
            FARWind.SetWindFunction(windStuff);                       //Set the WindFunction to the windStuff Function
        }
Esempio n. 6
0
        private static void UpdateAerodynamics(ModularFlightIntegrator fi, Part part)
        {
            //FIXME Proper model for airbrakes
            if (part.Modules.Contains <ModuleAeroSurface>() ||
                part.Modules.Contains("MissileLauncher") && part.vessel.rootPart == part)
            {
                fi.BaseFIUpdateAerodynamics(part);
            }
            else
            {
                Rigidbody rb = part.rb;
                if (!rb)
                {
                    return;
                }
                part.dragVector = rb.velocity +
                                  Krakensbane.GetFrameVelocity() -
                                  FARWind.GetWind(FlightGlobals.currentMainBody, part, rb.position);
                part.dragVectorSqrMag = part.dragVector.sqrMagnitude;
                if (part.dragVectorSqrMag.NearlyEqual(0) || part.ShieldedFromAirstream)
                {
                    part.dragVectorMag      = 0f;
                    part.dragVectorDir      = Vector3.zero;
                    part.dragVectorDirLocal = Vector3.zero;
                    part.dragScalar         = 0f;
                }
                else
                {
                    part.dragVectorMag      = (float)Math.Sqrt(part.dragVectorSqrMag);
                    part.dragVectorDir      = part.dragVector / part.dragVectorMag;
                    part.dragVectorDirLocal = -part.partTransform.InverseTransformDirection(part.dragVectorDir);
                    CalculateLocalDynPresAndAngularDrag(fi, part);
                }

                if (!part.DragCubes.None)
                {
                    part.DragCubes.SetDrag(part.dragVectorDirLocal, (float)fi.mach);
                }
            }
        }
Esempio n. 7
0
        public void UpdateVelocityAndAngVelocity(Vector3 frameVel)
        {
            if (partTransform is null)
            {
                if (part != null)
                {
                    partTransform = part.partTransform;
                }
                else
                {
                    return;
                }
            }

            if (part == null)
            {
                return;
            }

            Rigidbody rb = part.Rigidbody;

            if (rb == null)
            {
                return;
            }

            //world velocity
            partLocalVel = rb.velocity + frameVel - FARWind.GetWind(FARAeroUtil.CurrentBody, part, rb.position);

            worldSpaceVelNorm = partLocalVel.normalized;
            partLocalVel      = partTransform.InverseTransformDirection(partLocalVel);

            partLocalVelNorm = partLocalVel.normalized;

            partLocalAngVel = rb.angularVelocity;
            partLocalAngVel = partTransform.InverseTransformDirection(partLocalAngVel);
        }
 void UpdateAerodynamics(ModularFI.ModularFlightIntegrator fi, Part part)
 {
     if (part.dragModel != Part.DragModel.CYLINDRICAL || part.vessel.isEVA)     //FIXME Proper model for airbrakes
     {
         fi.BaseFIUpdateAerodynamics(part);
         return;
     }
     else
     {
         Rigidbody rb = part.rb;
         if (rb)
         {
             part.dragVector       = rb.velocity + Krakensbane.GetFrameVelocity() - FARWind.GetWind(FlightGlobals.currentMainBody, part, rb.position);
             part.dragVectorSqrMag = part.dragVector.sqrMagnitude;
             if (part.dragVectorSqrMag == 0f)
             {
                 part.dragVectorMag      = 0f;
                 part.dragVectorDir      = Vector3.zero;
                 part.dragVectorDirLocal = Vector3.zero;
                 part.dragScalar         = 0f;
             }
             else
             {
                 part.dragVectorMag      = (float)Math.Sqrt(part.dragVectorSqrMag);
                 part.dragVectorDir      = part.dragVector / part.dragVectorMag;
                 part.dragVectorDirLocal = -part.partTransform.InverseTransformDirection(part.dragVectorDir);
                 CalculateLocalDynPresAndAngularDrag(fi, part);
             }
             if (!part.DragCubes.None)
             {
                 part.DragCubes.SetDrag(part.dragVectorDirLocal, (float)fi.mach);
             }
         }
     }
 }