2 * Sixth 3D engine. Copyright ©2012-2018, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
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.
11 package eu.svjatoslav.sixth.e3d.gui;
13 import eu.svjatoslav.sixth.e3d.math.GeometryCoordinate;
14 import eu.svjatoslav.sixth.e3d.geometry.Point3D;
15 import eu.svjatoslav.sixth.e3d.math.TransformPipe;
17 public class UserRelativityTracker {
19 private final static int minimalSliceFactor = 5;
20 public GeometryCoordinate center = new GeometryCoordinate();
21 public GeometryCoordinate right;
22 public GeometryCoordinate down;
24 public UserRelativityTracker() {
28 public void analyze(final TransformPipe transformPipe,
29 final RenderingContext renderingContext) {
31 center.transform(transformPipe, renderingContext);
34 right.transform(transformPipe, renderingContext);
35 down.transform(transformPipe, renderingContext);
39 public void enableOrientationTracking() {
40 right = new GeometryCoordinate(new Point3D(10, 0, 0));
41 down = new GeometryCoordinate(new Point3D(0, 10, 0));
44 public double getAngleXY() {
45 return center.transformedCoordinate
46 .getAngleXY(down.transformedCoordinate);
49 public double getAngleXZ() {
50 return center.transformedCoordinate
51 .getAngleXZ(right.transformedCoordinate);
54 public double getAngleYZ() {
55 return center.transformedCoordinate
56 .getAngleYZ(down.transformedCoordinate);
59 public double getDistanceToUser() {
60 return center.transformedCoordinate.getVectorLength();
63 public double proposeSliceFactor() {
64 final double distanceToCamera = getDistanceToUser();
66 double proposedSliceFactor = distanceToCamera / 5;
68 if (proposedSliceFactor < minimalSliceFactor)
69 proposedSliceFactor = minimalSliceFactor;
71 return proposedSliceFactor;