Direct Known Subclasses:
RaytracingCamera, TextCanvas

public class TexturedRectangle extends AbstractCompositeShape
A rectangular shape with texture mapping, composed of two textured triangles.

This composite shape creates a textured rectangle in 3D space by splitting it into two TexturedPolygon triangles that share a common Texture. The rectangle is centered at the origin of its local coordinate system, with configurable world-space dimensions and independent texture resolution.

The contained Texture object is accessible via getTexture(), allowing dynamic rendering to the texture surface (e.g., drawing text, images, or procedural content) after construction.

Usage example:


 // Create a 200x100 textured rectangle at position (0, 0, 300)
 Transform transform = new Transform(new Point3D(0, 0, 300));
 TexturedRectangle rect = new TexturedRectangle(transform, 200, 100, 2);

 // Draw onto the texture dynamically
 Texture tex = rect.getTexture();
 tex.graphics.setColor(java.awt.Color.RED);
 tex.graphics.fillRect(0, 0, 50, 50);

 // Add to the scene
 shapeCollection.addShape(rect);
 
See Also:
  • Field Details

    • topLeft

      public Point3D topLeft
      Top-left corner position in local 3D coordinates.
    • topRight

      public Point3D topRight
      Top-right corner position in local 3D coordinates.
    • bottomRight

      public Point3D bottomRight
      Bottom-right corner position in local 3D coordinates.
    • bottomLeft

      public Point3D bottomLeft
      Bottom-left corner position in local 3D coordinates.
    • textureTopLeft

      public Point2D textureTopLeft
      Top-left corner mapping in texture coordinates (pixels).
    • textureTopRight

      public Point2D textureTopRight
      Top-right corner mapping in texture coordinates (pixels).
    • textureBottomRight

      public Point2D textureBottomRight
      Bottom-right corner mapping in texture coordinates (pixels).
    • textureBottomLeft

      public Point2D textureBottomLeft
      Bottom-left corner mapping in texture coordinates (pixels).
  • Constructor Details

    • TexturedRectangle

      public TexturedRectangle(Transform transform)
      Creates a textured rectangle with only a transform, without initializing geometry.

      After construction, call initialize(double, double, int, int, int) to set up the rectangle's dimensions, texture, and triangle geometry.

      Parameters:
      transform - the position and orientation of this rectangle in the scene
    • TexturedRectangle

      public TexturedRectangle(Transform transform, int width, int height, int maxTextureUpscale)
      Creates a textured rectangle where the texture resolution matches the world-space size.

      This is a convenience constructor equivalent to calling TexturedRectangle(Transform, int, int, int, int, int) with textureWidth = width and textureHeight = height.

      Parameters:
      transform - the position and orientation of this rectangle in the scene
      width - the width of the rectangle in world units (also used as texture width in pixels)
      height - the height of the rectangle in world units (also used as texture height in pixels)
      maxTextureUpscale - the maximum mipmap upscale factor for the texture
    • TexturedRectangle

      public TexturedRectangle(Transform transform, int width, int height, int textureWidth, int textureHeight, int maxTextureUpscale)
      Creates a fully initialized textured rectangle with independent world-space size and texture resolution.
      Parameters:
      transform - the position and orientation of this rectangle in the scene
      width - the width of the rectangle in world units
      height - the height of the rectangle in world units
      textureWidth - the width of the backing texture in pixels
      textureHeight - the height of the backing texture in pixels
      maxTextureUpscale - the maximum mipmap upscale factor for the texture
  • Method Details

    • getTexture

      public Texture getTexture()
      Returns the backing texture for this rectangle.

      The returned Texture can be used to draw dynamic content onto the rectangle's surface via its graphics field (a Graphics2D instance).

      Returns:
      the texture mapped onto this rectangle
    • initialize

      public void initialize(double width, double height, int textureWidth, int textureHeight, int maxTextureUpscale)
      Initializes the rectangle geometry, texture, and the two constituent textured triangles.

      The rectangle is centered at the local origin: corners span from (-width/2, -height/2, 0) to (width/2, height/2, 0). Two TexturedPolygon triangles are created to cover the full rectangle, sharing a single Texture instance.

      Parameters:
      width - the width of the rectangle in world units
      height - the height of the rectangle in world units
      textureWidth - the width of the backing texture in pixels
      textureHeight - the height of the backing texture in pixels
      maxTextureUpscale - the maximum mipmap upscale factor for the texture