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