Package eu.svjatoslav.sixth.e3d.math
Class Vertex
java.lang.Object
eu.svjatoslav.sixth.e3d.math.Vertex
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:
coordinate- Original position in local/model spacetransformedCoordinate- Position relative to viewer (camera space)onScreenCoordinate- 2D screen position after perspective projection
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 Summary
FieldsModifier and TypeFieldDescriptionVertex coordinate in local/model 3D space.Normal vector for this vertex (optional).Vertex position on screen in pixels, relative to top-left corner.Texture coordinate for UV mapping (optional).Vertex coordinate relative to the viewer after transformation (camera space). -
Constructor Summary
ConstructorsConstructorDescriptionVertex()Creates a vertex at the origin (0, 0, 0) with no texture coordinate.Creates a vertex at the specified position with no texture coordinate.Creates a vertex at the specified position with an optional texture coordinate. -
Method Summary
Modifier and TypeMethodDescriptionvoidcalculateLocationRelativeToViewer(TransformStack transforms, RenderingContext renderContext) Transforms this vertex from model space to screen space.clone()Creates a deep copy of this vertex.voidflip()Flips the orientation of this vertex by negating the normal vector.interpolate(Vertex other, double t) Creates a new vertex between this vertex and another by linearly interpolating all properties using parameter t.
-
Field Details
-
coordinate
Vertex coordinate in local/model 3D space. -
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
Vertex position on screen in pixels, relative to top-left corner. Calculated after transformation and perspective projection. -
textureCoordinate
Texture coordinate for UV mapping (optional). -
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
Creates a vertex at the specified position with no texture coordinate.- Parameters:
coordinate- the 3D position of this vertex
-
Vertex
Creates a vertex at the specified position with an optional texture coordinate.- Parameters:
coordinate- the 3D position of this vertextextureCoordinate- the UV texture coordinate, ornullfor 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
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). -
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
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 towardst- the interpolation parameter (0 = this vertex, 1 = other vertex)- Returns:
- a new Vertex representing the interpolated position
-