Drawing in the XZ plane

Last modified:

Some Shapes drawing functions don't accept 3D coordinates, such as lines with in Flat2D geometry, polylines, or Arcs.

So if you want to draw on any other plane than the XY plane (like the XZ plane), you'll have to either:

  1. When using component shapes, rotate the transform of the shape game object into the plane you want it to be in
  2. When using immediate mode shapes, rotate the drawing matrix, so that the drawing matrix XY coordinates align with XZ (or any other plane you want to render in)

Here's some example code, for immediate mode drawing of lines in the XZ plane:

// Drawing on the XZ plane, with 3D coordinates and billboarded lines
Draw.LineGeometry = LineGeometry.Billboard; // we can't use Flat2D here, since Flat2D works in XY
Vector3 a = new(1, 0, 2);
Vector3 b = new(3, 0, 4);
Draw.Line( a, b );

// Drawing on the XZ plane, with 2D coordinates
using( Draw.Scope ) { // resets rotation back to what it was before, when leaving this scope
    Draw.Rotate( Quaternion.Euler( 90, 0, 0 ) ); // aligns drawing Y with world Z
    Draw.LineGeometry = LineGeometry.Flat2D; // restricts coordinates to XY only
    Vector2 a = new(1, 2);
    Vector2 b = new(3, 4);
    Draw.Line( a, b );

This article was helpful for 4 people. Is this article helpful for you?