/Users/lyon/j4p/src/j3d/Axis.java

1    package j3d; 
2     
3    /* 
4     *      Axis.java 1.0 98/11/25 
5     * 
6     * Copyright (c) 1998 Sun Microsystems, Inc. All Rights Reserved. 
7     * 
8     * Sun grants you ("Licensee") a non-exclusive, royalty free, license to use, 
9     * modify and redistribute this software in source and binary code form, 
10    * provided that i) this copyright notice and license appear on all copies of 
11    * the software; and ii) Licensee does not utilize the software in a manner 
12    * which is disparaging to Sun. 
13    * 
14    * This software is provided "AS IS," without a warranty of any kind. ALL 
15    * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING ANY 
16    * IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR 
17    * NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN AND ITS LICENSORS SHALL NOT BE 
18    * LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING 
19    * OR DISTRIBUTING THE SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR ITS 
20    * LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT, 
21    * INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER 
22    * CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF 
23    * OR INABILITY TO USE SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE 
24    * POSSIBILITY OF SUCH DAMAGES. 
25    * 
26    * This software is not designed or intended for use in on-line control of 
27    * aircraft, air traffic, aircraft navigation or aircraft communications; or in 
28    * the design, construction, operation or maintenance of any nuclear 
29    * facility. Licensee represents and warrants that it will not use or 
30    * redistribute the Software for such purposes. 
31    */ 
32    
33   /* 
34    * Getting Started with the Java 3D API 
35    * written in Java 3D 
36    * 
37    * This program demonstrates: 
38    *   1. writing a visual object class 
39    *      In this program, Axis class defines a visual object 
40    *      This particular class extends Shape3D 
41    *      See the text for a discussion. 
42    *   2. Using LineArray to draw 3D lines. 
43    */ 
44    
45    
46   import javax.media.j3d.Geometry; 
47   import javax.media.j3d.GeometryArray; 
48   import javax.media.j3d.IndexedLineArray; 
49   import javax.media.j3d.Shape3D; 
50   import javax.vecmath.Point3f; 
51    
52    
53   public class Axis extends Shape3D { 
54    
55       //////////////////////////////////////////// 
56   // 
57   // create axis visual object 
58   // 
59       public Axis() { 
60    
61           this.setGeometry(createGeometry()); 
62    
63       } 
64    
65       private Geometry createGeometry() { 
66           // create line for X axis 
67           IndexedLineArray axisLines = new IndexedLineArray(18, GeometryArray.COORDINATES, 30); 
68    
69           axisLines.setCoordinate(0, new Point3f(-1.0f, 0.0f, 0.0f)); 
70           axisLines.setCoordinate(1, new Point3f(1.0f, 0.0f, 0.0f)); 
71           axisLines.setCoordinate(2, new Point3f(0.9f, 0.1f, 0.1f)); 
72           axisLines.setCoordinate(3, new Point3f(0.9f, -0.1f, 0.1f)); 
73           axisLines.setCoordinate(4, new Point3f(0.9f, 0.1f, -0.1f)); 
74           axisLines.setCoordinate(5, new Point3f(0.9f, -0.1f, -0.1f)); 
75           axisLines.setCoordinate(6, new Point3f(0.0f, -1.0f, 0.0f)); 
76           axisLines.setCoordinate(7, new Point3f(0.0f, 1.0f, 0.0f)); 
77           axisLines.setCoordinate(8, new Point3f(0.1f, 0.9f, 0.1f)); 
78           axisLines.setCoordinate(9, new Point3f(-0.1f, 0.9f, 0.1f)); 
79           axisLines.setCoordinate(10, new Point3f(0.1f, 0.9f, -0.1f)); 
80           axisLines.setCoordinate(11, new Point3f(-0.1f, 0.9f, -0.1f)); 
81           axisLines.setCoordinate(12, new Point3f(0.0f, 0.0f, -1.0f)); 
82           axisLines.setCoordinate(13, new Point3f(0.0f, 0.0f, 1.0f)); 
83           axisLines.setCoordinate(14, new Point3f(0.1f, 0.1f, 0.9f)); 
84           axisLines.setCoordinate(15, new Point3f(-0.1f, 0.1f, 0.9f)); 
85           axisLines.setCoordinate(16, new Point3f(0.1f, -0.1f, 0.9f)); 
86           axisLines.setCoordinate(17, new Point3f(-0.1f, -0.1f, 0.9f)); 
87    
88           axisLines.setCoordinateIndex(0, 0); 
89           axisLines.setCoordinateIndex(1, 1); 
90           axisLines.setCoordinateIndex(2, 2); 
91           axisLines.setCoordinateIndex(3, 1); 
92           axisLines.setCoordinateIndex(4, 3); 
93           axisLines.setCoordinateIndex(5, 1); 
94           axisLines.setCoordinateIndex(6, 4); 
95           axisLines.setCoordinateIndex(7, 1); 
96           axisLines.setCoordinateIndex(8, 5); 
97           axisLines.setCoordinateIndex(9, 1); 
98           axisLines.setCoordinateIndex(10, 6); 
99           axisLines.setCoordinateIndex(11, 7); 
100          axisLines.setCoordinateIndex(12, 8); 
101          axisLines.setCoordinateIndex(13, 7); 
102          axisLines.setCoordinateIndex(14, 9); 
103          axisLines.setCoordinateIndex(15, 7); 
104          axisLines.setCoordinateIndex(16, 10); 
105          axisLines.setCoordinateIndex(17, 7); 
106          axisLines.setCoordinateIndex(18, 11); 
107          axisLines.setCoordinateIndex(19, 7); 
108          axisLines.setCoordinateIndex(20, 12); 
109          axisLines.setCoordinateIndex(21, 13); 
110          axisLines.setCoordinateIndex(22, 14); 
111          axisLines.setCoordinateIndex(23, 13); 
112          axisLines.setCoordinateIndex(24, 15); 
113          axisLines.setCoordinateIndex(25, 13); 
114          axisLines.setCoordinateIndex(26, 16); 
115          axisLines.setCoordinateIndex(27, 13); 
116          axisLines.setCoordinateIndex(28, 17); 
117          axisLines.setCoordinateIndex(29, 13); 
118   
119          return axisLines; 
120   
121      } // end of Axis createGeometry() 
122   
123   
124  } // end of class Axis 
125