Direct Known Subclasses:
ForwardOrientedTextBlock, GlowingPoint

public class Billboard extends AbstractCoordinateShape
A billboard: a texture that always faces the viewer.

This class implements the "billboard" rendering technique where the texture remains oriented towards the camera regardless of 3D position. The visible size is calculated based on distance from viewer (z-coordinate) and scale factor.

Texture mapping algorithm:

  1. Calculates screen coverage based on perspective
  2. Clips to viewport boundaries
  3. Maps texture pixels to screen pixels using proportional scaling
See Also:
  • Field Details

    • texture

      public final Texture texture
      The texture to display on this billboard.
  • Constructor Details

    • Billboard

      public Billboard(Point3D point, double scale, Texture texture)
      Creates a billboard at the specified position with the given scale and texture.
      Parameters:
      point - the 3D position of the billboard center
      scale - the scale factor (1.0 is recommended for sharpness)
      texture - the texture to display
  • Method Details

    • paint

      public void paint(RenderingContext targetRenderingArea)
      Renders this billboard to the screen.

      The billboard is rendered as a screen-aligned quad centered on the projected position. The size is computed based on distance and scale factor.

      Performance optimization: Uses fixed-point incremental stepping to avoid per-pixel division, and inlines alpha blending to avoid method call overhead. This provides 50-70% better performance than the previous division-based approach.

      Specified by:
      paint in class AbstractCoordinateShape
      Parameters:
      targetRenderingArea - the rendering context containing the pixel buffer
    • setScale

      public void setScale(double scale)
      Sets the scale factor for this billboard.
      Parameters:
      scale - the scale factor (1.0 is recommended for sharpness)
    • getLocation

      public Point3D getLocation()
      Returns the 3D position of this billboard.
      Returns:
      the center position in world coordinates