001/*
002
003*/
004
005package renderer.models;
006import  renderer.scene.*;
007
008/**
009   Create a wireframe model of a cube aligned with
010   the x, y, and z axes and with one corner at the
011   origin.
012<p>
013   Here is a picture showing how the cube's eight vertices
014   are labeled.
015<pre>{@code
016                  v[4]
017                   +-----------------+ v[5]
018                  /|                /|
019                /  |              /  |
020              /    |            /    |
021            /      |          /      |
022      v[7] +-----------------+ v[6]  |
023           |       |         |       |               y
024           |       |         |       |               |
025           |       |         |       |               |
026           |  v[0] +---------|-------+ v[1]          |
027           |      /          |      /                |
028           |    /            |    /                  +----. x
029           |  /              |  /                   /
030           |/                |/                    /
031           +-----------------+                    /
032          v[3]              v[2]                 z
033}</pre>
034
035   @see Cube
036*/
037public class Box extends Model
038{
039   /**
040      Create a cube with all three sides of length 1.
041   */
042   public Box( )
043   {
044      this(1, 1, 1);
045   }
046
047
048   /**
049      Create a cube with the given side lengths.
050
051      @param xs  the size of the cube along the x-axis
052      @param ys  the size of the cube along the y-axis
053      @param zs  the size of the cube along the z-axis
054   */
055   public Box(double xs, double ys, double zs)
056   {
057      super();
058
059      // Create the cube's geometry.
060      Vertex[] v = new Vertex[8];
061      v[0] = new Vertex(0,    0,    0);      // four vertices around the bottom face
062      v[1] = new Vertex(0+xs, 0,    0);
063      v[2] = new Vertex(0+xs, 0,    0+zs);
064      v[3] = new Vertex(0,    0,    0+zs);
065      v[4] = new Vertex(0,    0+ys, 0);      // four vertices around the top face
066      v[5] = new Vertex(0+xs, 0+ys, 0);
067      v[6] = new Vertex(0+xs, 0+ys, 0+zs);
068      v[7] = new Vertex(0,    0+ys, 0+zs);
069
070      // Create 12 line segments
071      // bottom face
072      addLineSegment(new LineSegment(new Vertex(v[0]), new Vertex(v[1])));
073      addLineSegment(new LineSegment(new Vertex(v[1]), new Vertex(v[2])));
074      addLineSegment(new LineSegment(new Vertex(v[2]), new Vertex(v[3])));
075      addLineSegment(new LineSegment(new Vertex(v[3]), new Vertex(v[0])));
076      // top face
077      addLineSegment(new LineSegment(new Vertex(v[4]), new Vertex(v[5])));
078      addLineSegment(new LineSegment(new Vertex(v[5]), new Vertex(v[6])));
079      addLineSegment(new LineSegment(new Vertex(v[6]), new Vertex(v[7])));
080      addLineSegment(new LineSegment(new Vertex(v[7]), new Vertex(v[4])));
081      // back face
082      addLineSegment(new LineSegment(new Vertex(v[0]), new Vertex(v[4])));
083      addLineSegment(new LineSegment(new Vertex(v[1]), new Vertex(v[5])));
084      // front face
085      addLineSegment(new LineSegment(new Vertex(v[3]), new Vertex(v[7])));
086      addLineSegment(new LineSegment(new Vertex(v[2]), new Vertex(v[6])));
087   }
088}//Box