Refactoring.
[sixth-3d.git] / src / main / java / eu / svjatoslav / sixth / e3d / geometry / GeometryCoordinate.java
1 /*
2  * Sixth 3D engine. Copyright ©2012-2018, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of version 3 of the GNU Lesser General Public License
6  * or later as published by the Free Software Foundation.
7  *
8  */
9
10 package eu.svjatoslav.sixth.e3d.geometry;
11
12 import eu.svjatoslav.sixth.e3d.gui.RenderingContext;
13
14 public class GeometryCoordinate {
15
16     public Point3D coordinate;
17     public Point3D transformedCoordinate;
18     public Point2D onScreenCoordinate;
19
20     int lastTransformedFrame;
21
22     public GeometryCoordinate() {
23         coordinate = new Point3D();
24         transformedCoordinate = new Point3D();
25         onScreenCoordinate = new Point2D();
26     }
27
28     public GeometryCoordinate(final Point3D location) {
29         coordinate = location;
30         transformedCoordinate = new Point3D();
31         onScreenCoordinate = new Point2D();
32     }
33
34     public void transform(final TransformPipe transforms,
35                           final RenderingContext renderContext) {
36
37         if (lastTransformedFrame == renderContext.frameNumber)
38             return;
39
40         lastTransformedFrame = renderContext.frameNumber;
41
42         transforms.transform(coordinate, transformedCoordinate);
43
44         onScreenCoordinate.x = ((transformedCoordinate.x / transformedCoordinate.z) * renderContext.zoom)
45                 + renderContext.xCenter;
46         onScreenCoordinate.y = ((transformedCoordinate.y / transformedCoordinate.z) * renderContext.zoom)
47                 + renderContext.yCenter;
48     }
49 }