Exemple #1
0
        void InitDocking()
        {
            lastTarget = core.target.Target;

            try
            {
                vesselBoundingBox = vessel.GetBoundingBox();
                targetBoundingBox = lastTarget.GetVessel().GetBoundingBox();

                targetSize = targetBoundingBox.size.magnitude;

                if (!overrideSafeDistance)
                {
                    safeDistance = vesselBoundingBox.size.magnitude + targetSize + 0.5f;
                }
                else
                {
                    safeDistance = (float)overridenSafeDistance.val;
                }

                if (core.target.Target is ModuleDockingNode)
                {
                    acquireRange = ((ModuleDockingNode)core.target.Target).acquireRange * 0.5;
                }
                else
                {
                    acquireRange = 0.25;
                }
            }
            catch (Exception e)
            {
                print(e);
            }

            if (zSep < 0)  //we're behind the target
            {
                dockingStep = DockingStep.WRONG_SIDE_BACKING_UP;
            }
            else if (lateralSep.magnitude > dockingcorridorRadius) // in front but far from docking axis
            {
                if (zSep < targetSize)
                {
                    dockingStep = DockingStep.BACKING_UP;
                }
                else
                {
                    dockingStep = DockingStep.MOVING_TO_START;
                }
            }
            else
            {
                dockingStep = DockingStep.DOCKING;
            }
        }
Exemple #2
0
        // From FAR with ferram4 authorisation
        public static MechJebModuleDockingAutopilot.Box3d GetBoundingBox(this Vessel vessel, bool debug = false)
        {
            Vector3 minBounds = new Vector3();
            Vector3 maxBounds = new Vector3();

            if (debug)
            {
                MonoBehaviour.print("[GetBoundingBox] Start " + vessel.vesselName);
            }

            for (int i = 0; i < vessel.parts.Count; i++)
            {
                Part        p       = vessel.parts[i];
                Vector3Pair partBox = p.GetBoundingBox();

                if (debug)
                {
                    MonoBehaviour.print("[GetBoundingBox] " + p.name + " " + (partBox.p1 - partBox.p2).magnitude.ToString("F3"));
                }

                maxBounds.x = Mathf.Max(maxBounds.x, partBox.p1.x);
                minBounds.x = Mathf.Min(minBounds.x, partBox.p2.x);
                maxBounds.y = Mathf.Max(maxBounds.y, partBox.p1.y);
                minBounds.y = Mathf.Min(minBounds.y, partBox.p2.y);
                maxBounds.z = Mathf.Max(maxBounds.z, partBox.p1.z);
                minBounds.z = Mathf.Min(minBounds.z, partBox.p2.z);

                //foreach (var sympart in p.symmetryCounterparts)
                //{
                //    partBox = sympart.GetBoundingBox();

                //    maxBounds.x = Mathf.Max(maxBounds.x, partBox.p1.x);
                //    minBounds.x = Mathf.Min(minBounds.x, partBox.p2.x);
                //    maxBounds.y = Mathf.Max(maxBounds.y, partBox.p1.y);
                //    minBounds.y = Mathf.Min(minBounds.y, partBox.p2.y);
                //    maxBounds.z = Mathf.Max(maxBounds.z, partBox.p1.z);
                //    minBounds.z = Mathf.Min(minBounds.z, partBox.p2.z);
                //}
            }

            if (debug)
            {
                MonoBehaviour.print("[GetBoundingBox] End " + vessel.vesselName);
            }

            MechJebModuleDockingAutopilot.Box3d box = new MechJebModuleDockingAutopilot.Box3d();

            box.center = new Vector3d((maxBounds.x + minBounds.x) / 2, (maxBounds.y + minBounds.y) / 2, (maxBounds.z + minBounds.z) / 2);
            box.size   = new Vector3d(Math.Abs(box.center.x - maxBounds.x), Math.Abs(box.center.y - maxBounds.y), Math.Abs(box.center.z - maxBounds.z));

            return(box);
        }
Exemple #3
0
        void DrawBoundingBox()
        {
            if (drawBoundingBox && vessel == FlightGlobals.ActiveVessel)
            {
                vesselBoundingBox = vessel.GetBoundingBox();
                GLUtils.DrawBoundingBox(vessel.mainBody, vessel, vesselBoundingBox, Color.green);

                if (core.target.Target != null)
                {
                    Vessel targetVessel = core.target.Target.GetVessel();
                    targetBoundingBox = targetVessel.GetBoundingBox();
                    GLUtils.DrawBoundingBox(targetVessel.mainBody, targetVessel, targetBoundingBox, Color.blue);
                }
            }
        }
