add vertex normals
[anneal.git] / src / Main.java
index 64852c9..f598ac1 100644 (file)
@@ -8,20 +8,16 @@ public class Main implements GLEventListener {
 
     private Geom geom = new Geom();
 
+    /** magnification factor */
+    private static final float MAG = 1;
+
     public Main(StlFile stlf) {
         for(int i=0; i<stlf.coordArray.length; i+=3) {
-            Geom.P p0 = geom.newP(stlf.coordArray[i+0].x,
-                                  stlf.coordArray[i+0].y,
-                                  stlf.coordArray[i+0].z);
-            Geom.P p1 = geom.newP(stlf.coordArray[i+1].x,
-                                  stlf.coordArray[i+1].y,
-                                  stlf.coordArray[i+1].z);
-            Geom.P p2 = geom.newP(stlf.coordArray[i+2].x,
-                                  stlf.coordArray[i+2].y,
-                                  stlf.coordArray[i+2].z);
-            Geom.T t = geom.newT(geom.newE(p0, p1),
-                                 geom.newE(p1, p2),
-                                 geom.newE(p2, p0));
+            Geom.P p0 = geom.newP(stlf.coordArray[i+0].x * MAG, stlf.coordArray[i+0].y * MAG, stlf.coordArray[i+0].z * MAG);
+            Geom.P p1 = geom.newP(stlf.coordArray[i+1].x * MAG, stlf.coordArray[i+1].y * MAG, stlf.coordArray[i+1].z * MAG);
+            Geom.P p2 = geom.newP(stlf.coordArray[i+2].x * MAG, stlf.coordArray[i+2].y * MAG, stlf.coordArray[i+2].z * MAG);
+            Geom.V n  = geom.new V(stlf.normArray[i/3].x * MAG, stlf.normArray[i/3].y  * MAG, stlf.normArray[i/3].z * MAG);
+            Geom.T t  = geom.newT(geom.newE(p0, p1), geom.newE(p1, p2), geom.newE(p2, p0), n);
         }
     }
 
@@ -39,9 +35,8 @@ public class Main implements GLEventListener {
         display(gld);
     }
 
-    /**
-     * Take care of drawing here.
-     */
+    public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) { }
+    public void displayChanged(GLAutoDrawable drawable, boolean modeChanged, boolean deviceChanged) { }
     public void display(GLAutoDrawable drawable) {
         float red = 0.0f;
         float green = 0.0f;
@@ -61,11 +56,20 @@ public class Main implements GLEventListener {
             gl.glBegin(GL.GL_TRIANGLES);
             t.glVertices(gl);
             gl.glEnd();
+
+            Geom.P centroid = t.centroid();
+            gl.glBegin(GL.GL_LINES);
+            /*
+            centroid.glVertex(gl);
+            centroid.plus(t.norm().times(t.diameter())).glVertex(gl);
+            */
+            t.p1().glVertex(gl);
+            t.p1().plus(t.p1().norm().times(t.diameter())).glVertex(gl);
+            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 {
         StlFile stlf = new StlFile();