private void ClearShieldedParts()
        {
//            print("Clearing Parts in Cargo Bay...");
            foreach (Part p in FARShieldedParts)
            {
                if (p == null)
                {
                    continue;
                }
                FARBaseAerodynamics b = p.GetComponent <FARWingAerodynamicModel>() as FARBaseAerodynamics;
                if (b == null)
                {
                    b = p.GetComponent <FARBasicDragModel>() as FARBaseAerodynamics;
                }
                if (b == null)
                {
                    continue;
                }

                b.isShielded = false;
            }
            FARShieldedParts.Clear();
            bayOpen       = true;
            partsShielded = 0;
        }
Example #2
0
        private void ClearShieldedParts()
        {
            for (int i = 0; i < FARShieldedParts.Count; i++)
            {
                Part p = FARShieldedParts[i];

                if (p == null || p.Modules == null)
                {
                    continue;
                }
                FARBaseAerodynamics b = null;
                b = p.GetComponent <FARWingAerodynamicModel>() as FARBaseAerodynamics;
                if (b == null)
                {
                    b = p.GetComponent <FARBasicDragModel>() as FARBaseAerodynamics;
                }
                if (b == null)
                {
                    continue;
                }
                b.isShielded = false;
            }
            FARShieldedParts.Clear();
            partsShielded = 0;
        }
Example #3
0
        public static void PrecomputeGlobalCenterOfLift(FARCenterQuery lift, FARCenterQuery dummy, Vector3 vel)
        {
            /* Center of lift is the location where the derivative of
             * the total torque provided by aerodynamic forces relative to
             * AoA is zero (or at least minimal). This approximates the
             * derivative by a simple subtraction, like before. */

            var parts = GetAllEditorModules();

            for (int i = 0; i < parts.Count; i++)
            {
                FARBaseAerodynamics ba = parts[i];
                ba.velocityEditor = vel;
                ba.ResetCenterOfLift();
            }

            FlightEnv defaultfltenv = FlightEnv.NewDefaultVal();

            // run computations twice to let things like flap interactions settle
            for (int i = 0; i < parts.Count; i++)
            {
                FARBaseAerodynamics ba = parts[i];
                ba.PrecomputeCenterOfLift(vel, defaultfltenv, dummy);
            }
            for (int i = 0; i < parts.Count; i++)
            {
                FARBaseAerodynamics ba = parts[i];
                ba.PrecomputeCenterOfLift(vel, defaultfltenv, lift);
            }
        }
 private void ClearShieldedParts()
 {
     foreach (Part p in FARShieldedParts)
     {
         if (p == null || p.Modules == null)
         {
             continue;
         }
         FARBaseAerodynamics b = null;
         b = p.GetComponent <FARWingAerodynamicModel>() as FARBaseAerodynamics;
         if (b == null)
         {
             b = p.GetComponent <FARBasicDragModel>() as FARBaseAerodynamics;
         }
         if (b == null)
         {
             continue;
         }
         b.isShielded = false;
     }
     FARShieldedParts.Clear();
     partsShielded = 0;
 }
