/** Draw the current map and pieces. */
 @Override
 protected void paintComponentMiddleLayer(
     final Graphics2D g2d, final int topLeftX, final int topLeftY) {
   g2d.setColor(Color.lightGray);
   // g2d.fillRect(0, 0, getWidth(), getHeight());
   g2d.fillRect(0, 0, m_model.getMaxWidth(), m_model.getMaxHeight());
   g2d.setColor(Color.white);
   g2d.fillRect(
       m_mapData.getBevelWidth(),
       m_mapData.getBevelHeight(),
       m_model.getMaxWidth() - (m_mapData.getBevelWidth() * 2),
       m_model.getMaxHeight() - (m_mapData.getBevelHeight() * 2));
   for (final Map.Entry<Territory, Polygon> entry :
       m_mapData.getTerritoryPolygons(m_gameData.getMap()).entrySet()) {
     final Polygon p = entry.getValue();
     final Territory at = entry.getKey();
     final Color backgroundColor = Color.WHITE;
     g2d.setColor(Color.black);
     final Image image = m_images.get(at);
     if (image != null) {
       final Rectangle square = p.getBounds();
       g2d.drawImage(
           image, square.x, square.y, square.width, square.height, backgroundColor, null);
     }
     g2d.drawPolygon(p);
   }
 }
Example #2
0
 public void paint(Polygon shape, Graphics g, Color color, int side) {
   Rectangle r = shape.getBounds();
   int length = r.height * factor;
   int[] lengthPattern = {length, length};
   Color[] colorPattern = {color, null};
   paintStrokes(r, g, View.X_AXIS, lengthPattern, colorPattern);
 }
Example #3
0
  private void enlightTriangles(Wall wall, int width) {
    int brights[] = new int[4];
    for (int i = 0; i < 4; ++i) {
      brights[i] = calculateBrithness(wall.corners3D[i], wall.vector);
    }

    // podzial na 2 trojkaty
    int[][] triangleIndexes = {{0, 1, 2}, {0, 2, 3}};

    Polygon p = new Polygon();
    for (int[] corner : wall.corners2D) {
      p.addPoint(corner[0], corner[1]);
    }

    int minX = p.getBounds().x;
    int minY = p.getBounds().y;

    for (int[] indexes : triangleIndexes) {
      sortIndexes2D(indexes, wall.corners2D);

      int xoffset = wall.corners2D[indexes[0]][0] - minX;
      int yoffset = wall.corners2D[indexes[0]][1] - minY;
      int offset = xoffset + yoffset * width;
      if (shader == Shader.PHONG) {
        phongTriangle(wall, offset, width, indexes);
      } else {
        gouraudTriangle(wall, offset, width, indexes, brights);
      }
    }
  }
Example #4
0
 public void paint(Graphics g) {
   Polygon pt = at.transform(p);
   g.translate(xtranslate, ytranslate);
   g.drawPolygon(pt);
   for (int i = 0; i < pt.npoints; i++) g.drawString("p" + i, pt.xpoints[i], pt.ypoints[i]);
   Rectangle r = pt.getBounds();
   g.drawString("h=" + r.height + " w=" + r.width, r.height / 2, r.width / 2);
 }
Example #5
0
 public void paint(Polygon shape, Graphics g, Color color, int side) {
   Rectangle r = shape.getBounds();
   int length = Math.max(r.height / 2, 1);
   int[] lengthPattern = {length, length};
   Color[] colorPattern =
       ((side + 1) % 4 < 2) == (type == Value.GROOVE)
           ? new Color[] {getShadowColor(color), getLightColor(color)}
           : new Color[] {getLightColor(color), getShadowColor(color)};
   paintStrokes(r, g, View.Y_AXIS, lengthPattern, colorPattern);
 }
