Vixen
02b45cc4
csharp
public sealed class SceneGrid

The floor grid, at whatever spacing is legible from where the camera is.

No guide page documents this yet — the page shows what the code says about itself.

Remarks

The spacing is chosen, not fixed. A one-metre grid is a grey haze from two hundred metres up and three lines from half a metre away. The spacing is the power of ten (times one, two or five) that puts the lines roughly TargetSpacing pixels apart, which is the same rule a chart's axis ticks follow and for the same reason.

Two levels are drawn and the finer one fades. Snapping the spacing from one step of the sequence to the next in one frame makes the grid flash as the camera moves; drawing the next level down at an alpha that falls to zero as it becomes too dense makes the transition continuous, and it is what every editor that got this right does.

⚠ Every decision is made from the world coordinate, not from a loop index. Which lines are major, which are the axes and where a level starts are all facts about the world; a loop index is a fact about where the camera happens to be, because the lines are laid out from the pivot. Deriving the first of those from the second is what made the emphasised lines march sideways one line at a time as the view was panned — a grid that is subtly, continuously wrong and that nobody can point at.

It is a list of lines, not a draw call. What draws them is the viewport's business — a debug-line renderer, a shader, an overlay — and generating them here is what makes "does the grid pick a sane spacing" a unit test.

Fields and properties (10)

  • public const int MaximumLines

    How many lines one level may have across, whatever the camera asks for.

  • public bool Enabled

    Whether the grid is drawn at all.

  • public WorkPlane Plane

    The plane it draws, which is the ground until somebody moves it.

  • public float TargetSpacing

    How far apart the lines should look, in render pixels.

  • public float Reach

    How far a level reaches, in screen-heights of world at the pivot's depth.

  • public int Extent

    How many lines to draw either side of the middle, per level.

  • public Color4 LineColour

    The colour of an ordinary line.

  • public Color4 MajorColour

    The colour of every tenth line.

  • public Color4 AxisXColour

    The colour of the line through the origin along X.

  • public Color4 AxisZColour

    The colour of the line through the origin along Z.

Methods (3)

  • public float Spacing(EditorCamera camera, int height)

    The spacing the grid would use from where a camera is.

  • public IReadOnlyList<GridLine> Build(EditorCamera camera, int height)

    The lines to draw, in world space.

  • public (float Coarse, float Fine, float Fade) Levels(EditorCamera camera, int height)

    Which two spacings are drawn from where a camera is, and how much the finer shows.

Used by (8)

  • EditorApplicationVixen.Editor.App
  • GridTestsVixen.Editor.SceneView.Tests
  • SceneLinesVixen.Editor.SceneView
  • ScenePresenterVixen.Editor.App
  • SceneTestsVixen.Editor.SceneView.Tests
  • SceneViewportVixen.Editor.SceneView
  • WorkPlaneCommandTestsVixen.Editor.App.Tests
  • WorkPlaneTestsVixen.Editor.SceneView.Tests