Removed ViewListener interface. Renamed View to ViewPanel.
[sixth-3d.git] / src / main / java / eu / svjatoslav / sixth / e3d / gui / UserRelativityTracker.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
11 package eu.svjatoslav.sixth.e3d.gui;
12
13 import eu.svjatoslav.sixth.e3d.math.GeometryCoordinate;
14 import eu.svjatoslav.sixth.e3d.geometry.Point3D;
15 import eu.svjatoslav.sixth.e3d.math.TransformPipe;
16
17 public class UserRelativityTracker {
18
19     private final static int minimalSliceFactor = 5;
20     public GeometryCoordinate center = new GeometryCoordinate();
21     public GeometryCoordinate right;
22     public GeometryCoordinate down;
23
24     public UserRelativityTracker() {
25
26     }
27
28     public void analyze(final TransformPipe transformPipe,
29                         final RenderingContext renderingContext) {
30
31         center.transform(transformPipe, renderingContext);
32
33         if (right != null) {
34             right.transform(transformPipe, renderingContext);
35             down.transform(transformPipe, renderingContext);
36         }
37     }
38
39     public void enableOrientationTracking() {
40         right = new GeometryCoordinate(new Point3D(10, 0, 0));
41         down = new GeometryCoordinate(new Point3D(0, 10, 0));
42     }
43
44     public double getAngleXY() {
45         return center.transformedCoordinate
46                 .getAngleXY(down.transformedCoordinate);
47     }
48
49     public double getAngleXZ() {
50         return center.transformedCoordinate
51                 .getAngleXZ(right.transformedCoordinate);
52     }
53
54     public double getAngleYZ() {
55         return center.transformedCoordinate
56                 .getAngleYZ(down.transformedCoordinate);
57     }
58
59     public double getDistanceToUser() {
60         return center.transformedCoordinate.getVectorLength();
61     }
62
63     public double proposeSliceFactor() {
64         final double distanceToCamera = getDistanceToUser();
65
66         double proposedSliceFactor = distanceToCamera / 5;
67
68         if (proposedSliceFactor < minimalSliceFactor)
69             proposedSliceFactor = minimalSliceFactor;
70
71         return proposedSliceFactor;
72     }
73
74 }