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

            Vector3d velVector = _vessel.srf_velocity -
                                 FARAtmosphere.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 Vector3d GetVelocity()
 {
     if (HighLogic.LoadedSceneIsFlight)
     {
         return(part.Rigidbody.velocity +
                Krakensbane.GetFrameVelocityV3f() -
                FARAtmosphere.GetWind(FlightGlobals.currentMainBody, part, part.Rigidbody.position));
     }
     return(velocityEditor);
 }
        // ReSharper disable once UnusedMember.Global
        public Vector3d GetVelocity(Vector3 refPoint)
        {
            Vector3d velocity = Vector3.zero;

            if (!HighLogic.LoadedSceneIsFlight)
            {
                return(velocityEditor);
            }
            if (part.Rigidbody)
            {
                velocity += part.Rigidbody.GetPointVelocity(refPoint);
            }

            velocity += Krakensbane.GetFrameVelocity() - Krakensbane.GetLastCorrection() * TimeWarp.fixedDeltaTime;
            velocity -= FARAtmosphere.GetWind(FlightGlobals.currentMainBody, part, part.Rigidbody.position);

            return(velocity);
        }
        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() -
                                  FARAtmosphere.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)
                {
                    return;
                }

                part.DragCubes.SetDrag(part.dragVectorDirLocal, (float)fi.mach);
            }
        }
Esempio n. 5
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 - FARAtmosphere.GetWind(FARAeroUtil.CurrentBody, part, rb.position);

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

            partLocalVelNorm = partLocalVel.normalized;

            partLocalAngVel = rb.angularVelocity;
            partLocalAngVel = partTransform.InverseTransformDirection(partLocalAngVel);
        }