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;
12 * Tracks the position of the user in the 3D space.
14 * It can be used to determine the angle between the user and the object.
15 * Also, it can be used to determine the distance between the user and the object.
18 public class UserRelativityTracker {
20 private final static int minimalSliceFactor = 5;
21 public Vertex center = new Vertex();
25 public UserRelativityTracker() {
29 public void analyze(final TransformsStack transformPipe,
30 final RenderingContext renderingContext) {
32 center.calculateLocationRelativeToViewer(transformPipe, renderingContext);
35 right.calculateLocationRelativeToViewer(transformPipe, renderingContext);
36 down.calculateLocationRelativeToViewer(transformPipe, renderingContext);
40 public void enableOrientationTracking() {
41 right = new Vertex(new Point3D(10, 0, 0));
42 down = new Vertex(new Point3D(0, 10, 0));
45 public double getAngleXY() {
46 return center.transformedCoordinate
47 .getAngleXY(down.transformedCoordinate);
50 public double getAngleXZ() {
51 return center.transformedCoordinate
52 .getAngleXZ(right.transformedCoordinate);
55 public double getAngleYZ() {
56 return center.transformedCoordinate
57 .getAngleYZ(down.transformedCoordinate);
60 public double getDistanceToUser() {
61 return center.transformedCoordinate.getVectorLength();
64 public double proposeSliceFactor() {
65 final double distanceToCamera = getDistanceToUser();
67 double proposedSliceFactor = distanceToCamera / 5;
69 if (proposedSliceFactor < minimalSliceFactor)
70 proposedSliceFactor = minimalSliceFactor;
72 return proposedSliceFactor;