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.
    • transformedCoordinate

      public Point3D transformedCoordinate
      Vertex coordinate relative to the viewer after transformation (camera space). Visible vertices have positive z coordinate (in front of the viewer). No perspective correction is applied.
    • onScreenCoordinate

      public Point2D onScreenCoordinate
      Vertex position on screen in pixels, relative to top-left corner. Calculated after transformation and perspective projection.
    • 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

    • 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 to avoid redundant calculations.

      Parameters:
      transforms - the transform stack to apply (world-to-camera transforms)
      renderContext - the rendering context providing 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