Example #6
0
  /**
   * Return a list of all objects in the selection, respecting the different modifier.
   *
   * @param alt Whether the alt key was pressed, which means select all objects that are touched,
   *     instead those which are completely covered.
   * @return The collection of selected objects.
   */
  public Collection<OsmPrimitive> getSelectedObjects(boolean alt) {

    Collection<OsmPrimitive> selection = new LinkedList<>();

    // whether user only clicked, not dragged.
    boolean clicked = false;
    Rectangle bounding = lasso.getBounds();
    if (bounding.height <= 2 && bounding.width <= 2) {
      clicked = true;
    }

    if (clicked) {
      Point center = new Point(lasso.xpoints[0], lasso.ypoints[0]);
      OsmPrimitive osm = nc.getNearestNodeOrWay(center, OsmPrimitive.isSelectablePredicate, false);
      if (osm != null) {
        selection.add(osm);
      }
    } else {
      // nodes
      for (Node n : nc.getCurrentDataSet().getNodes()) {
        if (n.isSelectable() && lasso.contains(nc.getPoint2D(n))) {
          selection.add(n);
        }
      }

      // ways
      for (Way w : nc.getCurrentDataSet().getWays()) {
        if (!w.isSelectable() || w.getNodesCount() == 0) {
          continue;
        }
        if (alt) {
          for (Node n : w.getNodes()) {
            if (!n.isIncomplete() && lasso.contains(nc.getPoint2D(n))) {
              selection.add(w);
              break;
            }
          }
        } else {
          boolean allIn = true;
          for (Node n : w.getNodes()) {
            if (!n.isIncomplete() && !lasso.contains(nc.getPoint(n))) {
              allIn = false;
              break;
            }
          }
          if (allIn) {
            selection.add(w);
          }
        }
      }
    }
    return selection;
  }
Example #7
0
 void finishPolygon() {
   if (xpf != null) {
     FloatPolygon poly = new FloatPolygon(xpf, ypf, nPoints);
     Rectangle r = poly.getBounds();
     x = r.x;
     y = r.y;
     width = r.width;
     height = r.height;
     bounds = poly.getFloatBounds();
     float xbase = (float) bounds.getX();
     float ybase = (float) bounds.getY();
     for (int i = 0; i < nPoints; i++) {
       xpf[i] -= xbase;
       ypf[i] -= ybase;
     }
   } else {
     Polygon poly = new Polygon(xp, yp, nPoints);
     Rectangle r = poly.getBounds();
     x = r.x;
     y = r.y;
     width = r.width;
     height = r.height;
     for (int i = 0; i < nPoints; i++) {
       xp[i] = xp[i] - x;
       yp[i] = yp[i] - y;
     }
     bounds = null;
   }
   if (nPoints < 2
       || (!(type == FREELINE || type == POLYLINE || type == ANGLE)
           && (nPoints < 3 || width == 0 || height == 0))) {
     if (imp != null) imp.deleteRoi();
     if (type != POINT) return;
   }
   state = NORMAL;
   if (imp != null && !(type == TRACED_ROI)) imp.draw(x - 5, y - 5, width + 10, height + 10);
   oldX = x;
   oldY = y;
   oldWidth = width;
   oldHeight = height;
   if (Recorder.record
       && userCreated
       && (type == POLYGON
           || type == POLYLINE
           || type == ANGLE
           || (type == POINT && Recorder.scriptMode() && nPoints == 3)))
     Recorder.recordRoi(getPolygon(), type);
   if (type != POINT) modifyRoi();
   LineWidthAdjuster.update();
 }
Example #8
0
  public void updateLine() {
    PBounds sourceBounds = source.getBounds();
    PBounds targetBounds = target.getBounds();
    double x1, y1, x2, y2;

    if (Math.abs(sourceBounds.getCenterX() - targetBounds.getCenterX()) < 1.0) {
      // source and target on the same vertical position
      x1 = x2 = sourceBounds.getCenterX();
      y1 = sourceBounds.getMaxY();
      y2 = targetBounds.getMinY();
      y2 -= STROKE_ARROW.getLineWidth();

      if (y1 > y2) {
        y1 = sourceBounds.getMinY();
        y2 = targetBounds.getMaxY();
        y2 += STROKE_ARROW.getLineWidth();
      }
    } else {
      // source and target in different vertical positions
      x1 = sourceBounds.getMaxX();
      y1 = sourceBounds.getCenterY();
      x2 = targetBounds.getMinX();
      y2 = targetBounds.getCenterY();
      x2 -= STROKE_ARROW.getLineWidth();

      if (x1 > x2) {
        x1 = sourceBounds.getMinX();
        x2 = targetBounds.getMaxX();
        x2 += STROKE_ARROW.getLineWidth();
      }

      // move the ends a bit if we are not in the same vertical position
      int ydi = (int) Math.round((y2 - y1) / (MmfNode.HEIGHT + MmfNode.PADDING_HEIGHT));
      double yd = (ydi < 0 ? -1 : 1) * END_DELTA[Math.min(Math.abs(ydi), END_DELTA.length - 1)];
      y1 += yd;
      y2 -= yd;
    }

    line = new Line2D.Double(x1, y1, x2, y2);
    arrowHead = getArrowHead((int) x1, (int) y1, (int) x2, (int) y2);

    Rectangle bounds = line.getBounds();
    bounds.add(arrowHead.getBounds());
    setBounds(bounds);
  }
