-/*
- * Sixth 3D engine. Author: Svjatoslav Agejenko.
- * This project is released under Creative Commons Zero (CC0) license.
- */
-package eu.svjatoslav.sixth.e3d.math;
-
-import eu.svjatoslav.sixth.e3d.geometry.Point2D;
-import eu.svjatoslav.sixth.e3d.geometry.Point3D;
-import eu.svjatoslav.sixth.e3d.gui.RenderingContext;
-
-/**
- * A point in 3D space with a transformed and on-screen coordinates.
- */
-public class GeometryCoordinate {
-
- /**
- * The original coordinate.
- */
- public Point3D coordinate;
-
- /**
- * The transformed coordinate.
- */
- public Point3D transformedCoordinate;
-
- /**
- * The on-screen coordinate.
- */
- public Point2D onScreenCoordinate;
-
- private int lastTransformedFrame;
-
- public GeometryCoordinate() {
- coordinate = new Point3D();
- transformedCoordinate = new Point3D();
- onScreenCoordinate = new Point2D();
- }
-
- public GeometryCoordinate(final Point3D location) {
- coordinate = location;
- transformedCoordinate = new Point3D();
- onScreenCoordinate = new Point2D();
- }
-
- /**
- * Transforms the coordinate.
- *
- * @param transforms
- * The transform pipe.
- * @param renderContext
- * The rendering context.
- */
- public void transform(final TransformsPipeline transforms,
- final RenderingContext renderContext) {
-
- if (lastTransformedFrame == renderContext.frameNumber)
- return;
-
- lastTransformedFrame = renderContext.frameNumber;
-
- transforms.transform(coordinate, transformedCoordinate);
-
- onScreenCoordinate.x = ((transformedCoordinate.x / transformedCoordinate.z) * renderContext.zoom)
- + renderContext.xCenter;
- onScreenCoordinate.y = ((transformedCoordinate.y / transformedCoordinate.z) * renderContext.zoom)
- + renderContext.yCenter;
- }
-}