Example #5
0
        private void FindShieldedParts()
        {
            /*if (HighLogic.LoadedSceneIsEditor/* && FARAeroUtil.EditorAboutToAttach(false) &&
             *  !FARAeroUtil.CurEditorParts.Contains(part))
             *  return;*/

            ClearShieldedParts();
            UpdateShipPartsList();
            CalculateFairingBounds();

            Collider[] colliders = this.PartColliders;

            for (int i = 0; i < VesselPartList.Count; i++)
            {
                Part p = VesselPartList[i];

                if (FARShieldedParts.Contains(p) || p == null || p == part || part.symmetryCounterparts.Contains(p))
                {
                    continue;
                }

                FARBaseAerodynamics     b = null;
                FARBasicDragModel       d = null;
                FARWingAerodynamicModel w = null;
                Vector3 relPos            = -part.transform.position;
                w = p.GetComponent <FARWingAerodynamicModel>();
                if ((object)w == null)
                {
                    d = p.GetComponent <FARBasicDragModel>();
                }
                if ((object)w == null && (object)d == null)
                {
                    continue;
                }
                //if (p.GetComponent<FARPayloadFairingModule>() != null)
                //    continue;
                if (w)
                {
                    b       = w as FARBaseAerodynamics;
                    relPos += w.WingCentroid();
                }
                else
                {
                    b       = d as FARBaseAerodynamics;
                    relPos += p.transform.TransformDirection(d.CenterOfDrag) + p.transform.position;       //No attach node shifting with this
                }

                relPos = this.part.transform.worldToLocalMatrix.MultiplyVector(relPos);

                Vector3 fairingCenter = fairingBounds.center;
                fairingCenter *= 0.5f;
                fairingCenter  = this.part.transform.localToWorldMatrix.MultiplyVector(fairingCenter);
                fairingCenter += this.part.transform.position;

                if (fairingBounds.Contains(relPos))
                {
                    Vector3 vecFromPToPFCenter;
                    Vector3 origin;
                    if (w)
                    {
                        origin = w.WingCentroid();
                    }
                    else
                    {
                        origin = p.transform.position;
                    }

                    vecFromPToPFCenter = fairingCenter - origin;

                    RaycastHit[] hits = Physics.RaycastAll(origin, vecFromPToPFCenter, vecFromPToPFCenter.magnitude, FARAeroUtil.RaycastMask);

                    bool outsideMesh = false;

                    for (int k = 0; k < hits.Length; k++)
                    {
                        if (colliders.Contains(hits[k].collider))
                        {
                            outsideMesh = true;
                            break;
                        }
                    }
                    if (outsideMesh)
                    {
                        continue;
                    }

                    FARShieldedParts.Add(p);
                    if (b)
                    {
                        b.ActivateShielding();
                        //print("Shielded: " + p.partInfo.title);
                    }
                    for (int k = 0; k < p.symmetryCounterparts.Count; k++)
                    {
                        Part q = p.symmetryCounterparts[k];

                        if (q == null)
                        {
                            continue;
                        }
                        FARShieldedParts.Add(q);
                        b = q.GetComponent <FARBaseAerodynamics>();
                        if (b)
                        {
                            b.ActivateShielding();
                            //print("Shielded: " + p.partInfo.title);
                        }
                    }
                }
            }
            partsShielded = FARShieldedParts.Count;
        }
        private void FindShieldedParts()
        {
            /*if (HighLogic.LoadedSceneIsEditor/* && FARAeroUtil.EditorAboutToAttach(false) &&
             *  !FARAeroUtil.CurEditorParts.Contains(part))
             *  return;*/
            if (minBounds.Count == 0)
            {
                CalculateFairingBounds();
            }

            ClearShieldedParts();
            UpdateShipPartsList();

            Collider[] colliders;
            try
            {
                colliders = part.GetComponentsInChildren <Collider>();
            }
            catch (Exception e)
            {
                //Fail silently because it's the only way to avoid issues with pWings
                //Debug.LogException(e);
                colliders = new Collider[1] {
                    part.collider
                };
            }

            for (int i = 0; i < VesselPartList.Count; i++)
            {
                Part p = VesselPartList[i];

                if (FARShieldedParts.Contains(p) || p == null || p == part || part.symmetryCounterparts.Contains(p))
                {
                    continue;
                }

                FARBaseAerodynamics     b = null;
                FARBasicDragModel       d = null;
                FARWingAerodynamicModel w = null;
                Vector3 relPos            = -part.transform.position;
                w = p.GetComponent <FARWingAerodynamicModel>();
                if ((object)w == null)
                {
                    d = p.GetComponent <FARBasicDragModel>();
                }
                if ((object)w == null && (object)d == null)
                {
                    continue;
                }
                //if (p.GetComponent<FARPayloadFairingModule>() != null)
                //    continue;
                if (w)
                {
                    b       = w as FARBaseAerodynamics;
                    relPos += w.WingCentroid();
                }
                else
                {
                    b       = d as FARBaseAerodynamics;
                    relPos += p.partTransform.TransformDirection(d.CenterOfDrag) + p.partTransform.position;       //No attach node shifting with this
                }

                relPos = this.part.transform.worldToLocalMatrix.MultiplyVector(relPos);
                for (int j = 0; j < minBounds.Count; j++)
                {
                    Vector3 minBoundVec, maxBoundVec;
                    minBoundVec = minBounds[j];
                    maxBoundVec = maxBounds[j];
                    if (relPos.x < maxBoundVec.x && relPos.y < maxBoundVec.y && relPos.z < maxBoundVec.z && relPos.x > minBoundVec.x && relPos.y > minBoundVec.y && relPos.z > minBoundVec.z)
                    {
                        Vector3 vecFromPToPFCenter;
                        if (d)
                        {
                            vecFromPToPFCenter = p.partTransform.InverseTransformPoint(d.CoDshift);
                        }
                        else if (w)
                        {
                            vecFromPToPFCenter = w.WingCentroid();
                        }
                        else
                        {
                            vecFromPToPFCenter = p.partTransform.position;
                        }

                        vecFromPToPFCenter = this.part.partTransform.position - vecFromPToPFCenter;

                        RaycastHit[] hits = Physics.RaycastAll(p.partTransform.position, vecFromPToPFCenter, vecFromPToPFCenter.magnitude, FARAeroUtil.RaycastMask);

                        bool outsideMesh = false;

                        for (int k = 0; k < hits.Length; k++)
                        {
                            if (colliders.Contains(hits[k].collider))
                            {
                                outsideMesh = true;
                                break;
                            }
                        }
                        if (outsideMesh)
                        {
                            break;
                        }

                        FARShieldedParts.Add(p);
                        if (b)
                        {
                            b.isShielded = true;
                            //print("Shielded: " + p.partInfo.title);
                        }
                        for (int k = 0; k < p.symmetryCounterparts.Count; k++)
                        {
                            Part q = p.symmetryCounterparts[k];

                            if (q == null)
                            {
                                continue;
                            }
                            FARShieldedParts.Add(q);
                            b = q.GetComponent <FARBaseAerodynamics>();
                            if (b)
                            {
                                b.isShielded = true;
                                //print("Shielded: " + p.partInfo.title);
                            }
                        }
                        break;
                    }
                }
            }
            partsShielded = FARShieldedParts.Count;
        }
        private void FindShieldedParts()
        {
            if (minBounds == new Vector3())
            {
                CalculateBayBounds();
            }
            ClearShieldedParts();
            bayOpen = false;
            UpdateShipPartsList();

            double y_margin = Math.Max(0.12, 0.03 * (maxBounds.y - minBounds.y));

            foreach (Part p in VesselPartList)
            {
                if (FARShieldedParts.Contains(p) || p == null || p == part || part.symmetryCounterparts.Contains(p))
                {
                    continue;
                }

                FARBaseAerodynamics     b = null;
                FARBasicDragModel       d = null;
                FARWingAerodynamicModel w = null;
                Vector3 relPos            = -part.transform.position;
                w = p.GetComponent <FARWingAerodynamicModel>();
                if ((object)w == null)
                {
                    d = p.GetComponent <FARBasicDragModel>();
                }
                if ((object)w == null && (object)d == null)
                {
                    continue;
                }
                //if (p.GetComponent<FARPayloadFairingModule>() != null)
                //    continue;
                if (w)
                {
                    b       = w as FARBaseAerodynamics;
                    relPos += w.WingCentroid();
                }
                else
                {
                    b       = d as FARBaseAerodynamics;
                    relPos += p.partTransform.TransformDirection(d.CenterOfDrag) + p.partTransform.position;       //No attach node shifting with this
                }

                relPos = this.part.transform.worldToLocalMatrix.MultiplyVector(relPos);
                if (relPos.x < maxBounds.x && relPos.y < maxBounds.y + y_margin && relPos.z < maxBounds.z && relPos.x > minBounds.x && relPos.y > minBounds.y - y_margin && relPos.z > minBounds.z)
                {
                    if (relPos.y > maxBounds.y || relPos.y < minBounds.y)
                    {
                        // Enforce strict y bounds for parent and stack children
                        if (p == this.part.parent ||
                            p.parent == this.part && p.attachMode == AttachModes.STACK)
                        {
                            continue;
                        }
                    }

/*                    if (w)
 *                  {
 *                      if (w.nonSideAttach <= 0)
 *                      {
 *                          relPos = p.transform.position - this.part.transform.position;
 *                          relPos -= p.transform.right * Mathf.Sign(p.srfAttachNode.originalOrientation.x) * w.b_2;
 *
 *                          relPos = this.part.transform.worldToLocalMatrix.MultiplyVector(relPos);
 *
 *                          if (!(relPos.x < maxBounds.x && relPos.y < maxBounds.y && relPos.z < maxBounds.z && relPos.x > minBounds.x && relPos.y > minBounds.y && relPos.z > minBounds.z))
 *                              continue;
 *                      }
 *                  }*/
                    FARShieldedParts.Add(p);
                    if (b)
                    {
                        b.isShielded = true;
                        //print("Shielded: " + p.partInfo.title);
                    }
                    foreach (Part q in p.symmetryCounterparts)
                    {
                        if (q == null)
                        {
                            continue;
                        }
                        FARShieldedParts.Add(q);
                        b = q.GetComponent <FARBaseAerodynamics>();
                        if (b)
                        {
                            b.isShielded = true;
                            //print("Shielded: " + p.partInfo.title);
                        }
                    }
                }
            }
            if (HighLogic.LoadedSceneIsEditor)
            {
                foreach (Vessel v in FlightGlobals.Vessels)
                {
                    if (v == this.vessel)
                    {
                        continue;
                    }

                    Vector3 relPos = v.transform.position - this.part.transform.position;
                    relPos = this.part.transform.worldToLocalMatrix.MultiplyVector(relPos);
                    if (relPos.x < maxBounds.x && relPos.y < maxBounds.y && relPos.z < maxBounds.z && relPos.x > minBounds.x && relPos.y > minBounds.y && relPos.z > minBounds.z)
                    {
                        foreach (Part p in v.Parts)
                        {
                            FARBaseAerodynamics b = null;
                            b = p.GetComponent <FARBaseAerodynamics>();
                            if (b == null)
                            {
                                continue;
                            }

                            FARShieldedParts.Add(p);
                            if (b)
                            {
                                b.isShielded = true;
                                //print("Shielded: " + p.partInfo.title);
                            }
                        }
                    }
                }
            }
            partsShielded = FARShieldedParts.Count;
        }