Example #9
0
 public boolean clickTile() {
   if (isOnScreen()) {
     Polygon p = Calculations.getTilePolygon(getLocationX(), getLocationY());
     Rectangle r = p.getBounds();
     Point pt =
         new Point(new Random().nextInt(r.width) + r.x, new Random().nextInt(r.height) + r.y);
     if (pt.x > 0 && pt.x < 515 && pt.y > 54 && pt.y < 388) {
       Mouse.move(pt);
       try {
         Thread.sleep(100);
       } catch (Exception e) {
       }
       Mouse.click();
       return true;
     }
   }
   return false;
 }
Example #10
0
  /** Check the state of the keys and buttons and set the selection accordingly. */
  @Override
  public void mouseReleased(MouseEvent e) {
    if (e.getButton() != MouseEvent.BUTTON1) return;
    if (mousePos == null || mousePosStart == null) return; // injected release from outside
    // disable the selection rect
    Rectangle r;
    if (!lassoMode) {
      nc.requestClearRect();
      r = getSelectionRectangle();

      lasso = rectToPolygon(r);
    } else {
      nc.requestClearPoly();
      lasso.addPoint(mousePos.x, mousePos.y);
      r = lasso.getBounds();
    }
    mousePosStart = null;
    mousePos = null;

    if ((e.getModifiersEx() & MouseEvent.BUTTON3_DOWN_MASK) == 0) {
      selectionEndedListener.selectionEnded(r, e);
    }
  }