Exemple #4
0
        // From FAR with ferram4 authorisation
        public static MechJebModuleDockingAutopilot.Box3d GetBoundingBox(this Vessel vessel, bool debug = false)
        {
            Vector3 minBounds = new Vector3();
            Vector3 maxBounds = new Vector3();

            Log.dbg("[GetBoundingBox] Start {0}", vessel.vesselName);

            for (int i = 0; i < vessel.parts.Count; i++)
            {
                Part p = vessel.parts[i];
                PartExtensions.Vector3Pair partBox = p.GetBoundingBox();

                Log.dbg("[GetBoundingBox] {0} {1:0.000}", p.name, (partBox.p1 - partBox.p2).magnitude);

                maxBounds.x = Mathf.Max(maxBounds.x, partBox.p1.x);
                minBounds.x = Mathf.Min(minBounds.x, partBox.p2.x);
                maxBounds.y = Mathf.Max(maxBounds.y, partBox.p1.y);
                minBounds.y = Mathf.Min(minBounds.y, partBox.p2.y);
                maxBounds.z = Mathf.Max(maxBounds.z, partBox.p1.z);
                minBounds.z = Mathf.Min(minBounds.z, partBox.p2.z);

                //foreach (var sympart in p.symmetryCounterparts)
                //{
                //    partBox = sympart.GetBoundingBox();

                //    maxBounds.x = Mathf.Max(maxBounds.x, partBox.p1.x);
                //    minBounds.x = Mathf.Min(minBounds.x, partBox.p2.x);
                //    maxBounds.y = Mathf.Max(maxBounds.y, partBox.p1.y);
                //    minBounds.y = Mathf.Min(minBounds.y, partBox.p2.y);
                //    maxBounds.z = Mathf.Max(maxBounds.z, partBox.p1.z);
                //    minBounds.z = Mathf.Min(minBounds.z, partBox.p2.z);
                //}
            }

            if (debug)
            {
                Log.info("[GetBoundingBox] End {0}", vessel.vesselName);
            }

            MechJebModuleDockingAutopilot.Box3d box = new MechJebModuleDockingAutopilot.Box3d();

            box.center = new Vector3d((maxBounds.x + minBounds.x) / 2, (maxBounds.y + minBounds.y) / 2, (maxBounds.z + minBounds.z) / 2);
            box.size   = new Vector3d(Math.Abs(box.center.x - maxBounds.x), Math.Abs(box.center.y - maxBounds.y), Math.Abs(box.center.z - maxBounds.z));

            return(box);
        }
Exemple #5
0
        void InitDocking()
        {
            lastTarget = core.target.Target;

            try
            {
                vesselBoundingBox = vessel.GetBoundingBox();
                targetBoundingBox = lastTarget.GetVessel().GetBoundingBox();

                if (!overrideTargetSize)
                {
                    targetSize = targetBoundingBox.size.magnitude;
                }
                else
                {
                    targetSize = (float)overridenTargetSize.val;
                }

                if (!overrideSafeDistance)
                {
                    safeDistance = vesselBoundingBox.size.magnitude + targetSize + 0.5f;
                }
                else
                {
                    safeDistance = (float)overridenSafeDistance.val;
                }

                if (core.target.Target is ModuleDockingNode)
                {
                    acquireRange = ((ModuleDockingNode)core.target.Target).acquireRange * 0.5;
                }
                else
                {
                    acquireRange = 0.25;
                }
            }
            catch (Exception e)
            {
                Log.err(e, this);
            }

            if (zSep < 0)  //we're behind the target
            {
                // If we're more than half our own bounding box size behind the target port then use wrong side behavior
                // Still needs improvement. The reason for these changes is that to prevent wrong side behavior when our
                // port slipped behind the target by a fractional amount. The result is that rather than avoiding the
                // target ship we end up trying to pass right through it.
                // What's really needed here is code that compares bounding box positions to determine if we just try to back up or change sides completely.
                if (Math.Abs(zSep) > vesselBoundingBox.size.magnitude * 0.5f)
                {
                    dockingStep = DockingStep.WRONG_SIDE_BACKING_UP;
                }
                else
                {
                    dockingStep = DockingStep.BACKING_UP; // Just back straight up.
                }
            }
            else if (lateralSep.magnitude > dockingcorridorRadius) // in front but far from docking axis
            {
                if (zSep < targetSize)
                {
                    dockingStep = DockingStep.BACKING_UP;
                }
                else
                {
                    dockingStep = DockingStep.MOVING_TO_START;
                }
            }
            else
            {
                dockingStep = DockingStep.DOCKING;
            }
        }