Example #8
0
        private void FindShieldedParts()
        {
            if (minBounds == new Vector3())
            {
                CalculateBayBounds();
            }
            ClearShieldedParts();
            bayOpen = false;
            UpdateShipPartsList();

            double y_margin = Math.Max(0.12, 0.03 * (maxBounds.y - minBounds.y));

            Collider[] colliders;
            try
            {
                colliders = part.GetComponentsInChildren <Collider>();
            }
            catch (Exception e)
            {
                //Fail silently because it's the only way to avoid issues with pWings
                //Debug.LogException(e);
                colliders = new Collider[1] {
                    part.collider
                };
            }

            for (int i = 0; i < VesselPartList.Count; i++)
            {
                Part p = VesselPartList[i];

                if (FARShieldedParts.Contains(p) || p == null || p == part || part.symmetryCounterparts.Contains(p))
                {
                    continue;
                }

                FARBaseAerodynamics     b = null;
                FARBasicDragModel       d = null;
                FARWingAerodynamicModel w = null;
                Vector3 relPos            = -part.transform.position;
                w = p.GetComponent <FARWingAerodynamicModel>();
                if ((object)w == null)
                {
                    d = p.GetComponent <FARBasicDragModel>();
                }
                if ((object)w == null && (object)d == null)
                {
                    continue;
                }
                //if (p.GetComponent<FARPayloadFairingModule>() != null)
                //    continue;
                if (w)
                {
                    b       = w as FARBaseAerodynamics;
                    relPos += w.WingCentroid();
                }
                else
                {
                    b       = d as FARBaseAerodynamics;
                    relPos += p.partTransform.TransformDirection(d.CenterOfDrag) + p.partTransform.position;       //No attach node shifting with this
                }

                relPos = this.part.transform.worldToLocalMatrix.MultiplyVector(relPos);
                if (relPos.x < maxBounds.x && relPos.y < maxBounds.y + y_margin && relPos.z < maxBounds.z && relPos.x > minBounds.x && relPos.y > minBounds.y - y_margin && relPos.z > minBounds.z)
                {
                    if (relPos.y > maxBounds.y || relPos.y < minBounds.y)
                    {
                        // Enforce strict y bounds for parent and stack children
                        if (p == this.part.parent ||
                            p.parent == this.part && p.attachMode == AttachModes.STACK)
                        {
                            continue;
                        }
                    }
                    Vector3 vecFromPToCargoBayCenter;

                    /*if (d)
                     *  vecFromPToCargoBayCenter = p.partTransform.InverseTransformPoint(d.CoDshift);
                     * else if (w)
                     *  vecFromPToCargoBayCenter = w.WingCentroid();
                     * else*/
                    vecFromPToCargoBayCenter = p.partTransform.position;

                    vecFromPToCargoBayCenter = this.part.partTransform.position - vecFromPToCargoBayCenter;

                    RaycastHit[] hits = Physics.RaycastAll(p.partTransform.position, vecFromPToCargoBayCenter, vecFromPToCargoBayCenter.magnitude, FARAeroUtil.RaycastMask);

                    bool outsideMesh = false;

                    for (int j = 0; j < hits.Length; j++)
                    {
                        if (colliders.Contains(hits[j].collider))
                        {
                            outsideMesh = true;
                            break;
                        }
                    }
                    if (outsideMesh)
                    {
                        break;
                    }

                    FARShieldedParts.Add(p);
                    if (b)
                    {
                        b.isShielded = true;
                        //print("Shielded: " + p.partInfo.title);
                    }
                    for (int j = 0; j < p.symmetryCounterparts.Count; j++)
                    {
                        Part q = p.symmetryCounterparts[j];
                        if (q == null)
                        {
                            continue;
                        }
                        FARShieldedParts.Add(q);
                        b = q.GetComponent <FARBaseAerodynamics>();
                        if (b)
                        {
                            b.isShielded = true;
                            //print("Shielded: " + p.partInfo.title);
                        }
                    }
                }
            }
            partsShielded = FARShieldedParts.Count;
        }
