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 yz-plane.
014*/
015public class PanelYZ extends Model
016{
017   /**
018      Create a flat checkerboard panel in the yz-plane that runs
019      from -1 to 1 in the y-direction and -1 to 1 in the z-direction.
020   */
021   public PanelYZ( )
022   {
023      this(-1, 1, -1, 1);
024   }
025
026
027   /**
028      Create a flat checkerboard panel in the xz-plane with the given dimensions.
029
030      @param yMin  location of bottom edge
031      @param yMax  location of top edge
032      @param zMin  location of back edge
033      @param zMax  location of front edge
034   */
035   public PanelYZ(final int yMin, final int yMax,
036                  final int zMin, final int zMax)
037   {
038      this(yMin, yMax, zMin, zMax, 0.0);
039   }
040
041
042   /**
043      Create a flat checkerboard panel parallel to the yz-plane with the given dimensions.
044
045      @param yMin  location of bottom edge
046      @param yMax  location of top edge
047      @param zMin  location of back edge
048      @param zMax  location of front edge
049      @param x     x-plane that holds the panel
050   */
051   public PanelYZ(final int yMin, final int yMax,
052                  final int zMin, final int zMax,
053                  final double x)
054   {
055      super("PanelYZ");
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[(yMax-yMin)+1][(zMax-zMin)+1];
061
062      // Create the checkerboard of vertices.
063      int i = 0;
064      for (int y = yMin; y <= yMax; ++y)
065      {
066         for (int z = zMin; z <= zMax; ++z)
067         {
068            addVertex(new Vertex(x, y, z));
069            index[y-yMin][z-zMin] = i;
070            ++i;
071         }
072      }
073
074      // Create the line segments that run in the z-direction.
075      for (int y = 0; y <= yMax - yMin; ++y)
076      {
077         for (int z = 0; z < zMax - zMin; ++z)
078         {
079            addPrimitive(new LineSegment(index[y][z], index[y][z+1]));
080         }
081      }
082
083      // Create the line segments that run in the y-direction.
084      for (int z = 0; z <= zMax - zMin; ++z)
085      {
086         for (int y = 0; y < yMax - yMin; ++y)
087         {
088            addPrimitive(new LineSegment(index[y][z], index[y+1][z]));
089         }
090      }
091   }
092}//PanelYZ