*/
package eu.svjatoslav.sixth.e3d.gui;
+import eu.svjatoslav.sixth.e3d.geometry.Point2D;
import eu.svjatoslav.sixth.e3d.gui.humaninput.MouseEvent;
import eu.svjatoslav.sixth.e3d.gui.humaninput.MouseInteractionController;
public final byte[] pixels;
public final int width;
public final int height;
- public final int xCenter;
- public final int yCenter;
+ /**
+ * Center of the screen in screen space (pixels).
+ * This is the point where (0,0) coordinate of the world space is rendered.
+ */
+ public final Point2D centerCoordinate;
+
public final double zoom;
final BufferedImage bufferedImage;
public int frameNumber = 0;
public RenderingContext(final int width, final int height) {
this.width = width;
this.height = height;
-
- this.xCenter = width / 2;
- this.yCenter = height / 2;
-
+ this.centerCoordinate = new Point2D(width / 2d, height / 2d);
this.zoom = width / 3d;
bufferedImage = new BufferedImage(width, height, bufferedImageType);
package eu.svjatoslav.sixth.e3d.gui;
import eu.svjatoslav.sixth.e3d.geometry.Point3D;
-import eu.svjatoslav.sixth.e3d.math.GeometryCoordinate;
+import eu.svjatoslav.sixth.e3d.math.Vertex;
import eu.svjatoslav.sixth.e3d.math.TransformsPipeline;
public class UserRelativityTracker {
private final static int minimalSliceFactor = 5;
- public GeometryCoordinate center = new GeometryCoordinate();
- public GeometryCoordinate right;
- public GeometryCoordinate down;
+ public Vertex center = new Vertex();
+ public Vertex right;
+ public Vertex down;
public UserRelativityTracker() {
}
public void enableOrientationTracking() {
- right = new GeometryCoordinate(new Point3D(10, 0, 0));
- down = new GeometryCoordinate(new Point3D(0, 10, 0));
+ right = new Vertex(new Point3D(10, 0, 0));
+ down = new Vertex(new Point3D(0, 10, 0));
}
public double getAngleXY() {
+++ /dev/null
-/*
- * Sixth 3D engine. Author: Svjatoslav Agejenko.
- * This project is released under Creative Commons Zero (CC0) license.
- */
-package eu.svjatoslav.sixth.e3d.math;
-
-import eu.svjatoslav.sixth.e3d.geometry.Point2D;
-import eu.svjatoslav.sixth.e3d.geometry.Point3D;
-import eu.svjatoslav.sixth.e3d.gui.RenderingContext;
-
-/**
- * A point in 3D space with a transformed and on-screen coordinates.
- */
-public class GeometryCoordinate {
-
- /**
- * The original coordinate.
- */
- public Point3D coordinate;
-
- /**
- * The transformed coordinate.
- */
- public Point3D transformedCoordinate;
-
- /**
- * The on-screen coordinate.
- */
- public Point2D onScreenCoordinate;
-
- private int lastTransformedFrame;
-
- public GeometryCoordinate() {
- coordinate = new Point3D();
- transformedCoordinate = new Point3D();
- onScreenCoordinate = new Point2D();
- }
-
- public GeometryCoordinate(final Point3D location) {
- coordinate = location;
- transformedCoordinate = new Point3D();
- onScreenCoordinate = new Point2D();
- }
-
- /**
- * Transforms the coordinate.
- *
- * @param transforms
- * The transform pipe.
- * @param renderContext
- * The rendering context.
- */
- public void transform(final TransformsPipeline transforms,
- final RenderingContext renderContext) {
-
- if (lastTransformedFrame == renderContext.frameNumber)
- return;
-
- lastTransformedFrame = renderContext.frameNumber;
-
- transforms.transform(coordinate, transformedCoordinate);
-
- onScreenCoordinate.x = ((transformedCoordinate.x / transformedCoordinate.z) * renderContext.zoom)
- + renderContext.xCenter;
- onScreenCoordinate.y = ((transformedCoordinate.y / transformedCoordinate.z) * renderContext.zoom)
- + renderContext.yCenter;
- }
-}
--- /dev/null
+/*
+ * Sixth 3D engine. Author: Svjatoslav Agejenko.
+ * This project is released under Creative Commons Zero (CC0) license.
+ */
+package eu.svjatoslav.sixth.e3d.math;
+
+import eu.svjatoslav.sixth.e3d.geometry.Point2D;
+import eu.svjatoslav.sixth.e3d.geometry.Point3D;
+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.
+ */
+public class Vertex {
+
+ /**
+ * Vertex coordinate in 3D space.
+ */
+ public Point3D coordinate;
+
+ /**
+ * Vertex coordinate relative to the viewer after transformation.
+ */
+ public Point3D transformedCoordinate;
+
+ /**
+ * Vertex coordinate on screen after transformation.
+ */
+ public Point2D onScreenCoordinate;
+
+ private int lastTransformedFrame;
+
+ public Vertex() {
+ coordinate = new Point3D();
+ transformedCoordinate = new Point3D();
+ onScreenCoordinate = new Point2D();
+ }
+
+ public Vertex(final Point3D location) {
+ coordinate = location;
+ transformedCoordinate = new Point3D();
+ onScreenCoordinate = new Point2D();
+ }
+
+ /**
+ * Transforms the coordinate.
+ *
+ * @param transforms The transforms pipeline.
+ * @param renderContext The rendering context.
+ */
+ public void transform(final TransformsPipeline transforms,
+ final RenderingContext renderContext) {
+
+ if (lastTransformedFrame == renderContext.frameNumber)
+ return;
+
+ lastTransformedFrame = renderContext.frameNumber;
+
+ transforms.transform(coordinate, transformedCoordinate);
+
+ onScreenCoordinate.x = ((transformedCoordinate.x / transformedCoordinate.z) * renderContext.zoom);
+ onScreenCoordinate.y = ((transformedCoordinate.y / transformedCoordinate.z) * renderContext.zoom);
+ onScreenCoordinate.add(renderContext.centerCoordinate);
+ }
+}
import eu.svjatoslav.sixth.e3d.geometry.Point3D;
import eu.svjatoslav.sixth.e3d.gui.RenderingContext;
-import eu.svjatoslav.sixth.e3d.math.GeometryCoordinate;
+import eu.svjatoslav.sixth.e3d.math.Vertex;
import eu.svjatoslav.sixth.e3d.math.TransformsPipeline;
import eu.svjatoslav.sixth.e3d.renderer.raster.RenderAggregator;
private static final AtomicInteger lastShapeId = new AtomicInteger();
public final int shapeId;
- public final GeometryCoordinate[] coordinates;
+ public final Vertex[] coordinates;
public double onScreenZ;
public AbstractCoordinateShape(final int pointsCount) {
- coordinates = new GeometryCoordinate[pointsCount];
+ coordinates = new Vertex[pointsCount];
for (int i = 0; i < pointsCount; i++)
- coordinates[i] = new GeometryCoordinate();
+ coordinates[i] = new Vertex();
shapeId = lastShapeId.getAndIncrement();
}
public AbstractCoordinateShape(final Point3D... vertexes) {
- coordinates = new GeometryCoordinate[vertexes.length];
+ coordinates = new Vertex[vertexes.length];
for (int i = 0; i < vertexes.length; i++)
- coordinates[i] = new GeometryCoordinate(vertexes[i]);
+ coordinates[i] = new Vertex(vertexes[i]);
shapeId = lastShapeId.getAndIncrement();
}
double accumulatedZ = 0;
boolean paint = true;
- for (final GeometryCoordinate geometryPoint : coordinates) {
+ for (final Vertex geometryPoint : coordinates) {
geometryPoint.transform(transforms, renderingContext);
accumulatedZ += geometryPoint.transformedCoordinate.z;