View Javadoc

1   package com.insanityengine.ghia.apps;
2   
3   import java.applet.*;
4   
5   import java.awt.*;
6   import java.awt.image.*;
7   import java.awt.event.*;
8   
9   import javax.swing.*;
10  import javax.swing.event.*;
11  
12  import java.util.*;
13  
14  import com.insanityengine.ghia.m3.*;
15  import com.insanityengine.ghia.util.*;
16  import com.insanityengine.ghia.model.*;
17  import com.insanityengine.ghia.pixels.*;
18  import com.insanityengine.ghia.libograf.*;
19  
20  /***
21   * 
22   * <P>
23   * Loads aoff geometry files and stuff
24   * </P>
25   *
26   * <table border="1">
27   * <topic>945*5 = 4725 triangles</topic>
28   * <TH>RendererName</TH>
29   * <TH>KiloTrianglesPerSecond</TH>
30   * <TH>SnapShot</TH>
31   * <TR valign="top">
32   *	<TD>Memagery</TD>
33   *  <TD>1102/61.640=17.878002 * 4725 =  84475 tps =  84 kts</TD>
34   *	<TD><img src="http://ghia.sourceforge.net/images/old_snaps/Memagery_Geom.gif"/></TD>
35   * </TR>
36   * <TR valign="top">
37   *	<TD>WireFuRenderer</TD>
38   *	<TD>2370/60.817=38.969368 * 4725 = 184130 tps = 184 kts</TD>
39   *	<TD><img src="http://ghia.sourceforge.net/images/old_snaps/WireFuRender_Geom.gif"/></TD>
40   * </TR>
41   * <TR valign="top">
42   *	<TD>ZortPolyRenderer</TD>
43   *	<TD>97510/60.306=1616.9204 * 4725 = 7639948 tps = 76 kts</TD>
44   *	<TD><img src="http://ghia.sourceforge.net/images/old_snaps/ZortPolyRenderer_Geom.gif"/></TD>
45   * </TR>
46   * </table>
47   *
48   * @author BrianHammond
49   *
50   */
51  public class GeomLoadem extends AppletBase {
52  	
53  	/////////////////////////////////////////////////////////////
54  
55  	/*** 
56  	 * 
57  	 * main
58  	 * 
59  	 * @param argv
60  	 * 
61  	 */
62  	public final static void main( String argv[] ) {
63  		GeomLoadem gloadem = new GeomLoadem();
64  		gloadem.frame();
65  
66  		float f;
67  		for ( int i = 0 ; i < argv.length ; i++ ) {
68  			if ( '-' != argv[ i ].charAt( 0 ) ) {
69  				gloadem.load( argv[ i ] );
70  			} else {
71  				switch( argv[ i++ ] .charAt( 1 ) ) {
72  					case 's': 
73  						gloadem.setScale( ( float ) Stdlib.atof( argv[ i ] ) );
74  						break;
75  					case 't':
76  						gloadem.setSkin( argv[ i ] );
77  						break;
78  				}
79  			}
80  		}
81  	}
82  
83  	/////////////////////////////////////////////////////////////
84  	
85  	/*** 
86  	 * 
87  	 * load
88  	 * 
89  	 * @param geom
90  	 * 
91  	 */
92  	public void load( String geom ) {
93  		loader = new GeomLoader( geom );
94  		loader.center();
95  		System.out.println( "-----------------------------------" );
96  		System.out.println( geom + " : " + loader );
97  		System.out.println( "-----------------------------------" );
98  	}
99  
100 	/*** 
101 	 * 
102 	 * setSkin
103 	 * 
104 	 * @param href
105 	 * 
106 	 */
107 	public void setSkin( String href ) {
108 		skin = Imago.skinImage( href );
109 		gl.getRenderer().setSkin( skin );
110 	}
111 
112 	/*** 
113 	 * 
114 	 * initImpl
115 	 * 
116 	 * @param w
117 	 * @param h
118 	 * 
119 	 */
120 	public void initImpl( int w, int h ) {
121 
122 		try {
123 			String geom = getCodeBase() + getParameter( "file" );
124 			load( geom );
125 		} catch ( Exception e ) {
126 		}
127 	
128 		try {
129 			float f = ( float ) Stdlib.atof( getParameter( "scale" ) );
130 			if ( 0 != f ) setScale( f );
131 		} catch ( Exception e ) {
132 			
133 		}
134 
135 		try {
136 			skin = Imago.skinImage( getCodeBase() + "/" + getParameter( "skin" ) );
137 		} catch ( Exception e ) {
138 		}
139 		
140 		if ( null == skin ) {
141 			int[] sk = { 0x0000FF00 };
142 			skin = new ImageSkin( 1, 1, sk );
143 			gl.getRenderer().setSkin( skin );
144 		}
145 	}
146 
147 	/*** 
148 	 * 
149 	 * drawImpl
150 	 * 
151 	 */
152 	public void drawImpl() {
153 
154 		gl.getRenderer().clear();
155 
156 		gl.identity();
157 		gl.rotate( rotation );
158 		gl.scale( scale );
159 		
160 		if ( null == loader ) return;
161 
162 		loader.draw( gl );
163 
164 		if ( false ) cbgb();
165 	}
166 
167 	/*** 
168 	 * 
169 	 * cbgb
170 	 * 
171 	 */
172 	public void cbgb() {
173 		float f = 14;
174 		
175 		gl.identity();
176 		gl.rotate( rotation );
177 		gl.scale( scale.set( f ) );
178 
179 		float x = rotation.getX();
180 		float y = rotation.getY();
181 		float z = rotation.getZ();
182 
183 		cb( x, y, z, -f, 0, 0 );
184 		cb( x, y, z, +f, 0, 0 );
185 		cb( x, y, z, 0, -f, 0 );
186 		cb( x, y, z, 0, +f, 0 );
187 		cb( x, y, z, 0, 0, -f );
188 		cb( x, y, z, 0, 0, +f );
189 	}
190 	
191 	/*** 
192 	 * 
193 	 * cb
194 	 * 
195 	 * @param x
196 	 * @param y
197 	 * @param z
198 	 * @param a
199 	 * @param b
200 	 * @param c
201 	 * 
202 	 */
203 	public void cb( float x, float y, float z, float a, float b, float c ) {
204 		gl.push(); 
205 		gl.translate( new Pt3( a, b, c ) );
206 			loader.draw( gl );
207 		gl.pop();
208 	}
209 
210 	/*** 
211 	 * 
212 	 * setScale
213 	 * 
214 	 * @param f
215 	 * 
216 	 */
217 	public void setScale( float f ) {
218 		if ( 0 != f ) {
219 			scale.set( f );
220 			System.out.println( "" + " scale = " + scale );
221 		}	
222 	}
223 
224 	    
225 	/*** 
226 	 * 
227 	 * printRates
228 	 * 
229 	 * @return a float
230 	 * 
231 	 */
232 	public float printRates() {
233 		float fps = super.printRates();
234 		System.out.println( "pps = " + fps * loader.getSurfaceCount() );
235 		return fps;
236 	}
237 			
238 
239  	// 
240 	
241 	private GeomLoader loader = null;
242 	private Pt3 scale = new Pt3( 10.0f );
243 };
244 
245 /***
246  *
247  * $Log: GeomLoadem.java,v $
248  * Revision 1.12  2005/03/26 23:42:41  brian
249  * fix links
250  *
251  * Revision 1.11  2005/03/21 05:52:12  brian
252  * add enuff stuff to be able to calc pps (polygons per second)
253  *
254  * Revision 1.10  2005/03/19 17:50:02  brian
255  * repackaging
256  *
257  * Revision 1.9  2005/03/11 23:35:31  brian
258  * major refactoring to add in com.insanityengine.ghia.libograf.State bitz
259  *
260  * Revision 1.8  2005/03/10 13:31:19  brian
261  * introduce com.insanityengine.ghia/libograf/State to pave the way for quaternions based LiboGrafInterface implementation
262  *
263  * Revision 1.7  2004/09/11 14:37:21  brian
264  * added RendererConsumer and stuff
265  *
266  * Revision 1.6  2004/09/02 13:17:16  brian
267  * the big reorg
268  *
269  * Revision 1.5  2004/09/01 14:54:41  brian
270  * add support for parameters and cli args...
271  *
272  * Revision 1.4  2004/09/01 01:52:47  brian
273  * added test results (ok, and images) to javadoc
274  *
275  * Revision 1.3  2004/09/01 01:10:42  brian
276  * fix class level javadoc placement
277  *
278  * Revision 1.2  2004/09/01 00:11:06  brian
279  * author, log and header stuff
280  *
281  *
282  */