001/*
002 * Renderer Models. The MIT License.
003 * Copyright (c) 2022 rlkraft@pnw.edu
004 * See LICENSE for details.
005*/
006
007package renderer.models_L;
008
009import renderer.scene.*;
010import renderer.scene.primitives.*;
011
012/**
013   Create a flat wireframe checkerboard panel in the xy-plane.
014*/
015public class PanelXY extends Model
016{
017   /**
018      Create a flat checkerboard panel in the xy-plane that runs
019      from -1 to 1 in the x-direction and -1 to 1 in the y-direction.
020   */
021   public PanelXY( )
022   {
023      this(-1, 1, -1, 1);
024   }
025
026
027   /**
028      Create a flat checkerboard panel in the xy-plane with the given dimensions.
029
030      @param xMin  location of left edge
031      @param xMax  location of right edge
032      @param yMin  location of bottom edge
033      @param yMax  location of top edge
034   */
035   public PanelXY(final int xMin, final int xMax,
036                  final int yMin, final int yMax)
037   {
038      this(xMin, xMax, yMin, yMax, 0.0);
039   }
040
041
042   /**
043      Create a flat checkerboard panel parallel to the xy-plane with the given dimensions.
044
045      @param xMin  location of left edge
046      @param xMax  location of right edge
047      @param yMin  location of bottom edge
048      @param yMax  location of top edge
049      @param z     z-plane that holds the panel
050   */
051   public PanelXY(final int xMin, final int xMax,
052                  final int yMin, final int yMax,
053                  final double z)
054   {
055      super("PanelXY");
056
057      // Create the checkerboard panel's geometry.
058
059      // An array of indexes to be used to create line segments.
060      final int[][] index = new int[(xMax-xMin)+1][(yMax-yMin)+1];
061
062      // Create the checkerboard of vertices.
063      int i = 0;
064      for (int x = xMin; x <= xMax; ++x)
065      {
066         for (int y = yMin; y <= yMax; ++y)
067         {
068            addVertex(new Vertex(x, y, z));
069            index[x-xMin][y-yMin] = i;
070            ++i;
071         }
072      }
073
074      // Create the line segments that run in the y-direction.
075      for (int x = 0; x <= xMax - xMin; ++x)
076      {
077         for (int y = 0; y < yMax - yMin; ++y)
078         {
079            addPrimitive(new LineSegment(index[x][y], index[x][y+1]));
080         }
081      }
082
083      // Create the line segments that run in the x-direction.
084      for (int y = 0; y <= yMax - yMin; ++y)
085      {
086         for (int x = 0; x < xMax - xMin; ++x)
087         {
088            addPrimitive(new LineSegment(index[x][y], index[x+1][y]));
089         }
090      }
091   }
092}//PanelXY