Example #11
0
  /**
   * Applies the band select operation to a grid coverage.
   *
   * @param cropEnvelope the target envelope; always not null
   * @param cropROI the target ROI shape; nullable
   * @param roiTolerance; as read from op's params
   * @param sourceCoverage is the source {@link GridCoverage2D} that we want to crop.
   * @param hints A set of rendering hints, or {@code null} if none.
   * @param sourceGridToWorldTransform is the 2d grid-to-world transform for the source coverage.
   * @return The result as a grid coverage.
   */
  private static GridCoverage2D buildResult(
      final GeneralEnvelope cropEnvelope,
      final Geometry cropROI,
      final double roiTolerance,
      final boolean forceMosaic,
      final Hints hints,
      final GridCoverage2D sourceCoverage,
      final AffineTransform sourceGridToWorldTransform) {

    //
    // Getting the source coverage and its child geolocation objects
    //
    final RenderedImage sourceImage = sourceCoverage.getRenderedImage();
    final GridGeometry2D sourceGridGeometry = ((GridGeometry2D) sourceCoverage.getGridGeometry());
    final GridEnvelope2D sourceGridRange = sourceGridGeometry.getGridRange2D();

    //
    // Now we try to understand if we have a simple scale and translate or a
    // more elaborated grid-to-world transformation n which case a simple
    // crop could not be enough, but we may need a more elaborated chain of
    // operation in order to do a good job. As an instance if we
    // have a rotation which is not multiple of PI/2 we have to use
    // the mosaic with a ROI
    //
    final boolean isSimpleTransform =
        CoverageUtilities.isSimpleGridToWorldTransform(sourceGridToWorldTransform, EPS);

    // Do we need to explode the Palette to RGB(A)?
    //
    int actionTaken = 0;

    // //
    //
    // Layout
    //
    // //
    final RenderingHints targetHints = new RenderingHints(null);
    if (hints != null) targetHints.add(hints);
    final ImageLayout layout = initLayout(sourceImage, targetHints);
    targetHints.put(JAI.KEY_IMAGE_LAYOUT, layout);

    //
    // prepare the processor to use for this operation
    //
    final JAI processor = OperationJAI.getJAI(targetHints);
    final boolean useProvidedProcessor = !processor.equals(JAI.getDefaultInstance());

    try {

      if (cropROI != null) {
        // replace the cropEnvelope with the envelope of the intersection
        // of the ROI and the cropEnvelope.
        // Remember that envelope(intersection(roi,cropEnvelope)) != intersection(cropEnvelope,
        // envelope(roi))
        final Polygon modelSpaceROI = FeatureUtilities.getPolygon(cropEnvelope, GFACTORY);
        Geometry intersection = IntersectUtils.intersection(cropROI, modelSpaceROI);
        Envelope2D e2d =
            JTS.getEnvelope2D(
                intersection.getEnvelopeInternal(), cropEnvelope.getCoordinateReferenceSystem());
        GeneralEnvelope ge = new GeneralEnvelope((org.opengis.geometry.Envelope) e2d);
        cropEnvelope.setEnvelope(ge);
      }

      // //
      //
      // Build the new range by keeping into
      // account translation of grid geometry constructor for respecting
      // OGC PIXEL-IS-CENTER ImageDatum assumption.
      //
      // //
      final AffineTransform sourceWorldToGridTransform = sourceGridToWorldTransform.createInverse();

      // //
      //
      // finalRasterArea will hold the smallest rectangular integer raster area that contains the
      // floating point raster
      // area which we obtain when applying the world-to-grid transform to the cropEnvelope. Note
      // that we need to intersect
      // such an area with the area covered by the source coverage in order to be sure we do not try
      // to crop outside the
      // bounds of the source raster.
      //
      // //
      final Rectangle2D finalRasterAreaDouble =
          XAffineTransform.transform(
              sourceWorldToGridTransform, cropEnvelope.toRectangle2D(), null);
      final Rectangle finalRasterArea = finalRasterAreaDouble.getBounds();

      // intersection with the original range in order to not try to crop outside the image bounds
      Rectangle.intersect(finalRasterArea, sourceGridRange, finalRasterArea);
      if (finalRasterArea.isEmpty())
        throw new CannotCropException(Errors.format(ErrorKeys.CANT_CROP));

      // //
      //
      // It is worth to point out that doing a crop the G2W transform
      // should not change while the envelope might change as
      // a consequence of the rounding of the underlying image datum
      // which uses integer factors or in case the G2W is very
      // complex. Note that we will always strive to
      // conserve the original grid-to-world transform.
      //
      // //

      // we do not have to crop in this case (should not really happen at
      // this time)
      if (finalRasterArea.equals(sourceGridRange) && isSimpleTransform && cropROI == null)
        return sourceCoverage;

      // //
      //
      // if I get here I have something to crop
      // using the world-to-grid transform for going from envelope to the
      // new grid range.
      //
      // //
      final double minX = finalRasterArea.getMinX();
      final double minY = finalRasterArea.getMinY();
      final double width = finalRasterArea.getWidth();
      final double height = finalRasterArea.getHeight();

      // //
      //
      // Check if we need to use mosaic or crop
      //
      // //
      final PlanarImage croppedImage;
      final ParameterBlock pbj = new ParameterBlock();
      pbj.addSource(sourceImage);
      java.awt.Polygon rasterSpaceROI = null;
      String operatioName = null;
      if (!isSimpleTransform || cropROI != null) {
        // /////////////////////////////////////////////////////////////////////
        //
        // We don't have a simple scale and translate transform, JAI
        // crop MAY NOT suffice. Let's decide whether or not we'll use
        // the Mosaic.
        //
        // /////////////////////////////////////////////////////////////////////
        Polygon modelSpaceROI = FeatureUtilities.getPolygon(cropEnvelope, GFACTORY);

        // //
        //
        // Now convert this polygon back into a shape for the source
        // raster space.
        //
        // //
        final List<Point2D> points = new ArrayList<Point2D>(5);
        rasterSpaceROI =
            FeatureUtilities.convertPolygonToPointArray(
                modelSpaceROI, ProjectiveTransform.create(sourceWorldToGridTransform), points);
        if (rasterSpaceROI == null || rasterSpaceROI.getBounds().isEmpty())
          if (finalRasterArea.isEmpty())
            throw new CannotCropException(Errors.format(ErrorKeys.CANT_CROP));
        final boolean doMosaic =
            forceMosaic
                ? true
                : decideJAIOperation(roiTolerance, rasterSpaceROI.getBounds2D(), points);
        if (doMosaic || cropROI != null) {
          // prepare the params for the mosaic
          final ROI[] roiarr;
          try {
            if (cropROI != null) {
              final LiteShape2 cropRoiLS2 =
                  new LiteShape2(
                      cropROI, ProjectiveTransform.create(sourceWorldToGridTransform), null, false);
              ROI cropRS = new ROIShape(cropRoiLS2);
              Rectangle2D rt = cropRoiLS2.getBounds2D();
              if (!hasIntegerBounds(rt)) {
                // Approximate Geometry
                Geometry geo = (Geometry) cropRoiLS2.getGeometry().clone();
                transformGeometry(geo);
                cropRS = new ROIShape(new LiteShape2(geo, null, null, false));
              }
              roiarr = new ROI[] {cropRS};
            } else {
              final ROIShape roi = new ROIShape(rasterSpaceROI);
              roiarr = new ROI[] {roi};
            }
          } catch (FactoryException ex) {
            throw new CannotCropException(Errors.format(ErrorKeys.CANT_CROP), ex);
          }
          pbj.add(MosaicDescriptor.MOSAIC_TYPE_OVERLAY);
          pbj.add(null);
          pbj.add(roiarr);
          pbj.add(null);
          pbj.add(CoverageUtilities.getBackgroundValues(sourceCoverage));

          // prepare the final layout
          final Rectangle bounds = rasterSpaceROI.getBounds2D().getBounds();
          Rectangle.intersect(bounds, sourceGridRange, bounds);
          if (bounds.isEmpty()) throw new CannotCropException(Errors.format(ErrorKeys.CANT_CROP));

          // we do not have to crop in this case (should not really happen at
          // this time)
          if (!doMosaic && bounds.getBounds().equals(sourceGridRange) && isSimpleTransform)
            return sourceCoverage;

          // nice trick, we use the layout to do the actual crop
          final Rectangle boundsInt = bounds.getBounds();
          layout.setMinX(boundsInt.x);
          layout.setWidth(boundsInt.width);
          layout.setMinY(boundsInt.y);
          layout.setHeight(boundsInt.height);
          operatioName = "Mosaic";
        }
      }

      // do we still have to set the operation name? If so that means we have to go for crop.
      if (operatioName == null) {
        // executing the crop
        pbj.add((float) minX);
        pbj.add((float) minY);
        pbj.add((float) width);
        pbj.add((float) height);
        operatioName = "GTCrop";
      }
      // //
      //
      // Apply operation
      //
      // //
      if (!useProvidedProcessor) {
        croppedImage = JAI.create(operatioName, pbj, targetHints);
      } else {
        croppedImage = processor.createNS(operatioName, pbj, targetHints);
      }

      // conserve the input grid to world transformation
      Map sourceProperties = sourceCoverage.getProperties();
      Map properties = null;
      if (sourceProperties != null && !sourceProperties.isEmpty()) {
        properties = new HashMap(sourceProperties);
      }
      if (rasterSpaceROI != null) {
        if (properties != null) {
          properties.put("GC_ROI", rasterSpaceROI);
        } else {
          properties = Collections.singletonMap("GC_ROI", rasterSpaceROI);
        }
      }

      return new GridCoverageFactory(hints)
          .create(
              sourceCoverage.getName(),
              croppedImage,
              new GridGeometry2D(
                  new GridEnvelope2D(croppedImage.getBounds()),
                  sourceGridGeometry.getGridToCRS2D(PixelOrientation.CENTER),
                  sourceCoverage.getCoordinateReferenceSystem()),
              (GridSampleDimension[])
                  (actionTaken == 1 ? null : sourceCoverage.getSampleDimensions().clone()),
              new GridCoverage[] {sourceCoverage},
              properties);

    } catch (TransformException e) {
      throw new CannotCropException(Errors.format(ErrorKeys.CANT_CROP), e);
    } catch (NoninvertibleTransformException e) {
      throw new CannotCropException(Errors.format(ErrorKeys.CANT_CROP), e);
    }
  }
