2 * Sixth 3D engine. Author: Svjatoslav Agejenko.
3 * This project is released under Creative Commons Zero (CC0) license.
5 package eu.svjatoslav.sixth.e3d.math;
7 import eu.svjatoslav.sixth.e3d.geometry.Point2D;
8 import eu.svjatoslav.sixth.e3d.geometry.Point3D;
9 import eu.svjatoslav.sixth.e3d.gui.RenderingContext;
12 * It is used to store coordinates of vertices of 3D objects.
13 * It is also used to store coordinates of points in 3D space.
18 * Vertex coordinate in 3D space.
20 public Point3D coordinate;
23 * Vertex coordinate relative to the viewer after transformation.
25 public Point3D transformedCoordinate;
28 * Vertex coordinate on screen after transformation.
30 public Point2D onScreenCoordinate;
32 private int lastTransformedFrame;
35 coordinate = new Point3D();
36 transformedCoordinate = new Point3D();
37 onScreenCoordinate = new Point2D();
40 public Vertex(final Point3D location) {
41 coordinate = location;
42 transformedCoordinate = new Point3D();
43 onScreenCoordinate = new Point2D();
47 * Transforms the coordinate.
49 * @param transforms The transforms pipeline.
50 * @param renderContext The rendering context.
52 public void transform(final TransformsPipeline transforms,
53 final RenderingContext renderContext) {
55 if (lastTransformedFrame == renderContext.frameNumber)
58 lastTransformedFrame = renderContext.frameNumber;
60 transforms.transform(coordinate, transformedCoordinate);
62 onScreenCoordinate.x = ((transformedCoordinate.x / transformedCoordinate.z) * renderContext.zoom);
63 onScreenCoordinate.y = ((transformedCoordinate.y / transformedCoordinate.z) * renderContext.zoom);
64 onScreenCoordinate.add(renderContext.centerCoordinate);