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 {@code Box} with all three sides of length 1. 041 */ 042 public Box( ) 043 { 044 this(1, 1, 1); 045 } 046 047 048 /** 049 Create a {@code Box} with the given side lengths. 050 051 @param xs the size of the {@code Box} along the x-axis 052 @param ys the size of the {@code Box} along the y-axis 053 @param zs the size of the {@code Box} along the z-axis 054 */ 055 public Box(double xs, double ys, double zs) 056 { 057 super(); 058 059 // Create the box's geometry. 060 Vertex v0 = new Vertex(0, 0, 0); // four vertices around the bottom face 061 Vertex v1 = new Vertex(0+xs, 0, 0); 062 Vertex v2 = new Vertex(0+xs, 0, 0+zs); 063 Vertex v3 = new Vertex(0, 0, 0+zs); 064 Vertex v4 = new Vertex(0, 0+ys, 0); // four vertices around the top face 065 Vertex v5 = new Vertex(0+xs, 0+ys, 0); 066 Vertex v6 = new Vertex(0+xs, 0+ys, 0+zs); 067 Vertex v7 = new Vertex(0, 0+ys, 0+zs); 068 069 // Create 12 line segments 070 // bottom face 071 addLineSegment(v0, v1); 072 addLineSegment(v1, v2); 073 addLineSegment(v2, v3); 074 addLineSegment(v3, v0); 075 // top face 076 addLineSegment(v4, v5); 077 addLineSegment(v5, v6); 078 addLineSegment(v6, v7); 079 addLineSegment(v7, v4); 080 // back face 081 addLineSegment(v0, v4); 082 addLineSegment(v1, v5); 083 // front face 084 addLineSegment(v3, v7); 085 addLineSegment(v2, v6); 086/* 087 // Or, we could build the box the 088 // following, more efficient, way. 089 addVertex(v0, v1, v2, v3, v4, v5, v6, v7); 090 // bottom face 091 addLineSegment(0, 1); 092 addLineSegment(1, 2); 093 addLineSegment(2, 3); 094 addLineSegment(3, 0); 095 // top face 096 addLineSegment(4, 5); 097 addLineSegment(5, 6); 098 addLineSegment(6, 7); 099 addLineSegment(7, 4); 100 // back face 101 addLineSegment(0, 4); 102 addLineSegment(1, 5); 103 // front face 104 addLineSegment(3, 7); 105 addLineSegment(2, 6); 106*/ 107 } 108}//Box