Exemplo n.º 1
0
        private static void IncrementAreas(ref ProjectedArea data, Vector3 vector, Matrix4x4 transformMatrix)
        {
            vector = transformMatrix.MultiplyVector(vector);

            if (vector.x >= 0)
            {
                data.iP += vector.x;
            }
            else
            {
                data.iN -= vector.x;
            }

            if (vector.y >= 0)
            {
                data.jP += vector.y;
            }
            else
            {
                data.jN -= vector.y;
            }

            if (vector.z >= 0)
            {
                data.kP += vector.z;
            }
            else
            {
                data.kN -= vector.z;
            }
        }
Exemplo n.º 2
0
        // useful for acceleration with radiation or a shockwave
        public static void accelerateByRadialPressure(SpatialVectorDouble energySourcePosition, double energyInJoules, IList <FracturedParticle> particles)
        {
            foreach (FracturedParticle iParticle in particles)
            {
                SpatialVectorDouble diff = iParticle.relativePosition - energySourcePosition;
                double distance          = diff.length;

                if (distance > 0.0)
                {
                    double surfaceAreaOfRadiationSphereAtDistance = Area.ofSphere(distance);

                    double surfaceAreaOfProjectedSphere = ProjectedArea.ofSphere(iParticle.radius);

                    double absorbedEnergyRatio    = System.Math.Min(surfaceAreaOfProjectedSphere / surfaceAreaOfRadiationSphereAtDistance, 1.0);
                    double absolvedEnergyInJoules = absorbedEnergyRatio * energyInJoules;
                    iParticle.accelerateByEnergyInJoules(diff.normalized(), absolvedEnergyInJoules);
                }
            }
        }
Exemplo n.º 3
0
        public void SetProjectedArea(ProjectedArea areas, Matrix4x4 vesselToWorldMatrix)
        {
            var transformedArea = new ProjectedArea();

            if (!part)
            {
                return;
            }

            Matrix4x4 transformMatrix = part.partTransform.worldToLocalMatrix * vesselToWorldMatrix;

            IncrementAreas(ref transformedArea, (float)areas.iP * Vector3.right, transformMatrix);
            IncrementAreas(ref transformedArea, (float)areas.iN * -Vector3.right, transformMatrix);
            IncrementAreas(ref transformedArea, (float)areas.jP * Vector3.up, transformMatrix);
            IncrementAreas(ref transformedArea, (float)areas.jN * -Vector3.up, transformMatrix);
            IncrementAreas(ref transformedArea, (float)areas.kP * Vector3.forward, transformMatrix);
            IncrementAreas(ref transformedArea, (float)areas.kN * -Vector3.forward, transformMatrix);

            projectedArea           = transformedArea;
            projectedArea.totalArea = projectedArea.iN +
                                      projectedArea.iP +
                                      projectedArea.jN +
                                      projectedArea.jP +
                                      projectedArea.kN +
                                      projectedArea.kP;

            if (projectedArea.totalArea <= 0)
            {
                part.ShieldedFromAirstream = true;
                if (fieldsVisible)
                {
                    Fields["dragForce"].guiActive = false;
                    Fields["liftForce"].guiActive = false;
                    fieldsVisible = false;
                }

                if (!(liftArrow is null))
                {
                    Destroy(liftArrow);
                    liftArrow = null;
                }

                if (!(dragArrow is null))
                {
                    Destroy(dragArrow);
                    dragArrow = null;
                }

                if (!(momentArrow is null))
                {
                    Destroy(momentArrow);
                    momentArrow = null;
                }
            }
            else
            {
                part.ShieldedFromAirstream = false;
            }

            double areaForStress = projectedArea.totalArea / 6;

            if (!FARDebugValues.allowStructuralFailures ||
                areaForStress <= 0.1 ||
                part.Modules.Contains <RealChuteFAR>() ||
                part.Modules.Contains <ModuleAblator>())
            {
                partForceMaxY  = double.MaxValue;
                partForceMaxXZ = double.MaxValue;
                return;
            }

            partForceMaxY  = areaForStress * partStressMaxY;
            partForceMaxXZ = areaForStress * partStressMaxXZ;
        }
        private void IncrementAreas(ref ProjectedArea data, Vector3 vector, Matrix4x4 transformMatrix)
        {
            vector = transformMatrix.MultiplyVector(vector);

            if (vector.x >= 0)
                data.iP += vector.x;
            else
                data.iN -= vector.x;

            if (vector.y >= 0)
                data.jP += vector.y;
            else
                data.jN -= vector.y;

            if (vector.z >= 0)
                data.kP += vector.z;
            else
                data.kN -= vector.z;
        }
        public void SetProjectedArea(ProjectedArea areas, Matrix4x4 vesselToWorldMatrix)
        {
            ProjectedArea transformedArea = new ProjectedArea();
            if (!part)
                return;

            Matrix4x4 transformMatrix = part.partTransform.worldToLocalMatrix * vesselToWorldMatrix;

            IncrementAreas(ref transformedArea, (float)areas.iP * Vector3.right, transformMatrix);
            IncrementAreas(ref transformedArea, (float)areas.iN * -Vector3.right, transformMatrix);
            IncrementAreas(ref transformedArea, (float)areas.jP * Vector3.up, transformMatrix);
            IncrementAreas(ref transformedArea, (float)areas.jN * -Vector3.up, transformMatrix);
            IncrementAreas(ref transformedArea, (float)areas.kP * Vector3.forward, transformMatrix);
            IncrementAreas(ref transformedArea, (float)areas.kN * -Vector3.forward, transformMatrix);

            projectedArea = transformedArea;
            projectedArea.totalArea = projectedArea.iN + projectedArea.iP + projectedArea.jN + projectedArea.jP + projectedArea.kN + projectedArea.kP;

            if (projectedArea.totalArea <= 0)
            {
                part.ShieldedFromAirstream = true;
                if (fieldsVisible)
                {
                    Fields["dragForce"].guiActive = false;
                    Fields["liftForce"].guiActive = false;
                    fieldsVisible = false;
                }
                if ((object)liftArrow != null)
                {
                    UnityEngine.Object.Destroy(liftArrow);
                    liftArrow = null;
                }
                if ((object)dragArrow != null)
                {
                    UnityEngine.Object.Destroy(dragArrow);
                    dragArrow = null;
                }
                if ((object)momentArrow != null)
                {
                    UnityEngine.Object.Destroy(momentArrow);
                    momentArrow = null;
                }
            }
            else
            {
                part.ShieldedFromAirstream = false;
            }

            double areaForStress = projectedArea.totalArea / 6;
            if (areaForStress <= 0.1 || part.Modules.Contains("RealChuteFAR") || part.Modules.Contains("ModuleAblator"))
            {
                partForceMaxY = double.MaxValue;
                partForceMaxXZ = double.MaxValue;
                return;
            }
            partForceMaxY = areaForStress * partStressMaxY;
            partForceMaxXZ = areaForStress * partStressMaxXZ;
        }