View Javadoc

1   package com.insanityengine.ghia.model;
2   
3   import com.insanityengine.ghia.m3.*;
4   import com.insanityengine.ghia.libograf.*;
5   
6   /***
7    *
8    * <P>
9    * Guess what this does...
10   * </P>
11   *
12   * @author BrianHammond
13   *
14   * $Header: /usr/local/cvsroot/ghia/src/java/com/insanityengine/ghia/model/Cube.java,v 1.5 2005/03/19 17:50:02 brian Exp $
15   *
16   */
17  
18  public class Cube implements DrawingInterface {
19  
20  	/***
21  	 *
22  	 * Constructor
23  	 *
24  	 */
25  	public Cube() {}
26  
27  	/***
28  	 *
29  	 * Do some kinda drawing thang
30  	 *
31  	 * @param gl context to draw in
32  	 *
33  	 */
34  	public final void draw( LiboGrafInterface gl ) {
35  		cube( gl );
36  	}
37  
38  	////////////////////////////////////////////////////////////
39  	
40  	/***
41  	 *
42  	 * Draw a cube at given location... kinda lame...
43  	 *
44  	 */
45  	public static final void cube( LiboGrafInterface gl ) {
46  
47  		gl.startPolygon();
48  			gl.textCoord( 0, 0 ); gl.addPoint( pt0 );
49  			gl.textCoord( 1, 0 ); gl.addPoint( pt1 );
50  			gl.textCoord( 1, 1 ); gl.addPoint( pt2 );
51  			gl.textCoord( 0, 1 ); gl.addPoint( pt3 );
52  		gl.stopPolygon();
53  
54  		gl.startPolygon();
55  			gl.textCoord( 0, 0 ); gl.addPoint( pt4 );
56  			gl.textCoord( 1, 0 ); gl.addPoint( pt5 );
57  			gl.textCoord( 1, 1 ); gl.addPoint( pt1 );
58  			gl.textCoord( 0, 1 ); gl.addPoint( pt0 );
59  		gl.stopPolygon();
60  
61  		gl.startPolygon();
62  			gl.textCoord( 0, 0 ); gl.addPoint( pt2 );
63  			gl.textCoord( 1, 0 ); gl.addPoint( pt1 );
64  			gl.textCoord( 1, 1 ); gl.addPoint( pt5 );
65  			gl.textCoord( 0, 1 ); gl.addPoint( pt6 );
66  		gl.stopPolygon();
67  
68  		gl.startPolygon();
69  			gl.textCoord( 0.0f, 0.0f ); gl.addPoint( pt2 );
70  			gl.textCoord( 0.5f, 0.0f ); gl.addPoint( pt6 );
71  			gl.textCoord( 0.5f, 0.5f ); gl.addPoint( pt7 );
72  			gl.textCoord( 0.0f, 0.5f ); gl.addPoint( pt3 );
73  		gl.stopPolygon();
74  
75  		gl.getRenderer().setTextureFunction( M3_Constants.TEXT_CLAMP );
76  		gl.startPolygon();
77  			gl.textCoord( 0, 0 ); gl.addPoint( pt0 );
78  			gl.textCoord( 2, 0 ); gl.addPoint( pt3 );
79  			gl.textCoord( 2, 2 ); gl.addPoint( pt7 );
80  			gl.textCoord( 0, 2 ); gl.addPoint( pt4 );
81  		gl.stopPolygon();
82  
83  		gl.getRenderer().setTextureFunction( M3_Constants.TEXT_WRAP );
84  		gl.startPolygon();
85  			gl.textCoord( 0, 0 ); gl.addPoint( pt7 );
86  			gl.textCoord( 2, 0 ); gl.addPoint( pt6 );
87  			gl.textCoord( 2, 2 ); gl.addPoint( pt5 );
88  			gl.textCoord( 0, 2 ); gl.addPoint( pt4 );
89  		gl.stopPolygon();
90  	}
91  
92  	/***
93  	 *
94  	 * Draw a cube at given location... kinda lame...
95  	 *
96  	 * @param gl to draw with
97  	 * @param x coordinate
98  	 * @param y coordinate
99  	 * @param z coordinate
100 	 *
101 	 */
102 	public final static void cubeAt( LiboGrafInterface gl, float x, float y, float z ) {
103 		gl.push(); 
104 			gl.translate( displacement.set( x, y, z ) );
105 			Cube.cube( gl );
106 		gl.pop();
107 	}
108 	
109 	////////////////////////////////////////////////////////////
110 
111 	private final static Pt3 pt = new Pt3();
112 
113 	private final static Pt3 pt0 = new Pt3( -1.0f, -1.0f,  1.0f );
114 	private final static Pt3 pt1 = new Pt3( -1.0f,  1.0f,  1.0f );
115 	private final static Pt3 pt2 = new Pt3(  1.0f,  1.0f,  1.0f );
116 	private final static Pt3 pt3 = new Pt3(  1.0f, -1.0f,  1.0f );
117 	private final static Pt3 pt4 = new Pt3( -1.0f, -1.0f, -1.0f );
118 	private final static Pt3 pt5 = new Pt3( -1.0f,  1.0f, -1.0f );
119 	private final static Pt3 pt6 = new Pt3(  1.0f,  1.0f, -1.0f );
120 	private final static Pt3 pt7 = new Pt3(  1.0f, -1.0f, -1.0f );
121 
122 	private static Pt3 displacement = new Pt3();
123 
124 };
125 
126 /***
127  *
128  * $Log: Cube.java,v $
129  * Revision 1.5  2005/03/19 17:50:02  brian
130  * repackaging
131  *
132  * Revision 1.4  2005/03/11 23:35:31  brian
133  * major refactoring to add in com.insanityengine.ghia.libograf.State bitz
134  *
135  * Revision 1.3  2005/03/10 13:31:19  brian
136  * introduce com.insanityengine.ghia/libograf/State to pave the way for quaternions based LiboGrafInterface implementation
137  *
138  * Revision 1.2  2004/09/11 19:32:29  brian
139  * effects of adding LiboGrafInterface
140  *
141  * Revision 1.1  2004/09/02 13:17:16  brian
142  * the big reorg
143  *
144  * Revision 1.6  2004/09/01 01:10:42  brian
145  * fix class level javadoc placement
146  *
147  * Revision 1.5  2004/09/01 00:11:06  brian
148  * author, log and header stuff
149  *
150  *
151  */