Jump to content

GimbalDebug class to use in your plugin


philotical

Recommended Posts

What it does:

It will draw a line from the origin of the GameObject/Vessel/Part along each of the axis x/y/z as seen in unity editor.

It simulates a 3D-Gimbal.

It might help to debug the common rotation issues by making them visible in game.

Installation in your project:

simply change the namespace to fit your project and you are good to go..

The code below should work as it is - but you may change what ever you need to fit your situation..

/*
* GimbalDebug Class by Philotical is released as is with the license "Do what ever you want with it"
* All code you see is a direct derivate of Unity-Docs examples - so a license other than the above is obsolete
* Everyone can put that together on his own..
*
* Version 0.1 - released 17.06.2014
* bugs report here..
* http://forum.kerbalspaceprogram.com/threads/83386-GimbalDebug-class-to-use-in-your-plugin
*
* Usage:

GimbalDebug foo = new GimbalDebug();
foo.drawGimbal(nb.ship, 20, 0.5f);
// and later..
foo.removeGimbal();

* There are overloads:
* drawGimbal(GameObject o,int length, float width)
* drawGimbal(Vessel o,int length, float width)
* drawGimbal(Part o,int length, float width)

* What it does:
* It will draw a line from the origin of the GameObject/Vessel/Part along the axis x/y/z as seen in unity editor.
* It might help to debug the common rotation issues by making them visible in game.
*
* Installation in your project:
* simply change the namespace to fit your project and you are good to go..
* The code below should work as it is - but you may change what ever you need to fit your situation..

*/



using UnityEngine;

namespace YourCoolNameSpaceHere
{
class GimbalDebug
{
LineRenderer l1 = null;
LineRenderer l2 = null;
LineRenderer l3 = null;

public void drawGimbal(GameObject o,int length, float width)
{
_drawGimbal(o.transform, length, width);
}
public void drawGimbal(Vessel o, int length, float width)
{
_drawGimbal(o.transform, length, width);
}
public void drawGimbal(Part o, int length, float width)
{
_drawGimbal(o.transform, length, width);
}
public void removeGimbal()
{
_removeGimbal();
}
public void _drawGimbal(Transform o, int length, float width)
{
if (l1==null)
{
l1 = new LineRenderer();
l2 = new LineRenderer();
l3 = new LineRenderer();
}
this.l1 = DebugLine(l1, o.transform, o.transform.up, Color.green, length, width);
this.l2 = DebugLine(l2, o.transform, o.transform.right, Color.red, length, width);
this.l3 = DebugLine(l3, o.transform, o.transform.forward, Color.blue, length, width);
}
public void _removeGimbal()
{
this.l1.SetPosition(0, Vector3.zero);
this.l1.SetPosition(1, Vector3.zero);
this.l2.SetPosition(0, Vector3.zero);
this.l2.SetPosition(1, Vector3.zero);
this.l3.SetPosition(0, Vector3.zero);
this.l3.SetPosition(1, Vector3.zero);
}
private LineRenderer DebugLine(LineRenderer line, Transform origin, Vector3 transformDirection, Color color, int length, float width)
{
GameObject o = new GameObject("Test");
Transform transform = origin;
o.transform.parent = transform;
o.transform.localEulerAngles = Vector3.zero;
line = o.AddComponent<LineRenderer>();
line.transform.parent = transform;
line.useWorldSpace = false;
line.transform.localPosition = origin.localPosition;
line.transform.localEulerAngles = Vector3.zero;
line.material = new Material(Shader.Find("Particles/Additive"));
line.SetWidth(width, width);
line.SetVertexCount(2);
line.SetPosition(0, transform.localPosition);
line.SetPosition(1, transform.InverseTransformDirection(transformDirection) * length);
line.SetColors(color, color);
return line;
}

}
}

In case someone might find it usefull...

Screenshot:

uvyic5r.png

Bugs: report below...

have fun..

Edited by philotical
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...