checkpoint
authoradam <adam@megacz.com>
Mon, 26 Nov 2007 03:50:54 +0000 (19:50 -0800)
committeradam <adam@megacz.com>
Mon, 26 Nov 2007 03:50:54 +0000 (19:50 -0800)
darcs-hash:20071126035054-5007d-07a55acc220977fa3a8c23eb9e061296e1fca9e6.gz

Makefile
src/Geom.java
src/Main.java [new file with mode: 0644]

index a9c9949..0d6f0c7 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,4 +1,4 @@
 all:
        mkdir -p build
        javac -d build `find src -name \*.java`
-       java -cp build Geom
+       java -cp build Main
index fec07b5..c879bfe 100644 (file)
@@ -1,80 +1,42 @@
 import java.awt.*;
+import java.util.*;
 import java.awt.event.*;
 import javax.swing.*;
 import javax.media.opengl.*;
 import javax.media.opengl.glu.*;
 
-public class Geom implements GLEventListener {
+public class Geom {
 
-    public static StlFile stlf = null;
+    private HashMap<P,P> ps = new HashMap<P,P>();
 
-    /**
-     * Take care of initialization here.
-     */
-    public void init(GLAutoDrawable gld) {
-        GL gl = gld.getGL();
-        GLU glu = new GLU();
-        gl.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
-        gl.glViewport(0, 0, 500, 300);
-        gl.glMatrixMode(GL.GL_PROJECTION);
-        gl.glLoadIdentity();
-        //glu.gluOrtho2D(0.0, 500.0, 0.0, 300.0);
-        display(gld);
+    public P newP(float x, float y, float z) {
+        P p = new P(x, y, z);
+        P p2 = ps.get(p);
+        if (p2 != null) return p2;
+        ps.put(p, p);
+        return p;
     }
 
-
-    /**
-     * Take care of drawing here.
-     */
-    public void display(GLAutoDrawable drawable) {
-        float red = 0.0f;
-        float green = 0.0f;
-        float blue = 0.0f;
-        GL gl = drawable.getGL();
-        gl.glClear(GL.GL_COLOR_BUFFER_BIT);
-        gl.glPointSize(5.0f);
-
-        for(int i=0; i<stlf.coordArray.length; i+=3) {
-            red -= .09f;
-            green -= .12f;
-            blue -= .15f;
-            if (red < 0.15) red = 1.0f;
-            if (green < 0.15) green = 1.0f;
-            if (blue < 0.15) blue = 1.0f;
-            gl.glColor3f(red, green, blue);
-
-            gl.glBegin(GL.GL_TRIANGLES);
-            for(int j=0; j<3; j++)
-                gl.glVertex3f(stlf.coordArray[i+j].x,
-                              stlf.coordArray[i+j].y,
-                              stlf.coordArray[i+j].z);
-            gl.glEnd();
-        }
-    }
-
-
-    public void reshape(
-                        GLAutoDrawable drawable,
-                        int x,
-                        int y,
-                        int width,
-                     int height
-                        ) {}
-    public void displayChanged(
-                               GLAutoDrawable drawable,
-                               boolean modeChanged,
-                            boolean deviceChanged
-                               ) {}
-
     /** point in 3-space */
-    public static class P {
+    public class P {
         public final float x, y, z;
         public P(float x, float y, float z) { this.x = x; this.y = y; this.z = z; }
         public V minus(P p) { return null; }
+        public boolean equals(Object o) {
+            if (o==null || !(o instanceof P)) return false;
+            P p = (P)o;
+            return p.x==x && p.y==y && p.z==z;
+        }
+        public int hashCode() {
+            return
+                Float.floatToIntBits(x) ^
+                Float.floatToIntBits(y) ^
+                Float.floatToIntBits(z);
+        }
     }
 
     /** vector in 3-space */
-    public static class V {
+    public class V {
         private final float x, y, z;
         public V(float x, float y, float z) { this.x = x; this.y = y; this.z = z; }
         public V norm() { return null; /* FIXME */ }
@@ -83,7 +45,7 @@ public class Geom implements GLEventListener {
     }
 
     /** an edge */
-    public static class E {
+    public class E {
         public final P p1, p2;
         private T t1, t2;
         public E(P p1, P p2) { this.p1 = p1; this.p2 = p2; }
@@ -98,7 +60,7 @@ public class Geom implements GLEventListener {
     }
 
     /** a triangle (face) */
-    public static class T {
+    public class T {
         public final E e1, e2, e3;
         public T(E e1, E e2, E e3, V normal) {
             P p1 = e1.shared(e2);
@@ -125,40 +87,7 @@ public class Geom implements GLEventListener {
     }
 
     /** matrix */
-    public static class M {
-    }
-
-    public static void main(String[] s) throws Exception {
-        stlf = new StlFile();
-        stlf.load("teapot.stl");
-        /*
-        for(int i=0; i<stlf.coordArray.length; i+=3) {
-            System.out.println("triangle: (" +
-                               stlf.coordArray[i+0] + ", " +
-                               stlf.coordArray[i+1] + ", " +
-                               stlf.coordArray[i+2] + ")");
-        }
-
-    gi.setCoordinates();
-    gi.setNormals(normArray);
-    gi.setStripCounts(stripCounts);
-
-        GeometryInfo gi = ;
-        ga.convertToIndexedTriangles();
-        GeometryArray ga = ;
-        ga.convertToIndexedTriangles();
-        */
-
-        Geom geom = new Geom();
-        
-
-        Frame f = new Frame();
-        GLCapabilities glcaps = new GLCapabilities();
-        GLCanvas glcanvas = new GLCanvas();
-        glcanvas.addGLEventListener(geom);
-        f.add(glcanvas, BorderLayout.CENTER);
-        f.show();
-        f.setSize(500, 300);
+    public class M {
     }
 
 }
diff --git a/src/Main.java b/src/Main.java
new file mode 100644 (file)
index 0000000..df0aaf7
--- /dev/null
@@ -0,0 +1,70 @@
+import java.awt.*;
+import java.awt.event.*;
+import javax.swing.*;
+import javax.media.opengl.*;
+import javax.media.opengl.glu.*;
+
+public class Main implements GLEventListener {
+
+    public static StlFile stlf = null;
+
+    /**
+     * Take care of initialization here.
+     */
+    public void init(GLAutoDrawable gld) {
+        GL gl = gld.getGL();
+        GLU glu = new GLU();
+        gl.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
+        gl.glViewport(0, 0, 500, 300);
+        gl.glMatrixMode(GL.GL_PROJECTION);
+        gl.glLoadIdentity();
+        //glu.gluOrtho2D(0.0, 500.0, 0.0, 300.0);
+        display(gld);
+    }
+
+    /**
+     * Take care of drawing here.
+     */
+    public void display(GLAutoDrawable drawable) {
+        float red = 0.0f;
+        float green = 0.0f;
+        float blue = 0.0f;
+        GL gl = drawable.getGL();
+        gl.glClear(GL.GL_COLOR_BUFFER_BIT);
+        gl.glPointSize(5.0f);
+
+        for(int i=0; i<stlf.coordArray.length; i+=3) {
+            red -= .09f;
+            green -= .12f;
+            blue -= .15f;
+            if (red < 0.15) red = 1.0f;
+            if (green < 0.15) green = 1.0f;
+            if (blue < 0.15) blue = 1.0f;
+            gl.glColor3f(red, green, blue);
+
+            gl.glBegin(GL.GL_TRIANGLES);
+            for(int j=0; j<3; j++)
+                gl.glVertex3f(stlf.coordArray[i+j].x,
+                              stlf.coordArray[i+j].y,
+                              stlf.coordArray[i+j].z);
+            gl.glEnd();
+        }
+    }
+    public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) { }
+    public void displayChanged(GLAutoDrawable drawable, boolean modeChanged, boolean deviceChanged) { }
+
+
+    public static void main(String[] s) throws Exception {
+        stlf = new StlFile();
+        stlf.load("teapot.stl");
+        Main main = new Main();
+        Frame f = new Frame();
+        GLCapabilities glcaps = new GLCapabilities();
+        GLCanvas glcanvas = new GLCanvas();
+        glcanvas.addGLEventListener(main);
+        f.add(glcanvas, BorderLayout.CENTER);
+        f.show();
+        f.setSize(500, 300);
+    }
+
+}
\ No newline at end of file