Example #12
0
  public Rectangle realBounds(Polygon[] polys) {
    int maxheight = -9999999;
    int minheight = 9999999;
    int maxwidth = -9999999;
    int minwidth = 9999999;
    int maxX = -9999999;
    int minX = 9999999;
    int maxY = -9999999;
    int minY = 9999999;

    for (Polygon p : polys) {
      if (p.getBounds().height > maxheight) {
        maxheight = p.getBounds().height;
      } else if (p.getBounds().height < minheight) {
        minheight = p.getBounds().height;
      }
      if (p.getBounds().width > maxwidth) {
        maxwidth = p.getBounds().width;
      } else if (p.getBounds().width < minwidth) {
        minwidth = p.getBounds().width;
      }
      if (p.getBounds().x > maxX) {
        maxX = p.getBounds().x;
      } else if (p.getBounds().x < minX) {
        minX = p.getBounds().x;
      }
      if (p.getBounds().y > maxY) {
        maxY = p.getBounds().y;
      } else if (p.getBounds().y < minY) {
        minY = p.getBounds().y;
      }
    }
    return new Rectangle(
        ((maxX + minX) / 2),
        ((maxY + minY) / 2),
        ((maxwidth + minwidth) / 2),
        ((maxheight + minheight) / 2));
  }
