Jump to content

Basic Line, Point and Transform Debug code


Recommended Posts

Working with KSP multiple coordinate systems can be a pain and sometime a quick drawing on screen help understanding what is going on. Here is class to draw some debugging lines, point and transforms.

https://github.com/sarbian/DebugStuff/blob/master/DebugDrawer.cs

Licence : public domain. 

Calling it is as simple as a line in an Update()

DebugDrawer.DebugLine(FlightGlobals.ActiveVessel.transform.position, Planetarium.fetch.Home.transform.position, Color.yellow);

DebugDrawer.DebugPoint(Vector3.zero, Color.green);

DebugDrawer.DebugTransforms(FlightGlobals.ActiveVessel.transform);

 

 

Edited by sarbian
Link to comment
Share on other sites

  • 3 months later...

Thank you for this. 

I found some small problem:

I had to add this into the code:

        private IEnumerator EndOfFrameDrawing()
        {
            Debug.Log("DebugDrawer starting");
            while (true)
            {
                if ((lines.Count + points.Count + transforms.Count) == 0 )
                {
                    yield return new WaitForEndOfFrame();
                    continue;
                }

I mean the if 

Quote

                if ((lines.Count + points.Count + transforms.Count) == 0 )
                {
                    yield return new WaitForEndOfFrame();
                    continue;
                }

I got thousands GL Matrix Error as long I don't draw lines and KSP got funky after some time (Kerbin crashed) 

Is there a reason why you did't put the drawing into the unity Draw() call?

  I also extended it to use this function. 

Quote

      /// <summary>
        /// Paints the vector from the start point
        /// </summary>
        /// <param name="start"></param>
        /// <param name="vector"></param>
        /// <param name="col"></param>
        public static void DebugVector(Vector3 start, Vector3 vector, Color col)
        {
            lines.Add(new Line(start, start + vector, col));
        }

 

Edited by Ger_space
Added DebugVector
Link to comment
Share on other sites

57 minutes ago, Ger_space said:

I got thousands GL Matrix Error as long I don't draw lines and KSP got funky after some tim

With the updated version or the original one ?

 

59 minutes ago, Ger_space said:

unity Draw() call?

Which Draw call ? 

Link to comment
Share on other sites

1 minute ago, Ger_space said:

The Unity one is OnGUI().

I dont like to use OnGui for something it is not meant to do. And you have to check for the current event to avoid drawing multiple time since onGui is called a bunch of time per frame.

Link to comment
Share on other sites

  • 1 year later...

In KSP 1.7.2 I can't get the DebugDrawer methods to show anything in the map view, although it seems to me the class is meant to have the ability.
Is there any trick for making that work (outside of converting the values to scaledspace scale) ?

Link to comment
Share on other sites

On 6/18/2019 at 7:53 PM, Gotmachine said:

outside of converting the values to scaledspace scale

If you don't convert to scaled space then what your are drawing will not be at the correct scale.

Link to comment
Share on other sites

I am converting to scaledspace. I'm pretty sure of what I'm doing in this aspect as I can draw my intended lines using another method.
They just don't show up when I'm using the DebugDrawer class.
Although that work perfectly fine in flight mode/scene (with non-ScaledSpace coordinates, of course ;))

Link to comment
Share on other sites

This thread is quite old. Please consider starting a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...