Refactoring to remove unneeded complexity.
[sixth-3d.git] / src / main / java / eu / svjatoslav / sixth / e3d / renderer / raster / shapes / basic / solidpolygon / SolidPolygon.java
index 992a406..e941408 100644 (file)
@@ -1,32 +1,36 @@
 /*
- * Sixth 3D engine. Copyright ©2012-2018, 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.solidpolygon;
 
 import eu.svjatoslav.sixth.e3d.geometry.Point2D;
 import eu.svjatoslav.sixth.e3d.geometry.Point3D;
-import eu.svjatoslav.sixth.e3d.geometry.Polygon;
 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;
 
+import static eu.svjatoslav.sixth.e3d.geometry.Polygon.pointWithinPolygon;
+
+/**
+ * polygon with solid color.
+ */
 public class SolidPolygon extends AbstractCoordinateShape {
 
-    final static LineInterpolator polygonBoundary1 = new LineInterpolator();
-    final static LineInterpolator polygonBoundary2 = new LineInterpolator();
-    final static LineInterpolator polygonBoundary3 = new LineInterpolator();
+    private final static LineInterpolator polygonBoundary1 = new LineInterpolator();
+    private final static LineInterpolator polygonBoundary2 = new LineInterpolator();
+    private final static LineInterpolator polygonBoundary3 = new LineInterpolator();
     private Color color;
 
     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;
     }
 
@@ -52,7 +56,7 @@ public class SolidPolygon extends AbstractCoordinateShape {
         final int width = x2 - x1;
 
         int offset = ((y * renderBuffer.width) + x1) * 4;
-        final byte[] offSreenBufferBytes = renderBuffer.bytes;
+        final byte[] offScreenBufferBytes = renderBuffer.pixels;
 
         final int polygonAlpha = color.a;
         final int b = color.b;
@@ -61,13 +65,13 @@ public class SolidPolygon extends AbstractCoordinateShape {
 
         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 {
@@ -78,13 +82,13 @@ public class SolidPolygon extends AbstractCoordinateShape {
             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++;
             }
 
@@ -103,10 +107,10 @@ public class SolidPolygon extends AbstractCoordinateShape {
         onScreenPoint3.roundToInteger();
 
         if (mouseInteractionController != null)
-            if (context.mouseClick != null)
-                if (Polygon.pointWithinPolygon(context.mouseClick.coordinate,
+            if (context.getMouseEvent() != null)
+                if (pointWithinPolygon(context.getMouseEvent().coordinate,
                         onScreenPoint1, onScreenPoint2, onScreenPoint3))
-                    context.clickedItem = mouseInteractionController;
+                    context.setCurrentObjectUnderMouseCursor(mouseInteractionController);
 
         if (color.isTransparent())
             return;