Example #13
0
  /**
   * Calculates an approximation of the tiles that are making up the building. Sets these tiles
   * values to the corresponding collision values.
   *
   * @param collsionMatrix The collision matrix that is modified
   */
  public void calculateCollision(int[][] collisionMatrix) {
    Rectangle rect = p.getBounds();
    int maxX, maxY, minX, minY;
    maxX = (int) rect.getMaxX();
    maxY = (int) rect.getMaxY();
    minX = (int) rect.getMinX();
    minY = (int) rect.getMinY();

    // If building is a building used for education - find the center of it and add an EDUCATION
    // node
    if (tag.equals(OSM_Reader.EDUCATION)) {
      createEducationCenter(collisionMatrix, (maxX - minX) / 2 + minX, (maxY - minY) / 2 + minY);
    }

    double distance;
    double[] minDistances = new double[targetsInside.size()];
    Arrays.fill(minDistances, Double.MAX_VALUE);
    LinkedList<int[]> closestNodes = new LinkedList<int[]>();
    // Initiate vector with edge points (closest to respective target point)
    for (int i = 0; i < targetsInside.size(); i++) {
      int[] temp = new int[2];
      closestNodes.add(temp);
    }

    // Go through each line of the building
    for (int y = minY; y <= maxY; y++) {
      // Are we inside of map bounds (y)
      if (Math.round(OSM_Reader.scaleCollision * y) >= 0
          && Math.round(OSM_Reader.scaleCollision * y) < collisionMatrix.length) {
        for (int x = minX; x <= maxX; x++) {
          // Are we inside of map bounds (x)
          if (Math.round(OSM_Reader.scaleCollision * x) >= 0
              && Math.round(OSM_Reader.scaleCollision * x) < collisionMatrix.length) {
            // Is this point inside of the building? (and has no previous cost value)
            if (p.contains(x, y)
                && collisionMatrix[Math.round(OSM_Reader.scaleCollision * x)][
                        Math.round(OSM_Reader.scaleCollision * y)]
                    == 0) {
              collisionMatrix[Math.round(OSM_Reader.scaleCollision * x)][
                      Math.round(OSM_Reader.scaleCollision * y)] =
                  cost;

              // On the edge of the building
              if (!p.contains(x - 1, y) || !p.contains(x + 1, y)) {
                Node node;
                // Go through all targets that are inside of the building
                for (int i = 0; i < targetsInside.size(); i++) {
                  node = targetsInside.get(i);

                  // Calculate the Euclidean distance from target to edge
                  distance =
                      Math.sqrt(Math.pow(node.getXPos() - x, 2) + Math.pow(node.getYPos() - y, 2));

                  // Check if target is closer to this edge point
                  if (minDistances[i] > distance) {
                    minDistances[i] = distance;
                    closestNodes.get(i)[0] = x;
                    closestNodes.get(i)[1] = y;
                  }
                }
              }
            }
          }
        }
      }
    }
    createEntranceWays(collisionMatrix, closestNodes);
  }
 public Rectangle getBounds() {
   return areaShape.getBounds();
 }
