Updated readability of the code.
[sixth-3d.git] / src / main / java / eu / svjatoslav / sixth / e3d / gui / UserRelativityTracker.java
1 /*
2  * Sixth 3D engine. Author: Svjatoslav Agejenko.
3  * This project is released under Creative Commons Zero (CC0) license.
4  */
5 package eu.svjatoslav.sixth.e3d.gui;
6
7 import eu.svjatoslav.sixth.e3d.geometry.Point3D;
8 import eu.svjatoslav.sixth.e3d.math.TransformsStack;
9 import eu.svjatoslav.sixth.e3d.math.Vertex;
10
11 public class UserRelativityTracker {
12
13     private final static int minimalSliceFactor = 5;
14     public Vertex center = new Vertex();
15     public Vertex right;
16     public Vertex down;
17
18     public UserRelativityTracker() {
19
20     }
21
22     public void analyze(final TransformsStack transformPipe,
23                         final RenderingContext renderingContext) {
24
25         center.calculateLocationRelativeToViewer(transformPipe, renderingContext);
26
27         if (right != null) {
28             right.calculateLocationRelativeToViewer(transformPipe, renderingContext);
29             down.calculateLocationRelativeToViewer(transformPipe, renderingContext);
30         }
31     }
32
33     public void enableOrientationTracking() {
34         right = new Vertex(new Point3D(10, 0, 0));
35         down = new Vertex(new Point3D(0, 10, 0));
36     }
37
38     public double getAngleXY() {
39         return center.transformedCoordinate
40                 .getAngleXY(down.transformedCoordinate);
41     }
42
43     public double getAngleXZ() {
44         return center.transformedCoordinate
45                 .getAngleXZ(right.transformedCoordinate);
46     }
47
48     public double getAngleYZ() {
49         return center.transformedCoordinate
50                 .getAngleYZ(down.transformedCoordinate);
51     }
52
53     public double getDistanceToUser() {
54         return center.transformedCoordinate.getVectorLength();
55     }
56
57     public double proposeSliceFactor() {
58         final double distanceToCamera = getDistanceToUser();
59
60         double proposedSliceFactor = distanceToCamera / 5;
61
62         if (proposedSliceFactor < minimalSliceFactor)
63             proposedSliceFactor = minimalSliceFactor;
64
65         return proposedSliceFactor;
66     }
67
68 }