2 * Sixth 3D engine. Author: Svjatoslav Agejenko.
3 * This project is released under Creative Commons Zero (CC0) license.
5 package eu.svjatoslav.sixth.e3d.gui;
7 import eu.svjatoslav.sixth.e3d.geometry.Point3D;
8 import eu.svjatoslav.sixth.e3d.math.TransformsStack;
9 import eu.svjatoslav.sixth.e3d.math.Vertex;
11 public class UserRelativityTracker {
13 private final static int minimalSliceFactor = 5;
14 public Vertex center = new Vertex();
18 public UserRelativityTracker() {
22 public void analyze(final TransformsStack transformPipe,
23 final RenderingContext renderingContext) {
25 center.calculateLocationRelativeToViewer(transformPipe, renderingContext);
28 right.calculateLocationRelativeToViewer(transformPipe, renderingContext);
29 down.calculateLocationRelativeToViewer(transformPipe, renderingContext);
33 public void enableOrientationTracking() {
34 right = new Vertex(new Point3D(10, 0, 0));
35 down = new Vertex(new Point3D(0, 10, 0));
38 public double getAngleXY() {
39 return center.transformedCoordinate
40 .getAngleXY(down.transformedCoordinate);
43 public double getAngleXZ() {
44 return center.transformedCoordinate
45 .getAngleXZ(right.transformedCoordinate);
48 public double getAngleYZ() {
49 return center.transformedCoordinate
50 .getAngleYZ(down.transformedCoordinate);
53 public double getDistanceToUser() {
54 return center.transformedCoordinate.getVectorLength();
57 public double proposeSliceFactor() {
58 final double distanceToCamera = getDistanceToUser();
60 double proposedSliceFactor = distanceToCamera / 5;
62 if (proposedSliceFactor < minimalSliceFactor)
63 proposedSliceFactor = minimalSliceFactor;
65 return proposedSliceFactor;