Example #15
0
  /**
   * Niedokonczona implementacja usredniania Gourouda dla calego czworokata
   *
   * @param wall
   * @param width
   */
  private void gouraudRectangle(Wall wall, int width) {

    int brights[] = new int[4];
    for (int i = 0; i < 4; ++i) {
      brights[i] = calculateBrithness(wall.corners3D[i], wall.vector);
    }

    int[] indexes = {0, 1, 2, 3};
    sortIndexes2D(indexes, wall.corners2D);

    Polygon p = new Polygon();
    for (int[] corner : wall.corners2D) {
      p.addPoint(corner[0], corner[1]);
    }

    int xoffset = wall.corners2D[indexes[0]][0] - p.getBounds().x;
    int yoffset = wall.corners2D[indexes[0]][1] - p.getBounds().y;
    int offset = xoffset + (yoffset) * width;

    int diffY_0_1 = diffY(1, 0, indexes, wall.corners2D);
    int diffY_1_2 = diffY(2, 1, indexes, wall.corners2D);
    int diffY_2_3 = diffY(3, 2, indexes, wall.corners2D);

    double stepX_0_1 = stepX(1, 0, indexes, wall.corners2D);
    double stepX_1_3 = stepX(3, 1, indexes, wall.corners2D);
    double stepX_0_2 = stepX(2, 0, indexes, wall.corners2D);
    double stepX_2_3 = stepX(3, 2, indexes, wall.corners2D);

    double stepB_0_1 = stepB(1, 0, indexes, brights, wall.corners2D);
    double stepB_1_3 = stepB(3, 1, indexes, brights, wall.corners2D);
    double stepB_0_2 = stepB(2, 0, indexes, brights, wall.corners2D);
    double stepB_2_3 = stepB(3, 2, indexes, brights, wall.corners2D);

    double x1 = 0;
    double x2 = 0;
    double b1;
    double b2;

    b1 = b2 = brights[indexes[0]];

    int y;
    for (y = 0; y < diffY_0_1; ++y) {

      gradientLine(wall.buff, (int) (offset + x1), (int) (x2 - x1 + 0.5), (int) b1, (int) b2);

      x1 += stepX_0_2;
      b1 += stepB_0_2;

      x2 += stepX_0_1;
      b2 += stepB_0_1;

      offset += width;
    }
    if (diffY_0_1 == 0) {
      x2 = width;
    }
    for (y = 0; y < diffY_1_2; ++y) {

      gradientLine(wall.buff, (int) (offset + x1), (int) (x2 - x1 + 0.5), (int) b1, (int) b2);

      x1 += stepX_0_2;
      b1 += stepB_0_2;

      x2 += stepX_1_3;
      b2 += stepB_1_3;

      offset += width;
    }
    for (y = 0; y < diffY_2_3; ++y) {

      gradientLine(wall.buff, (int) (offset + x1), (int) (x2 - x1 + 0.5), (int) b1, (int) b2);

      x1 += stepX_2_3;
      b1 += stepB_2_3;

      x2 += stepX_1_3;
      b2 += stepB_1_3;

      offset += width;
    }
  }
Example #16
0
 private double polygonSize(Polygon polygon) {
   return Math.max(polygon.getBounds().getHeight(), polygon.getBounds().getWidth());
 }