001/* 002 003*/ 004 005package renderer.models; 006import renderer.scene.*; 007 008/** 009 Create a wireframe model of a cube with its center 010 at the origin, having edge length 2, and with its 011 vertices at {@code (±1, ±1, ±1)}. 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 Tetrahedron 036 @see Octahedron 037 @see Icosahedron 038 @see Dodecahedron 039*/ 040public class Cube extends Model 041{ 042 /** 043 Create a cube with its center at the origin, having edge 044 length 2, and with its vertices at {@code (±1, ±1, ±1)}. 045 */ 046 public Cube( ) 047 { 048 super(); 049 050 // Create the cube's geometry. 051 Vertex v0 = new Vertex(-1, -1, -1); // four vertices around the bottom face 052 Vertex v1 = new Vertex( 1, -1, -1); 053 Vertex v2 = new Vertex( 1, -1, 1); 054 Vertex v3 = new Vertex(-1, -1, 1); 055 Vertex v4 = new Vertex(-1, 1, -1); // four vertices around the top face 056 Vertex v5 = new Vertex( 1, 1, -1); 057 Vertex v6 = new Vertex( 1, 1, 1); 058 Vertex v7 = new Vertex(-1, 1, 1); 059 060 // Create 12 line segments 061 // bottom face 062 addLineSegment(v0, v1); 063 addLineSegment(v1, v2); 064 addLineSegment(v2, v3); 065 addLineSegment(v3, v0); 066 // top face 067 addLineSegment(v4, v5); 068 addLineSegment(v5, v6); 069 addLineSegment(v6, v7); 070 addLineSegment(v7, v4); 071 // back face 072 addLineSegment(v0, v4); 073 addLineSegment(v1, v5); 074 // front face 075 addLineSegment(v3, v7); 076 addLineSegment(v2, v6); 077 } 078}//Cube