// light_dat.java projection may not be best // needs center // needs heapsort.java compiled import java.io.*; import java.util.*; import java.text.*; import java.awt.*; import java.awt.event.*; public class light_dat extends Frame { // .dat format file input int num_points; int num_polys; double x[] = new double[20000]; double y[] = new double[20000]; double z[] = new double[20000]; int data_polys[] = new int[256000]; int pripoly[] = new int[18000]; int priindex[] = new int[18000]; double priz[] = new double[18000]; double winxyz[] = new double[3]; int maxpolys; double dxmin, dxmax, dymin, dymax, dzmin, dzmax; double dxctr, dyctr, dzctr, dxinc, dyinc, dzinc; String fname; double size = 1.0; double gsize = 1.0; double nsize = -1.0; double scale = 0.15; double offs = 1.0; // not used boolean debug = true; int xm, ym, bm; // mouse double pos[] = {0.0, 0.0, 0.0}; // keys or mouse clicks double roll = 0.0; // rotate object double pitch = 0.0; double heading = 0.0; int wire = 1; // ??? set to zero when debugged int vert = 0; int colorz = 0; int noden = 1; int nonum = 0; double mmatrix[][] = new double[4][4];// 4 by 4 model transformation matrix double pmatrix[][] = new double[4][4];// 4 by 4 persp transformation matrix int viewport[] = new int[4]; double pxyzw[] = new double[4]; int win_w = 600; int win_h = 600; double M_PI = Math.PI; heapsort H = new heapsort(); light_dat(String filename) { System.out.println("light_dat.java reading "+filename); read_data(filename); System.out.println("num_points="+num_points+", num_polys="+num_polys); System.out.println("size="+size+", maxpolys="+maxpolys); fname = filename; setTitle("light_dat"); setSize(win_w,win_h); setBackground(Color.white); addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }); setVisible(true); this.addMouseListener (new mousePressHandler()); } // end light_dat void read_data(String filename) { String input_line; int k=0; int ntok, pts; StringTokenizer T; String token[] = new String[255]; try { FileReader fin = new FileReader(filename); BufferedReader file_in = new BufferedReader(fin); if(debug) System.out.println("read_data reading "+filename); input_line = file_in.readLine(); if(debug) System.out.println(input_line); T = new StringTokenizer(input_line," "); ntok=0; while(T.hasMoreTokens()) { token[ntok]=T.nextToken(); if(debug) System.out.println("token["+ntok+"]=|"+token[ntok]+"|"); ntok++; } num_points = Integer.parseInt(token[0]); num_polys = Integer.parseInt(token[1]); System.out.println("num_points="+num_points+", num_polys="+num_polys); // read points for(int i=0; i v Y ^ < Z > < R > ^ P v v H ^ W V C N sz SZ Nn", 20, win_h-25); g.drawString("x="+pos[0]+", y="+pos[1]+", z-"+pos[2]+", R="+roll+", P="+ pitch+", H="+heading+", S="+size, 20, win_h-10); order_polys(); if(colorz==1) draw_face_dat(g); if(wire==1) draw_wire_dat(g); if(noden==1) draw_node_dat(g); else if(vert==1) draw_vert_dat(g); else draw_face_dat(g); } // end paint class mousePressHandler extends MouseAdapter { public void mousePressed (MouseEvent e) { char key=' '; xm = e.getX(); ym = e.getY(); bm = e.getButton(); System.out.println("mouse xm="+xm+", ym="+ym+", bm="+bm); if(ym>win_h-21 || ym18 && xm<28) key = 'x'; if(xm>45 && xm<55) key = 'X'; if(xm>62 && xm<72) key = 'y'; if(xm>85 && xm<95) key = 'Y'; if(xm>102 && xm<112) key = 'z'; if(xm>125 && xm<135) key = 'Z'; if(xm>148 && xm<158) key = 'r'; if(xm>172 && xm<182) key = 'R'; if(xm>191 && xm<201) key = 'p'; if(xm>214 && xm<224) key = 'P'; if(xm>230 && xm<240) key = 'h'; if(xm>255 && xm<265) key = 'H'; if(xm>275 && xm<295) key = 'W'; if(xm>300 && xm<320) key = 'V'; if(xm>325 && xm<345) key = 'C'; if(xm>345 && xm<370) key = 'N'; if(xm>370 && xm<400) key = 's'; if(xm>400 && xm<430) key = 'S'; if(xm>430 && xm<460) key = 'n'; if(debug) { System.out.println("at xm="+xm+", ym="+ym+", bm="+bm); // debug print System.out.println("key="+key); } if(key == 'x') {pos[0] -= dxinc;} // position object if(key == 'X') {pos[0] += dxinc;} if(key == 'y') {pos[1] -= dyinc;} if(key == 'Y') {pos[1] += dyinc;} if(key == 'z') {pos[2] -= dzinc;} if(key == 'Z') {pos[2] += dzinc;} if(key == 'r') {roll -= 15.0; // rotate object if(roll<=-360) roll += 360.0;} if(key == 'R') {roll += 15.0; if(roll>=360) roll -= 360.0;} if(key == 'p') {pitch -= 15.0; if(pitch<=-360) pitch += 360.0;} if(key == 'P') {pitch += 15.0; if(pitch>=360) pitch -= 360.0;} if(key == 'h') {heading -= 15.0; if(heading<=-360) heading += 360.0;} if(key == 'H') {heading += 15.0; if(heading>=360) heading -= 360.0;} if(key == 'w' || key == 'W') {wire = 1-wire;} // 0,0,0 is colorz face if(key == 'v' || key == 'V') {vert = 1-vert; wire=0; colorz=0;} if(key == 'c' || key == 'C') {colorz = 1-colorz; wire=0; vert=0;} if(key == 'N' || key == 'N') {noden = 1-noden;} if(key == 's') {gsize = gsize*1.15;} // size smaller if(key == 'S') {gsize = gsize*0.85;} // size larger if(key == 'n') {nonum = 1-nonum;} System.out.println("roll="+roll+", pitch="+pitch+", head="+heading+ ", size="+gsize); // debug print requestFocus(); repaint(); } } // end mousePressHandler void draw_face_dat(Graphics g) { int i, j, k, pts, pt, pt1; int skipz=0; double nxyz[] = new double[3]; int xpts[] = new int[10]; int ypts[] = new int[10]; double xsav[] = new double[3]; double ysav[] = new double[3]; double zsav[] = new double[3]; double zmin=0.0, zmax=0.0, zavg=0.0; double x1, x2, x3, x4, y1, y2, y3, y4, z1, z2, z3, z4 ; build_mmat(); // from pitch, heading, roll, pos //glGetDoublev(GL_MODELVIEW_MATRIX, mmatrix); // save transformation //glGetDoublev(GL_PROJECTION_MATRIX, pmatrix); if(debug) System.out.println("in draw_face_dat"); // use num_polys to do that many faces k = 0; for(i=0; i zmax) zmax = winxyz[2]; } zavg = zavg/ (double)num_points; } // use num_polys to do wire frame k = 0; for(i=0; i