2 * Sixth 3D engine. Author: Svjatoslav Agejenko.
3 * This project is released under Creative Commons Zero (CC0) license.
9 package eu.svjatoslav.sixth.e3d.gui;
11 import eu.svjatoslav.sixth.e3d.geometry.Point3D;
12 import eu.svjatoslav.sixth.e3d.math.GeometryCoordinate;
13 import eu.svjatoslav.sixth.e3d.math.TransformPipe;
15 public class UserRelativityTracker {
17 private final static int minimalSliceFactor = 5;
18 public GeometryCoordinate center = new GeometryCoordinate();
19 public GeometryCoordinate right;
20 public GeometryCoordinate down;
22 public UserRelativityTracker() {
26 public void analyze(final TransformPipe transformPipe,
27 final RenderingContext renderingContext) {
29 center.transform(transformPipe, renderingContext);
32 right.transform(transformPipe, renderingContext);
33 down.transform(transformPipe, renderingContext);
37 public void enableOrientationTracking() {
38 right = new GeometryCoordinate(new Point3D(10, 0, 0));
39 down = new GeometryCoordinate(new Point3D(0, 10, 0));
42 public double getAngleXY() {
43 return center.transformedCoordinate
44 .getAngleXY(down.transformedCoordinate);
47 public double getAngleXZ() {
48 return center.transformedCoordinate
49 .getAngleXZ(right.transformedCoordinate);
52 public double getAngleYZ() {
53 return center.transformedCoordinate
54 .getAngleYZ(down.transformedCoordinate);
57 public double getDistanceToUser() {
58 return center.transformedCoordinate.getVectorLength();
61 public double proposeSliceFactor() {
62 final double distanceToCamera = getDistanceToUser();
64 double proposedSliceFactor = distanceToCamera / 5;
66 if (proposedSliceFactor < minimalSliceFactor)
67 proposedSliceFactor = minimalSliceFactor;
69 return proposedSliceFactor;