*/
package eu.svjatoslav.sixth.e3d.gui;
+import static java.lang.Integer.compare;
+
/**
* A pointer to a character in a text using row and column.
* <p>
return result;
}
+ /**
+ * Compares this pointer to another pointer.
+ *
+ * @param textPointer The pointer to compare to.
+ * @return <ul>
+ * <li>-1 if this pointer is smaller than the argument pointer.</li>
+ * <li>0 if they are equal.</li>
+ * <li>1 if this pointer is bigger than the argument pointer.</li>
+ * </ul>
+ */
@Override
public int compareTo(final TextPointer textPointer) {
- if (textPointer.row > row)
+ if (row < textPointer.row)
return -1;
- if (textPointer.row < row)
+ if (row > textPointer.row)
return 1;
- return Integer.compare(column, textPointer.column);
-
+ return compare(column, textPointer.column);
}
/**
- * Checks if this pointer is between the specified pointers.
+ * Checks if this pointer is between the argument pointers.
+ * <p>
+ * This pointer is considered to be between the pointers if it is bigger or equal to the start pointer
+ * and smaller than the end pointer.
*
* @param start The start pointer.
* @param end The end pointer.
import eu.svjatoslav.sixth.e3d.math.TransformsStack;
import eu.svjatoslav.sixth.e3d.math.Vertex;
+/**
+ * Tracks the position of the user in the 3D space.
+ * <p>
+ * It can be used to determine the angle between the user and the object.
+ * Also, it can be used to determine the distance between the user and the object.
+ */
+
public class UserRelativityTracker {
private final static int minimalSliceFactor = 5;
import eu.svjatoslav.sixth.e3d.gui.RenderingContext;
/**
- * It is used to store coordinates of vertices of 3D objects.
- * It is also used to store coordinates of points in 3D space.
+ * Vertex is a point where two or more lines, line segments, or rays come together.
+ * In other words, it's a corner of a polygon, polyhedron, or other geometric shape.
+ * For example, a triangle has three vertices, a square has four, and a cube has eight.
*/
public class Vertex {
* Vertex coordinate relative to the viewer after transformation.
* Visible vertices have positive z coordinate.
* Viewer is located at (0, 0, 0).
+ * No perspective correction is applied.
*/
public Point3D transformedCoordinate;
/**
- * Vertex coordinate in pixels relative to the top left corner of the screen after transformation.
+ * Vertex coordinate in pixels relative to the top left corner of the screen after transformation
+ * and perspective correction.
*/
public Point2D onScreenCoordinate;
import static eu.svjatoslav.sixth.e3d.renderer.raster.Color.BLACK;
import static eu.svjatoslav.sixth.e3d.renderer.raster.Color.WHITE;
+import static java.lang.Math.PI;
+import static java.lang.Math.abs;
public class TextCanvas extends TexturedRectangle {
@Override
public void beforeTransformHook(final TransformsStack transformPipe,
final RenderingContext context) {
+ ensureOptimalRenderMode(context);
+ }
- final double textRelativeSize = context.width
- / getRelativityTracker().getDistanceToUser();
+ private void ensureOptimalRenderMode(RenderingContext context) {
+ // if the text is too far away, use texture
+ final double textRelativeSize = context.width / getRelativityTracker().getDistanceToUser();
if (textRelativeSize < 2d) {
- if (renderMode == RenderMode.CHARACTERS)
- setRenderMode(RenderMode.TEXTURE);
+ setRenderMode(RenderMode.TEXTURE);
return;
}
- final double piHalf = Math.PI / 2;
-
- final double deviation = Math.abs(getRelativityTracker().getAngleXZ()
+ // if user is looking at the text from the side, use texture
+ final double piHalf = PI / 2;
+ final double deviation = abs(getRelativityTracker().getAngleXZ()
+ piHalf)
- + Math.abs(getRelativityTracker().getAngleYZ() + piHalf);
+ + abs(getRelativityTracker().getAngleYZ() + piHalf);
final double maxDeviation = 0.5;
-
- if (deviation > maxDeviation) {
- if (renderMode == RenderMode.CHARACTERS)
- setRenderMode(RenderMode.TEXTURE);
- } else if (renderMode == RenderMode.TEXTURE)
- setRenderMode(RenderMode.CHARACTERS);
+ setRenderMode(deviation > maxDeviation ? RenderMode.TEXTURE : RenderMode.CHARACTERS);
}
public void clear() {