Exemple #6
0
        public static void DrawBoundingBox(CelestialBody mainBody, Vessel vessel, MechJebModuleDockingAutopilot.Box3d box, Color c)
        {
            //Vector3d origin = vessel.GetWorldPos3D() - vessel.GetTransform().rotation * box.center ;
            //Vector3d origin = vessel.GetTransform().TransformPoint(box.center);
            Vector3d origin = vessel.transform.TransformPoint(box.center);

            Vector3d A1 = origin + vessel.transform.rotation * new Vector3d(+box.size.x, +box.size.y, +box.size.z);
            Vector3d A2 = origin + vessel.transform.rotation * new Vector3d(+box.size.x, -box.size.y, +box.size.z);
            Vector3d A3 = origin + vessel.transform.rotation * new Vector3d(-box.size.x, -box.size.y, +box.size.z);
            Vector3d A4 = origin + vessel.transform.rotation * new Vector3d(-box.size.x, +box.size.y, +box.size.z);

            Vector3d B1 = origin + vessel.transform.rotation * new Vector3d(+box.size.x, +box.size.y, -box.size.z);
            Vector3d B2 = origin + vessel.transform.rotation * new Vector3d(+box.size.x, -box.size.y, -box.size.z);
            Vector3d B3 = origin + vessel.transform.rotation * new Vector3d(-box.size.x, -box.size.y, -box.size.z);
            Vector3d B4 = origin + vessel.transform.rotation * new Vector3d(-box.size.x, +box.size.y, -box.size.z);

            GL.PushMatrix();
            material.SetPass(0);
            GL.LoadOrtho();
            GL.Begin(GL.LINES);
            GL.Color(c);

            GLVertex(A1);
            GLVertex(A2);

            GLVertex(A2);
            GLVertex(A3);

            GLVertex(A3);
            GLVertex(A4);

            GLVertex(A4);
            GLVertex(A1);

            GLVertex(B1);
            GLVertex(B2);

            GLVertex(B2);
            GLVertex(B3);

            GLVertex(B3);
            GLVertex(B4);

            GLVertex(B4);
            GLVertex(B1);

            GLVertex(A1);
            GLVertex(B1);

            GLVertex(A2);
            GLVertex(B2);

            GLVertex(A3);
            GLVertex(B3);

            GLVertex(A4);
            GLVertex(B4);

            GL.End();
            GL.PopMatrix();
        }
        void InitDocking()
        {
            lastTarget = core.target.Target;

            try
            {
                vesselBoundingBox = vessel.GetBoundingBox();
                targetBoundingBox = lastTarget.GetVessel().GetBoundingBox();

                if (!overrideTargetSize)
                    targetSize = targetBoundingBox.size.magnitude;
                else
                    targetSize = (float)overridenTargetSize.val;

                if (!overrideSafeDistance)
                    safeDistance = vesselBoundingBox.size.magnitude + targetSize + 0.5f;
                else
                    safeDistance = (float)overridenSafeDistance.val;

                if (core.target.Target is ModuleDockingNode)
                    acquireRange = ((ModuleDockingNode)core.target.Target).acquireRange * 0.5;
                else
                    acquireRange = 0.25;

            }
            catch (Exception e)
            {
                print(e);
            }

            if (zSep < 0)  //we're behind the target
                dockingStep = DockingStep.WRONG_SIDE_BACKING_UP;
            else if (lateralSep.magnitude > dockingcorridorRadius) // in front but far from docking axis
                if (zSep < targetSize)
                    dockingStep = DockingStep.BACKING_UP;
                else
                    dockingStep = DockingStep.MOVING_TO_START;
            else
                dockingStep = DockingStep.DOCKING;
        }
        void DrawBoundingBox()
        {
            if (drawBoundingBox && vessel == FlightGlobals.ActiveVessel)
            {
                vesselBoundingBox = vessel.GetBoundingBox();
                GLUtils.DrawBoundingBox(vessel.mainBody, vessel, vesselBoundingBox, Color.green);

                if (core.target.Target != null)
                {
                    Vessel targetVessel = core.target.Target.GetVessel();
                    targetBoundingBox = targetVessel.GetBoundingBox();
                    GLUtils.DrawBoundingBox(targetVessel.mainBody, targetVessel, targetBoundingBox, Color.blue);
                }
            }
        }