Skip to content

Instantly share code, notes, and snippets.

@karl-
Created February 12, 2025 15:31
Show Gist options
  • Save karl-/81872c8438cef405ff4c439dcd943716 to your computer and use it in GitHub Desktop.
Save karl-/81872c8438cef405ff4c439dcd943716 to your computer and use it in GitHub Desktop.
Draw wire bounding box corners.
public static void CubeWireCorners(Vector3 center, Vector3 size)
{
var ext = size * .5f;
DrawCorner(Matrix4x4.TRS(center - ext, Quaternion.identity, Vector3.one));
DrawCorner(Matrix4x4.TRS(center + ext, Quaternion.Euler(180f, 90f, 0f), Vector3.one));
DrawCorner(Matrix4x4.TRS(center + new Vector3(-ext.x, -ext.y, ext.z), Quaternion.Euler(0f, 90f, 0f), Vector3.one));
DrawCorner(Matrix4x4.TRS(center + new Vector3(-ext.x, ext.y, ext.z), Quaternion.Euler(180f, 0f, 0f), Vector3.one));
DrawCorner(Matrix4x4.TRS(center + new Vector3(-ext.x, ext.y, -ext.z), Quaternion.Euler(180f, -90f, 0f), Vector3.one));
DrawCorner(Matrix4x4.TRS(center + new Vector3( ext.x, -ext.y, -ext.z), Quaternion.Euler(0f, -90f, 0f), Vector3.one));
DrawCorner(Matrix4x4.TRS(center + new Vector3( ext.x, -ext.y, ext.z), Quaternion.Euler(0f, 180f, 0f), Vector3.one));
DrawCorner(Matrix4x4.TRS(center + new Vector3( ext.x, ext.y, -ext.z), Quaternion.Euler(180f, 180f, 0f), Vector3.one));
void DrawCorner(Matrix4x4 trs)
{
var c = trs.MultiplyPoint3x4(Vector3.zero);
Handles.DrawLine(c, c + trs.MultiplyVector(Vector3.right) * .2f, LineThickness);
Handles.DrawLine(c, c + trs.MultiplyVector(Vector3.forward) * .2f, LineThickness);
Handles.DrawLine(c, c + trs.MultiplyVector(Vector3.up) * .2f, LineThickness);
}
}
@karl-
Copy link
Author

karl- commented Feb 12, 2025

Screenshot 2025-02-12 at 10 30 04 AM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment