projects
/
sixth-3d.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
ca3c552
)
Improved code readability
author
Svjatoslav Agejenko
<svjatoslav@svjatoslav.eu>
Sun, 21 May 2023 00:08:23 +0000
(
03:08
+0300)
committer
Svjatoslav Agejenko
<svjatoslav@svjatoslav.eu>
Sun, 21 May 2023 00:08:23 +0000
(
03:08
+0300)
src/main/java/eu/svjatoslav/sixth/e3d/gui/TextPointer.java
patch
|
blob
|
history
src/main/java/eu/svjatoslav/sixth/e3d/gui/UserRelativityTracker.java
patch
|
blob
|
history
src/main/java/eu/svjatoslav/sixth/e3d/math/Vertex.java
patch
|
blob
|
history
src/main/java/eu/svjatoslav/sixth/e3d/renderer/raster/shapes/composite/textcanvas/TextCanvas.java
patch
|
blob
|
history
diff --git
a/src/main/java/eu/svjatoslav/sixth/e3d/gui/TextPointer.java
b/src/main/java/eu/svjatoslav/sixth/e3d/gui/TextPointer.java
index
67291f5
..
91cd6e6
100755
(executable)
--- a/
src/main/java/eu/svjatoslav/sixth/e3d/gui/TextPointer.java
+++ b/
src/main/java/eu/svjatoslav/sixth/e3d/gui/TextPointer.java
@@
-4,6
+4,8
@@
*/
package eu.svjatoslav.sixth.e3d.gui;
*/
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>
/**
* A pointer to a character in a text using row and column.
* <p>
@@
-49,20
+51,32
@@
public class TextPointer implements Comparable<TextPointer> {
return result;
}
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) {
@Override
public int compareTo(final TextPointer textPointer) {
- if (
textPointer.row >
row)
+ if (
row < textPointer.
row)
return -1;
return -1;
- if (
textPointer.row <
row)
+ if (
row > textPointer.
row)
return 1;
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.
*
* @param start The start pointer.
* @param end The end pointer.
diff --git
a/src/main/java/eu/svjatoslav/sixth/e3d/gui/UserRelativityTracker.java
b/src/main/java/eu/svjatoslav/sixth/e3d/gui/UserRelativityTracker.java
index
6665676
..
dd706db
100644
(file)
--- a/
src/main/java/eu/svjatoslav/sixth/e3d/gui/UserRelativityTracker.java
+++ b/
src/main/java/eu/svjatoslav/sixth/e3d/gui/UserRelativityTracker.java
@@
-8,6
+8,13
@@
import eu.svjatoslav.sixth.e3d.geometry.Point3D;
import eu.svjatoslav.sixth.e3d.math.TransformsStack;
import eu.svjatoslav.sixth.e3d.math.Vertex;
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;
public class UserRelativityTracker {
private final static int minimalSliceFactor = 5;
diff --git
a/src/main/java/eu/svjatoslav/sixth/e3d/math/Vertex.java
b/src/main/java/eu/svjatoslav/sixth/e3d/math/Vertex.java
index
69b3095
..
50423b1
100644
(file)
--- a/
src/main/java/eu/svjatoslav/sixth/e3d/math/Vertex.java
+++ b/
src/main/java/eu/svjatoslav/sixth/e3d/math/Vertex.java
@@
-9,8
+9,9
@@
import eu.svjatoslav.sixth.e3d.geometry.Point3D;
import eu.svjatoslav.sixth.e3d.gui.RenderingContext;
/**
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 {
*/
public class Vertex {
@@
-23,11
+24,13
@@
public class Vertex {
* Vertex coordinate relative to the viewer after transformation.
* Visible vertices have positive z coordinate.
* Viewer is located at (0, 0, 0).
* 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;
/**
*/
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;
*/
public Point2D onScreenCoordinate;
diff --git
a/src/main/java/eu/svjatoslav/sixth/e3d/renderer/raster/shapes/composite/textcanvas/TextCanvas.java
b/src/main/java/eu/svjatoslav/sixth/e3d/renderer/raster/shapes/composite/textcanvas/TextCanvas.java
index
f77f71e
..
8c3e49f
100644
(file)
--- a/
src/main/java/eu/svjatoslav/sixth/e3d/renderer/raster/shapes/composite/textcanvas/TextCanvas.java
+++ b/
src/main/java/eu/svjatoslav/sixth/e3d/renderer/raster/shapes/composite/textcanvas/TextCanvas.java
@@
-19,6
+19,8
@@
import java.io.StringReader;
import static eu.svjatoslav.sixth.e3d.renderer.raster.Color.BLACK;
import static eu.svjatoslav.sixth.e3d.renderer.raster.Color.WHITE;
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 {
public class TextCanvas extends TexturedRectangle {
@@
-132,29
+134,26
@@
public class TextCanvas extends TexturedRectangle {
@Override
public void beforeTransformHook(final TransformsStack transformPipe,
final RenderingContext context) {
@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 (textRelativeSize < 2d) {
- if (renderMode == RenderMode.CHARACTERS)
- setRenderMode(RenderMode.TEXTURE);
+ setRenderMode(RenderMode.TEXTURE);
return;
}
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)
+ piHalf)
- +
Math.
abs(getRelativityTracker().getAngleYZ() + piHalf);
+ + abs(getRelativityTracker().getAngleYZ() + piHalf);
final double maxDeviation = 0.5;
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() {
}
public void clear() {