*/
public Point2D onScreenCoordinate;
+
+ /**
+ * Coordinate within texture.
+ */
+ public Point2D textureCoordinate;
+
+
/**
* The frame number when this vertex was last transformed.
*/
private int lastTransformedFrame;
public Vertex() {
- coordinate = new Point3D();
- transformedCoordinate = new Point3D();
- onScreenCoordinate = new Point2D();
+ this(new Point3D());
}
public Vertex(final Point3D location) {
+ this(location, null);
+ }
+
+ public Vertex(final Point3D location, Point2D textureCoordinate) {
coordinate = location;
transformedCoordinate = new Point3D();
onScreenCoordinate = new Point2D();
+ this.textureCoordinate = textureCoordinate;
}
*/
package eu.svjatoslav.sixth.e3d.renderer.raster.shapes;
-import eu.svjatoslav.sixth.e3d.geometry.Point3D;
import eu.svjatoslav.sixth.e3d.gui.RenderingContext;
import eu.svjatoslav.sixth.e3d.math.TransformsStack;
import eu.svjatoslav.sixth.e3d.math.Vertex;
shapeId = lastShapeId.getAndIncrement();
}
- public AbstractCoordinateShape(final Point3D... vertexes) {
- coordinates = new Vertex[vertexes.length];
-
- for (int i = 0; i < vertexes.length; i++)
- coordinates[i] = new Vertex(vertexes[i]);
+ public AbstractCoordinateShape(final Vertex... vertexes) {
+ coordinates = vertexes;
shapeId = lastShapeId.getAndIncrement();
}
import eu.svjatoslav.sixth.e3d.geometry.Point2D;
import eu.svjatoslav.sixth.e3d.geometry.Point3D;
import eu.svjatoslav.sixth.e3d.gui.RenderingContext;
+import eu.svjatoslav.sixth.e3d.math.Vertex;
import eu.svjatoslav.sixth.e3d.renderer.raster.shapes.AbstractCoordinateShape;
import eu.svjatoslav.sixth.e3d.renderer.raster.texture.Texture;
import eu.svjatoslav.sixth.e3d.renderer.raster.texture.TextureBitmap;
public ForwardOrientedTexture(final Point3D point, final double scale,
final Texture texture) {
- super(point);
+ super(new Vertex(point));
this.texture = texture;
setScale(scale);
}
import eu.svjatoslav.sixth.e3d.geometry.Point2D;
import eu.svjatoslav.sixth.e3d.geometry.Point3D;
import eu.svjatoslav.sixth.e3d.gui.RenderingContext;
+import eu.svjatoslav.sixth.e3d.math.Vertex;
import eu.svjatoslav.sixth.e3d.renderer.raster.Color;
import eu.svjatoslav.sixth.e3d.renderer.raster.shapes.AbstractCoordinateShape;
public Line(final Point3D point1, final Point3D point2, final Color color,
final double width) {
- super(point1, point2);
+ super(
+ new Vertex(point1),
+ new Vertex(point2)
+ );
this.color = color;
this.width = width;
import eu.svjatoslav.sixth.e3d.geometry.Point3D;
import eu.svjatoslav.sixth.e3d.gui.RenderingContext;
import eu.svjatoslav.sixth.e3d.gui.humaninput.MouseInteractionController;
+import eu.svjatoslav.sixth.e3d.math.Vertex;
import eu.svjatoslav.sixth.e3d.renderer.raster.Color;
import eu.svjatoslav.sixth.e3d.renderer.raster.shapes.AbstractCoordinateShape;
public SolidPolygon(final Point3D point1, final Point3D point2,
final Point3D point3, final Color color) {
- super(point1, point2, point3);
+ super(
+ new Vertex(point1),
+ new Vertex(point2),
+ new Vertex(point3)
+ );
this.color = color;
}
final int width = x2 - x1;
int offset = ((y * renderBuffer.width) + x1) * 4;
- final byte[] offSreenBufferBytes = renderBuffer.pixels;
+ final byte[] offScreenBufferBytes = renderBuffer.pixels;
final int polygonAlpha = color.a;
final int b = color.b;
if (polygonAlpha == 255)
for (int i = 0; i < width; i++) {
- offSreenBufferBytes[offset] = (byte) 255;
+ offScreenBufferBytes[offset] = (byte) 255;
offset++;
- offSreenBufferBytes[offset] = (byte) b;
+ offScreenBufferBytes[offset] = (byte) b;
offset++;
- offSreenBufferBytes[offset] = (byte) g;
+ offScreenBufferBytes[offset] = (byte) g;
offset++;
- offSreenBufferBytes[offset] = (byte) r;
+ offScreenBufferBytes[offset] = (byte) r;
offset++;
}
else {
final int redWithAlpha = r * polygonAlpha;
for (int i = 0; i < width; i++) {
- offSreenBufferBytes[offset] = (byte) 255;
+ offScreenBufferBytes[offset] = (byte) 255;
offset++;
- offSreenBufferBytes[offset] = (byte) ((((offSreenBufferBytes[offset] & 0xff) * backgroundAlpha) + blueWithAlpha) / 256);
+ offScreenBufferBytes[offset] = (byte) ((((offScreenBufferBytes[offset] & 0xff) * backgroundAlpha) + blueWithAlpha) / 256);
offset++;
- offSreenBufferBytes[offset] = (byte) ((((offSreenBufferBytes[offset] & 0xff) * backgroundAlpha) + greenWithAlpha) / 256);
+ offScreenBufferBytes[offset] = (byte) ((((offScreenBufferBytes[offset] & 0xff) * backgroundAlpha) + greenWithAlpha) / 256);
offset++;
- offSreenBufferBytes[offset] = (byte) ((((offSreenBufferBytes[offset] & 0xff) * backgroundAlpha) + redWithAlpha) / 256);
+ offScreenBufferBytes[offset] = (byte) ((((offScreenBufferBytes[offset] & 0xff) * backgroundAlpha) + redWithAlpha) / 256);
offset++;
}
package eu.svjatoslav.sixth.e3d.renderer.raster.shapes.basic.texturedpolygon;
import eu.svjatoslav.sixth.e3d.geometry.Point2D;
-import eu.svjatoslav.sixth.e3d.geometry.Point3D;
import eu.svjatoslav.sixth.e3d.gui.RenderingContext;
+import eu.svjatoslav.sixth.e3d.math.Vertex;
import eu.svjatoslav.sixth.e3d.renderer.raster.shapes.AbstractCoordinateShape;
-import eu.svjatoslav.sixth.e3d.renderer.raster.slicer.PolygonCoordinate;
import eu.svjatoslav.sixth.e3d.renderer.raster.texture.Texture;
import eu.svjatoslav.sixth.e3d.renderer.raster.texture.TextureBitmap;
public class TexturedPolygon extends AbstractCoordinateShape {
public final Texture texture;
- /**
- * Polygon texture coordinates.
- */
- public Point2D texturePoint1, texturePoint2, texturePoint3;
/**
* If <code>true</code> then polygon borders will be drawn.
* It is used for debugging purposes.
*/
public boolean showBorders = false;
+
private double totalTextureDistance = -1;
- public TexturedPolygon(final Point3D p1, final Point3D p2,
- final Point3D p3, final Point2D tp1, final Point2D tp2,
- final Point2D tp3, final Texture texture) {
+ public TexturedPolygon(Vertex p1, Vertex p2, Vertex p3, final Texture texture) {
super(p1, p2, p3);
-
- texturePoint1 = tp1;
- texturePoint2 = tp2;
- texturePoint3 = tp3;
-
this.texture = texture;
}
- public TexturedPolygon(final PolygonCoordinate pc1,
- final PolygonCoordinate pc2, final PolygonCoordinate pc3,
- final Texture texture) {
-
- this(pc1.spaceCoordinate, pc2.spaceCoordinate, pc3.spaceCoordinate, pc1.textureCoordinate, pc2.textureCoordinate,
- pc3.textureCoordinate, texture);
- }
-
private void computeTotalTextureDistance() {
// compute total texture distance
- totalTextureDistance = texturePoint1.getDistanceTo(texturePoint2);
- totalTextureDistance += texturePoint1.getDistanceTo(texturePoint3);
- totalTextureDistance += texturePoint2.getDistanceTo(texturePoint3);
+ totalTextureDistance = coordinates[0].textureCoordinate.getDistanceTo(coordinates[1].textureCoordinate);
+ totalTextureDistance += coordinates[0].textureCoordinate.getDistanceTo(coordinates[2].textureCoordinate);
+ totalTextureDistance += coordinates[1].textureCoordinate.getDistanceTo(coordinates[2].textureCoordinate);
}
private void drawHorizontalLine(final PolygonBorderInterpolator line1,
new PolygonBorderInterpolator(), new PolygonBorderInterpolator(),
new PolygonBorderInterpolator()};
- is[0].setPoints(projectedPoint1, projectedPoint2, texturePoint1,
- texturePoint2);
- is[1].setPoints(projectedPoint1, projectedPoint3, texturePoint1,
- texturePoint3);
- is[2].setPoints(projectedPoint2, projectedPoint3, texturePoint2,
- texturePoint3);
+ is[0].setPoints(projectedPoint1, projectedPoint2,
+ coordinates[0].textureCoordinate,
+ coordinates[1].textureCoordinate);
+ is[1].setPoints(projectedPoint1, projectedPoint3,
+ coordinates[0].textureCoordinate,
+ coordinates[2].textureCoordinate);
+ is[2].setPoints(projectedPoint2, projectedPoint3,
+ coordinates[1].textureCoordinate,
+ coordinates[2].textureCoordinate);
sort(is);
import eu.svjatoslav.sixth.e3d.geometry.Point2D;
import eu.svjatoslav.sixth.e3d.geometry.Point3D;
import eu.svjatoslav.sixth.e3d.math.Transform;
+import eu.svjatoslav.sixth.e3d.math.Vertex;
import eu.svjatoslav.sixth.e3d.renderer.raster.shapes.basic.texturedpolygon.TexturedPolygon;
import eu.svjatoslav.sixth.e3d.renderer.raster.shapes.composite.base.AbstractCompositeShape;
import eu.svjatoslav.sixth.e3d.renderer.raster.texture.Texture;
textureBottomRight = new Point2D(textureWidth, textureHeight);
textureBottomLeft = new Point2D(0, textureHeight);
- final TexturedPolygon texturedPolygon1 = new TexturedPolygon(topLeft,
- topRight, bottomRight, textureTopLeft, textureTopRight,
- textureBottomRight, texture);
+
+
+
+ final TexturedPolygon texturedPolygon1 = new TexturedPolygon(
+ new Vertex(topLeft, textureTopLeft),
+ new Vertex(topRight, textureTopRight),
+ new Vertex(bottomRight, textureBottomRight), texture);
texturedPolygon1
.setMouseInteractionController(mouseInteractionController);
- final TexturedPolygon texturedPolygon2 = new TexturedPolygon(topLeft,
- bottomLeft, bottomRight, textureTopLeft, textureBottomLeft,
- textureBottomRight, texture);
+ final TexturedPolygon texturedPolygon2 = new TexturedPolygon(
+ new Vertex(topLeft, textureTopLeft),
+ new Vertex(bottomLeft, textureBottomLeft),
+ new Vertex(bottomRight, textureBottomRight), texture);
texturedPolygon2
.setMouseInteractionController(mouseInteractionController);
import eu.svjatoslav.sixth.e3d.geometry.Point2D;
import eu.svjatoslav.sixth.e3d.geometry.Point3D;
+import eu.svjatoslav.sixth.e3d.math.Vertex;
import java.util.Comparator;
public class BorderLine implements Comparator<BorderLine> {
public final int count;
- final PolygonCoordinate c1;
- final PolygonCoordinate c2;
+ final Vertex c1;
+ final Vertex c2;
- public BorderLine(final PolygonCoordinate c1, final PolygonCoordinate c2,
+ public BorderLine(final Vertex c1, final Vertex c2,
final int count) {
this.c1 = c1;
this.c2 = c2;
}
public double getLength() {
- return c1.spaceCoordinate.getDistanceTo(c2.spaceCoordinate);
+ return c1.coordinate.getDistanceTo(c2.coordinate);
}
- public PolygonCoordinate getMiddlePoint() {
- return new PolygonCoordinate(new Point3D().computeMiddlePoint(c1.spaceCoordinate,
- c2.spaceCoordinate), new Point2D().setToMiddle(c1.textureCoordinate,
- c2.textureCoordinate));
+ public Vertex getMiddlePoint() {
+ return new Vertex(
+ new Point3D().computeMiddlePoint(c1.coordinate, c2.coordinate),
+ new Point2D().setToMiddle(c1.textureCoordinate, c2.textureCoordinate));
}
}
+++ /dev/null
-/*
- * Sixth 3D engine. Author: Svjatoslav Agejenko.
- * This project is released under Creative Commons Zero (CC0) license.
- */
-package eu.svjatoslav.sixth.e3d.renderer.raster.slicer;
-
-import eu.svjatoslav.sixth.e3d.geometry.Point2D;
-import eu.svjatoslav.sixth.e3d.geometry.Point3D;
-
-/**
- * Polygon coordinate.
- * This class is used to store coordinates of a point in 3D space and its
- * texture coordinate.
- *
- * TODO: Refactor this class out of existence. Use Vertex instead. Texture coordinates should be moved to Vertex.
- */
-public class PolygonCoordinate {
-
- /**
- * Space coordinate of the point.
- */
- public Point3D spaceCoordinate;
-
- /**
- * Texture coordinate of the point.
- */
- public Point2D textureCoordinate;
-
- public PolygonCoordinate(final Point3D spaceCoordinate, final Point2D textureCoordinate) {
- this.spaceCoordinate = spaceCoordinate;
- this.textureCoordinate = textureCoordinate;
- }
-
-}
*/
package eu.svjatoslav.sixth.e3d.renderer.raster.slicer;
+import eu.svjatoslav.sixth.e3d.math.Vertex;
import eu.svjatoslav.sixth.e3d.renderer.raster.shapes.basic.texturedpolygon.TexturedPolygon;
import java.util.ArrayList;
this.maxDistance = maxDistance;
}
- private void considerSlicing(final PolygonCoordinate c1,
- final PolygonCoordinate c2,
- final PolygonCoordinate c3,
+ private void considerSlicing(final Vertex c1,
+ final Vertex c2,
+ final Vertex c3,
final TexturedPolygon originalPolygon) {
final BorderLine[] lines = new BorderLine[]{
return;
}
- final PolygonCoordinate middle = longestLine.getMiddlePoint();
+ final Vertex middle = longestLine.getMiddlePoint();
switch (longestLine.count) {
case 1:
public void slice(final TexturedPolygon originalPolygon) {
- final PolygonCoordinate pc1 = new PolygonCoordinate(
- originalPolygon.coordinates[0].coordinate,
- originalPolygon.texturePoint1);
-
- final PolygonCoordinate pc2 = new PolygonCoordinate(
- originalPolygon.coordinates[1].coordinate,
- originalPolygon.texturePoint2);
-
- final PolygonCoordinate pc3 = new PolygonCoordinate(
- originalPolygon.coordinates[2].coordinate,
- originalPolygon.texturePoint3);
-
- considerSlicing(pc1, pc2, pc3, originalPolygon);
+ considerSlicing(
+ originalPolygon.coordinates[0],
+ originalPolygon.coordinates[1],
+ originalPolygon.coordinates[2],
+ originalPolygon);
}
}