f50f6d9263f9e028a7c01e532f0549395a0c8bcc
[sixth-3d.git] / src / main / java / eu / svjatoslav / sixth / e3d / gui / UserRelativityTracker.java
1 /*
2  * Sixth - System for data storage, computation, exploration and interaction.
3  * Copyright ©2012-2016, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
4  * 
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of version 3 of the GNU Lesser General Public License
7  * or later as published by the Free Software Foundation.
8  */
9
10
11 package eu.svjatoslav.sixth.e3d.gui;
12
13 import eu.svjatoslav.sixth.e3d.geometry.GeometryCoordinate;
14 import eu.svjatoslav.sixth.e3d.geometry.Point3D;
15 import eu.svjatoslav.sixth.e3d.geometry.TransformPipe;
16
17 public class UserRelativityTracker {
18
19     public 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
61                 .getDistanceTo(Point3D.ZERO);
62     }
63
64     public double proposeSliceFactor() {
65         final double distanceToCamera = getDistanceToUser();
66
67         double proposedSliceFactor = distanceToCamera / 5;
68
69         if (proposedSliceFactor < minimalSliceFactor)
70             proposedSliceFactor = minimalSliceFactor;
71
72         return proposedSliceFactor;
73     }
74
75 }