X-Git-Url: http://www2.svjatoslav.eu/gitweb/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Feu%2Fsvjatoslav%2Fsixth%2Fe3d%2Fmath%2FVertex.java;h=24c243fb46b83caa7800b787dae66ce6202bc8af;hb=59980888bd6bba94f84e4f63ce67e5b624df8aea;hp=0c77868b426dc844cd666376f5eeb24b3fa106d0;hpb=de8fb260a5e99922231b1d0f437916e796ec6ccb;p=sixth-3d.git diff --git a/src/main/java/eu/svjatoslav/sixth/e3d/math/Vertex.java b/src/main/java/eu/svjatoslav/sixth/e3d/math/Vertex.java index 0c77868..24c243f 100644 --- a/src/main/java/eu/svjatoslav/sixth/e3d/math/Vertex.java +++ b/src/main/java/eu/svjatoslav/sixth/e3d/math/Vertex.java @@ -1,5 +1,5 @@ /* - * Sixth 3D engine. Author: Svjatoslav Agejenko. + * Sixth 3D engine. Author: Svjatoslav Agejenko. * This project is released under Creative Commons Zero (CC0) license. */ package eu.svjatoslav.sixth.e3d.math; @@ -9,8 +9,9 @@ import eu.svjatoslav.sixth.e3d.geometry.Point3D; import eu.svjatoslav.sixth.e3d.gui.RenderingContext; /** - * It is used to store coordinates of vertices of 3D objects. - * It is also used to store coordinates of points in 3D space. + * Vertex is a point where two or more lines, line segments, or rays come together. + * In other words, it's a corner of a polygon, polyhedron, or other geometric shape. + * For example, a triangle has three vertices, a square has four, and a cube has eight. */ public class Vertex { @@ -21,36 +22,55 @@ public class Vertex { /** * Vertex coordinate relative to the viewer after transformation. + * Visible vertices have positive z coordinate. + * Viewer is located at (0, 0, 0). + * No perspective correction is applied. */ public Point3D transformedCoordinate; /** - * Vertex coordinate on screen after transformation. + * Vertex coordinate in pixels relative to the top left corner of the screen after transformation + * and perspective correction. */ public Point2D onScreenCoordinate; + + /** + * Coordinate within texture. + */ + public Point2D textureCoordinate; + + + /** + * The frame number when this vertex was last transformed. + */ private int lastTransformedFrame; public Vertex() { - coordinate = new Point3D(); - transformedCoordinate = new Point3D(); - onScreenCoordinate = new Point2D(); + this(new Point3D()); } public Vertex(final Point3D location) { + this(location, null); + } + + public Vertex(final Point3D location, Point2D textureCoordinate) { coordinate = location; transformedCoordinate = new Point3D(); onScreenCoordinate = new Point2D(); + this.textureCoordinate = textureCoordinate; } + /** - * Transforms the coordinate. + * Transforms vertex coordinate to calculate its location relative to the viewer. + * It also calculates its location on the screen. * - * @param transforms The transforms pipeline. - * @param renderContext The rendering context. + * @param transforms Transforms pipeline. + * @param renderContext Rendering context. */ - public void transform(final TransformsPipeline transforms, - final RenderingContext renderContext) { + public void calculateLocationRelativeToViewer(final TransformsStack transforms, + final RenderingContext renderContext) { if (lastTransformedFrame == renderContext.frameNumber) return;