Class Projector

java.lang.Object
lol.trq.helios.math.Projector

public final class Projector extends Object
Projects 3D points to screen coordinates, as gluProject does, without allocating.

Capture the matrices where the 3D scene is drawn (in a world render hook, where Minecraft's matrices are camera-relative), then project points during GUI drawing. Results are in drawing units with the origin at the top left: framebuffer pixels times pixel, which is 1 / guiScale on a GUI screen.

// world render hook:
projector.capture(helios.gl(), 1f / scaledResolution.getScaleFactor());
// GUI draw:
float[] box = new float[4];
if (projector.projectBox(minX, minY, minZ, maxX, maxY, maxZ, box)) {
    batch.outline(box[0], box[1], box[2] - box[0], box[3] - box[1], 0, 1, Paint.solid(0xFFFF4040));
}
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a projector with identity matrices and an empty viewport.
  • Method Summary

    Modifier and Type
    Method
    Description
    capture(GlBackend gl, float pixel)
    Captures the host's current model-view and projection matrices and the viewport.
    boolean
    project(double x, double y, double z, float[] out)
    Projects a point.
    boolean
    projectBox(double minX, double minY, double minZ, double maxX, double maxY, double maxZ, float[] out)
    Projects an axis-aligned box and returns its screen bounds: the 2D box for ESP.
    set(float[] modelView, float[] projection, int[] viewport, float pixel)
    Sets the matrices and viewport directly.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • Projector

      public Projector()
      Creates a projector with identity matrices and an empty viewport.
  • Method Details

    • capture

      public Projector capture(GlBackend gl, float pixel)
      Captures the host's current model-view and projection matrices and the viewport.
      Parameters:
      gl - the backend
      pixel - one framebuffer pixel in output units, such as 1 / guiScale
      Returns:
      this projector
    • set

      public Projector set(float[] modelView, float[] projection, int[] viewport, float pixel)
      Sets the matrices and viewport directly.
      Parameters:
      modelView - the model-view matrix, column-major; copied
      projection - the projection matrix, column-major; copied
      viewport - x, y, width, height in framebuffer pixels; copied
      pixel - one framebuffer pixel in output units
      Returns:
      this projector
    • project

      public boolean project(double x, double y, double z, float[] out)
      Projects a point.
      Parameters:
      x - x in the captured model space
      y - y
      z - z
      out - receives screen x, screen y (drawing units, top-left origin) and depth (0 near, 1 far)
      Returns:
      false when the point is behind the camera, leaving out unspecified
    • projectBox

      public boolean projectBox(double minX, double minY, double minZ, double maxX, double maxY, double maxZ, float[] out)
      Projects an axis-aligned box and returns its screen bounds: the 2D box for ESP.
      Parameters:
      minX - box min x
      minY - box min y
      minZ - box min z
      maxX - box max x
      maxY - box max y
      maxZ - box max z
      out - receives left, top, right, bottom in drawing units
      Returns:
      false when no corner is in front of the camera within the depth range