Class Vertex

java.lang.Object
eu.svjatoslav.sixth.e3d.math.Vertex

public class Vertex extends Object
A vertex in 3D space with transformation and screen projection support.

A vertex represents a corner point of a polygon or polyhedron. In addition to the 3D coordinate, it stores the transformed position (relative to viewer) and the projected screen coordinates for rendering.

Coordinate spaces:

Example:


 Vertex v = new Vertex(new Point3D(10, 20, 30));
 v.calculateLocationRelativeToViewer(transformStack, renderContext);
 if (v.transformedCoordinate.z > 0) {
     // Vertex is in front of the camera
 }
 
See Also:
  • Field Details

    • coordinate

      public Point3D coordinate
      Vertex coordinate in local/model 3D space.
    • textureCoordinate

      public Point2D textureCoordinate
      Texture coordinate for UV mapping (optional).
    • normal

      public Point3D normal
      Normal vector for this vertex (optional). Used by CSG operations for smooth interpolation during polygon splitting. Null for non-CSG usage; existing rendering code ignores this field.
  • Constructor Details

    • Vertex

      public Vertex()
      Creates a vertex at the origin (0, 0, 0) with no texture coordinate.
    • Vertex

      public Vertex(Point3D coordinate)
      Creates a vertex at the specified position with no texture coordinate.
      Parameters:
      coordinate - the 3D position of this vertex
    • Vertex

      public Vertex(Point3D coordinate, Point2D textureCoordinate)
      Creates a vertex at the specified position with an optional texture coordinate.
      Parameters:
      coordinate - the 3D position of this vertex
      textureCoordinate - the UV texture coordinate, or null for none
  • Method Details

    • transformedCoordinate

      public Point3D transformedCoordinate(RenderingContext renderContext)
      Returns the camera-space coordinate for the rendering context's buffer slot. Valid only after this vertex was transformed for that slot's current frame.
      Parameters:
      renderContext - the rendering context (selects the buffer slot)
      Returns:
      the transformed coordinate (camera space) for the active slot
    • onScreenCoordinate

      public Point2D onScreenCoordinate(RenderingContext renderContext)
      Returns the screen-space position for the rendering context's buffer slot.
      Parameters:
      renderContext - the rendering context (selects the buffer slot)
      Returns:
      the on-screen coordinate (pixels) for the active slot
    • calculateLocationRelativeToViewer

      public void calculateLocationRelativeToViewer(TransformStack transforms, RenderingContext renderContext)
      Transforms this vertex from model space to screen space.

      This method applies the transform stack to compute the vertex position relative to the viewer, then projects it to 2D screen coordinates. Results are cached per-frame per-slot to avoid redundant calculations.

      Parameters:
      transforms - the transform stack to apply (world-to-camera transforms)
      renderContext - the rendering context providing projection parameters
    • setCameraSpaceCoordinate

      public void setCameraSpaceCoordinate(double x, double y, double z, RenderingContext renderContext)
      Writes a camera-space position directly into this vertex's slot state and projects it to screen coordinates, bypassing the transform stack.

      Used by near-plane clipping (AbstractCoordinateShape), which creates intersection vertices that exist ONLY in camera space — there is no model-space coordinate to transform. The given z must be > 0 (clip against the near plane guarantees z == nearPlaneDistance).

      Parameters:
      x - camera-space X
      y - camera-space Y
      z - camera-space Z (depth in front of viewer, > 0)
      renderContext - the rendering context (selects the buffer slot and provides projection parameters)
    • clone

      public Vertex clone()
      Creates a deep copy of this vertex. Clones the coordinate, normal (if present), and texture coordinate (if present). The transformedCoordinate and onScreenCoordinate are not cloned (they are computed per-frame).
      Overrides:
      clone in class Object
      Returns:
      a new Vertex with cloned data
    • flip

      public void flip()
      Flips the orientation of this vertex by negating the normal vector. Called when the orientation of a polygon is flipped during CSG operations. If normal is null, this method does nothing.
    • interpolate

      public Vertex interpolate(Vertex other, double t)
      Creates a new vertex between this vertex and another by linearly interpolating all properties using parameter t.

      Interpolates: position, normal (if present), and texture coordinate (if present).

      Parameters:
      other - the other vertex to interpolate towards
      t - the interpolation parameter (0 = this vertex, 1 = other vertex)
      Returns:
      a new Vertex representing the interpolated position