X-Git-Url: http://www2.svjatoslav.eu/gitweb/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Feu%2Fsvjatoslav%2Fsixth%2Fe3d%2Frenderer%2Fraster%2Fshapes%2Fbasic%2Fline%2FLine.java;h=0ad06d8d702a80116288308e8e15627b0bb3fa33;hb=59980888bd6bba94f84e4f63ce67e5b624df8aea;hp=490e82578a73dff133d1851424fe2e9b5d81e0f7;hpb=6213716671ccab6b7256de41838e1f5401ce173c;p=sixth-3d.git diff --git a/src/main/java/eu/svjatoslav/sixth/e3d/renderer/raster/shapes/basic/line/Line.java b/src/main/java/eu/svjatoslav/sixth/e3d/renderer/raster/shapes/basic/line/Line.java index 490e825..0ad06d8 100644 --- a/src/main/java/eu/svjatoslav/sixth/e3d/renderer/raster/shapes/basic/line/Line.java +++ b/src/main/java/eu/svjatoslav/sixth/e3d/renderer/raster/shapes/basic/line/Line.java @@ -1,53 +1,63 @@ /* - * Sixth - System for data storage, computation, exploration and interaction. - * Copyright ©2012-2016, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 3 of the GNU Lesser General Public License - * or later as published by the Free Software Foundation. + * Sixth 3D engine. Author: Svjatoslav Agejenko. + * This project is released under Creative Commons Zero (CC0) license. */ - - package eu.svjatoslav.sixth.e3d.renderer.raster.shapes.basic.line; 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; +/** + * Line in 3D space. + * + * Line is represented by two points, width and color and width. + */ public class Line extends AbstractCoordinateShape { private static final double MINIMUM_WIDTH_THRESHOLD = 1; private static final double LINE_WIDTH_MULTIPLIER = 0.2d; + /** + * width of the line. + */ public final double width; - final LineInterpolator[] li = new LineInterpolator[4]; + final LineInterpolator[] lineInterpolators = new LineInterpolator[4]; + + /** + * Color of the line. + */ public Color color; public Line(final Line parentLine) { this(parentLine.coordinates[0].coordinate.clone(), - parentLine.coordinates[1].coordinate.clone(), new Color( - parentLine.color), parentLine.width); + parentLine.coordinates[1].coordinate.clone(), + new Color(parentLine.color), parentLine.width); } 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; - for (int i = 0; i < li.length; i++) - li[i] = new LineInterpolator(); + for (int i = 0; i < lineInterpolators.length; i++) + lineInterpolators[i] = new LineInterpolator(); } - public void drawHorizontalLine(final LineInterpolator line1, - final LineInterpolator line2, final int y, - final RenderingContext renderBuffer) { + private void drawHorizontalLine(final LineInterpolator line1, + final LineInterpolator line2, final int y, + final RenderingContext renderBuffer) { int x1 = line1.getX(y); int x2 = line2.getX(y); @@ -79,7 +89,7 @@ public class Line extends AbstractCoordinateShape { final int drawnWidth = x2 - x1; int offset = ((y * renderBuffer.width) + x1) * 4; - final byte[] offSreenBufferBytes = renderBuffer.bytes; + final byte[] offSreenBufferBytes = renderBuffer.pixels; final int lineAlpha = color.a; @@ -108,8 +118,8 @@ public class Line extends AbstractCoordinateShape { } - public void drawSinglePixelHorizontalLine(final RenderingContext buffer, - final int alpha) { + private void drawSinglePixelHorizontalLine(final RenderingContext buffer, + final int alpha) { final Point2D onScreenPoint1 = coordinates[0].onScreenCoordinate; final Point2D onScreenPoint2 = coordinates[1].onScreenCoordinate; @@ -135,7 +145,7 @@ public class Line extends AbstractCoordinateShape { if (lineWidth == 0) return; - final byte[] offSreenBufferBytes = buffer.bytes; + final byte[] offSreenBufferBytes = buffer.pixels; final int backgroundAlpha = 255 - alpha; final int blueWithAlpha = color.b * alpha; @@ -164,8 +174,8 @@ public class Line extends AbstractCoordinateShape { } - public void drawSinglePixelVerticalLine(final RenderingContext buffer, - final int alpha) { + private void drawSinglePixelVerticalLine(final RenderingContext buffer, + final int alpha) { final Point2D onScreenPoint1 = coordinates[0].onScreenCoordinate; final Point2D onScreenPoint2 = coordinates[1].onScreenCoordinate; @@ -191,11 +201,11 @@ public class Line extends AbstractCoordinateShape { if (lineHeight == 0) return; - final byte[] offSreenBufferBytes = buffer.bytes; + final byte[] offScreenBufferBytes = buffer.pixels; final int backgroundAlpha = 255 - alpha; final int blueWithAlpha = color.b * alpha; - final int greenWithAplha = color.g * alpha; + final int greenWithAlpha = color.g * alpha; final int redWithAlpha = color.r * alpha; for (int relativeY = 0; relativeY <= lineHeight; relativeY++) { @@ -207,22 +217,22 @@ public class Line extends AbstractCoordinateShape { if ((x >= 0) && (x < buffer.width)) { int ramOffset = ((y * buffer.width) + x) * 4; - offSreenBufferBytes[ramOffset] = (byte) 255; + offScreenBufferBytes[ramOffset] = (byte) 255; ramOffset++; - offSreenBufferBytes[ramOffset] = (byte) ((((offSreenBufferBytes[ramOffset] & 0xff) * backgroundAlpha) + blueWithAlpha) / 256); + offScreenBufferBytes[ramOffset] = (byte) ((((offScreenBufferBytes[ramOffset] & 0xff) * backgroundAlpha) + blueWithAlpha) / 256); ramOffset++; - offSreenBufferBytes[ramOffset] = (byte) ((((offSreenBufferBytes[ramOffset] & 0xff) * backgroundAlpha) + greenWithAplha) / 256); + offScreenBufferBytes[ramOffset] = (byte) ((((offScreenBufferBytes[ramOffset] & 0xff) * backgroundAlpha) + greenWithAlpha) / 256); ramOffset++; - offSreenBufferBytes[ramOffset] = (byte) ((((offSreenBufferBytes[ramOffset] & 0xff) * backgroundAlpha) + redWithAlpha) / 256); + offScreenBufferBytes[ramOffset] = (byte) ((((offScreenBufferBytes[ramOffset] & 0xff) * backgroundAlpha) + redWithAlpha) / 256); } } } } - public int getLineInterpolator(final int startPointer, final int y) { + private int getLineInterpolator(final int startPointer, final int y) { - for (int i = startPointer; i < li.length; i++) - if (li[i].containsY(y)) + for (int i = startPointer; i < lineInterpolators.length; i++) + if (lineInterpolators[i].containsY(y)) return i; return -1; } @@ -280,11 +290,11 @@ public class Line extends AbstractCoordinateShape { final double p2x2 = onScreenPoint2.x + xdec2; final double p2y2 = onScreenPoint2.y - yinc2; - li[0].setPoints(p1x1, p1y1, 1d, p2x1, p2y1, 1d); - li[1].setPoints(p1x2, p1y2, -1d, p2x2, p2y2, -1d); + lineInterpolators[0].setPoints(p1x1, p1y1, 1d, p2x1, p2y1, 1d); + lineInterpolators[1].setPoints(p1x2, p1y2, -1d, p2x2, p2y2, -1d); - li[2].setPoints(p1x1, p1y1, 1d, p1x2, p1y2, -1d); - li[3].setPoints(p2x1, p2y1, 1d, p2x2, p2y2, -1d); + lineInterpolators[2].setPoints(p1x1, p1y1, 1d, p1x2, p1y2, -1d); + lineInterpolators[3].setPoints(p2x1, p2y1, 1d, p2x2, p2y2, -1d); double ymin = p1y1; if (p1y2 < ymin) @@ -311,7 +321,7 @@ public class Line extends AbstractCoordinateShape { if (li1 != -1) { final int li2 = getLineInterpolator(li1 + 1, y); if (li2 != -1) - drawHorizontalLine(li[li1], li[li2], y, buffer); + drawHorizontalLine(lineInterpolators[li1], lineInterpolators[li2], y, buffer); } } }