Example #9
0
        private void FindShieldedParts()
        {
            if (minBounds == new Vector3())
            {
                CalculateBayBounds();
            }
            ClearShieldedParts();
            bayOpen = false;
            UpdateShipPartsList();

            double y_margin = Math.Max(0.12, 0.03 * (maxBounds.y - minBounds.y));

            Collider[] colliders = this.PartColliders;

            for (int i = 0; i < VesselPartList.Count; i++)
            {
                Part p = VesselPartList[i];

                if (FARShieldedParts.Contains(p) || p == null || p == part || part.symmetryCounterparts.Contains(p))
                {
                    continue;
                }

                FARBaseAerodynamics     b = null;
                FARBasicDragModel       d = null;
                FARWingAerodynamicModel w = null;
                Vector3 relPos            = -part.transform.position;
                w = p.GetComponent <FARWingAerodynamicModel>();
                if ((object)w == null)
                {
                    d = p.GetComponent <FARBasicDragModel>();
                }
                if ((object)w == null && (object)d == null)
                {
                    continue;
                }
                //if (p.GetComponent<FARPayloadFairingModule>() != null)
                //    continue;
                if (w)
                {
                    b       = w as FARBaseAerodynamics;
                    relPos += w.WingCentroid();
                }
                else
                {
                    b       = d as FARBaseAerodynamics;
                    relPos += p.partTransform.TransformDirection(d.CenterOfDrag) + p.partTransform.position;       //No attach node shifting with this
                }

                relPos = this.part.transform.worldToLocalMatrix.MultiplyVector(relPos);
                if (relPos.x < maxBounds.x && relPos.y < maxBounds.y + y_margin && relPos.z < maxBounds.z && relPos.x > minBounds.x && relPos.y > minBounds.y - y_margin && relPos.z > minBounds.z)
                {
                    if (relPos.y > maxBounds.y || relPos.y < minBounds.y)
                    {
                        // Enforce strict y bounds for parent and stack children
                        if (p == this.part.parent ||
                            p.parent == this.part && p.attachMode == AttachModes.STACK)
                        {
                            continue;
                        }
                    }
                    Vector3 vecFromPToCargoBayCenter;
                    Vector3 origin;
                    if (w)
                    {
                        origin = w.WingCentroid();
                    }
                    else
                    {
                        origin = p.transform.position;
                    }

                    vecFromPToCargoBayCenter = part.transform.position - origin;

                    if (w)  //This accounts for wings that are clipping into the cargo bay.
                    {
                        origin -= vecFromPToCargoBayCenter.normalized * 0.1f;
                    }

                    RaycastHit[] hits = Physics.RaycastAll(origin, vecFromPToCargoBayCenter, vecFromPToCargoBayCenter.magnitude, FARAeroUtil.RaycastMask);

                    bool outsideMesh = false;

                    for (int j = 0; j < hits.Length; j++)
                    {
                        if (colliders.Contains(hits[j].collider))
                        {
                            outsideMesh = true;
                            break;
                        }
                    }
                    if (outsideMesh)
                    {
                        continue;
                    }

                    FARShieldedParts.Add(p);
                    if (b)
                    {
                        b.ActivateShielding();
                        //print("Shielded: " + p.partInfo.title);
                    }
                    for (int j = 0; j < p.symmetryCounterparts.Count; j++)
                    {
                        Part q = p.symmetryCounterparts[j];
                        if (q == null)
                        {
                            continue;
                        }
                        FARShieldedParts.Add(q);
                        b = q.GetComponent <FARBaseAerodynamics>();
                        if (b)
                        {
                            b.ActivateShielding();
                            //print("Shielded: " + p.partInfo.title);
                        }
                    }
                }
            }
            partsShielded = FARShieldedParts.Count;
        }
        private void FindShieldedParts()
        {
            /*if (HighLogic.LoadedSceneIsEditor/* && FARAeroUtil.EditorAboutToAttach(false) &&
             *  !FARAeroUtil.CurEditorParts.Contains(part))
             *  return;*/
            if (minBounds.Count == 0)
            {
                CalculateFairingBounds();
            }

            ClearShieldedParts();
            UpdateShipPartsList();

            foreach (Part p in VesselPartList)
            {
                if (FARShieldedParts.Contains(p) || p == null || p == part || part.symmetryCounterparts.Contains(p))
                {
                    continue;
                }

                FARBaseAerodynamics     b = null;
                FARBasicDragModel       d = null;
                FARWingAerodynamicModel w = null;
                Vector3 relPos            = -part.transform.position;
                w = p.GetComponent <FARWingAerodynamicModel>();
                if ((object)w == null)
                {
                    d = p.GetComponent <FARBasicDragModel>();
                }
                if ((object)w == null && (object)d == null)
                {
                    continue;
                }
                //if (p.GetComponent<FARPayloadFairingModule>() != null)
                //    continue;
                if (w)
                {
                    b       = w as FARBaseAerodynamics;
                    relPos += w.WingCentroid();
                }
                else
                {
                    b       = d as FARBaseAerodynamics;
                    relPos += p.partTransform.TransformDirection(d.CenterOfDrag) + p.partTransform.position;       //No attach node shifting with this
                }


                relPos = this.part.transform.worldToLocalMatrix.MultiplyVector(relPos);
                for (int i = 0; i < minBounds.Count; i++)
                {
                    Vector3 minBoundVec, maxBoundVec;
                    minBoundVec = minBounds[i];
                    maxBoundVec = maxBounds[i];
                    if (relPos.x < maxBoundVec.x && relPos.y < maxBoundVec.y && relPos.z < maxBoundVec.z && relPos.x > minBoundVec.x && relPos.y > minBoundVec.y && relPos.z > minBoundVec.z)
                    {
                        FARShieldedParts.Add(p);
                        if (b)
                        {
                            b.isShielded = true;
                            //print("Shielded: " + p.partInfo.title);
                        }
                        foreach (Part q in p.symmetryCounterparts)
                        {
                            if (q == null)
                            {
                                continue;
                            }
                            FARShieldedParts.Add(q);
                            b = q.GetComponent <FARBaseAerodynamics>();
                            if (b)
                            {
                                b.isShielded = true;
                                //print("Shielded: " + p.partInfo.title);
                            }
                        }
                        break;
                    }
                }
            }
            partsShielded = FARShieldedParts.Count;
        }