checkpoint
[anneal.git] / src / edu / berkeley / qfat / MeshViewer.java
index 7dc5b0a..cb21cfb 100644 (file)
@@ -83,6 +83,31 @@ public class MeshViewer implements GLEventListener, MouseListener, MouseMotionLi
         gl.glMatrixMode(GL.GL_PROJECTION);
         gl.glLoadIdentity();
         gl.glMatrixMode(GL.GL_MODELVIEW);
+
+        float mat_specular[] = { 0.5f, 0.5f, 0.5f, 0.5f };
+        float mat_shininess[] = { 50.0f };
+        gl.glShadeModel(GL.GL_SMOOTH);
+        gl.glMaterialfv(GL.GL_FRONT, GL.GL_DIFFUSE, mat_specular, 0);  
+        //gl.glMaterialfv(GL.GL_FRONT, GL.GL_SPECULAR, mat_specular, 0);  
+        gl.glMaterialfv(GL.GL_FRONT, GL.GL_AMBIENT, new float[] { 0.3f, 0.3f, 0.3f, 0.3f }, 0);  
+        //gl.glMaterialfv(GL.GL_FRONT, GL.GL_SHININESS, mat_shininess, 0);
+        gl.glLightfv(GL.GL_LIGHT0, GL.GL_POSITION, new float[] { 1.0f, 4.0f, -10.0f, 0.0f }, 0);
+        gl.glLightfv(GL.GL_LIGHT1, GL.GL_POSITION, new float[] { -10.0f, 10.0f, 10.0f, 0.0f }, 0);
+        gl.glLightfv(GL.GL_LIGHT2, GL.GL_POSITION, new float[] { 10.0f, -10.0f, 10.0f, 0.0f }, 0);
+        gl.glLightfv(GL.GL_LIGHT3, GL.GL_POSITION, new float[] { 10.0f, 10.0f,  -10.0f, 0.0f }, 0);
+        gl.glLightfv(GL.GL_LIGHT4, GL.GL_POSITION, new float[] { -10.0f, 10.0f, -10.0f, 0.0f }, 0);
+        gl.glLightfv(GL.GL_LIGHT5, GL.GL_POSITION, new float[] { 10.0f, -10.0f, -10.0f, 0.0f }, 0);
+        gl.glEnable(GL.GL_LIGHTING);
+        gl.glEnable(GL.GL_LIGHT0);
+        gl.glEnable(GL.GL_LIGHT1);
+        gl.glEnable(GL.GL_LIGHT2);
+        gl.glEnable(GL.GL_LIGHT3);
+        gl.glEnable(GL.GL_LIGHT4);
+        gl.glEnable(GL.GL_LIGHT5);
+
+        gl.glColorMaterial(GL.GL_FRONT_AND_BACK, GL.GL_AMBIENT_AND_DIFFUSE);
+        gl.glEnable(GL.GL_COLOR_MATERIAL);
+
         display(gld);
     }
 
@@ -107,7 +132,7 @@ public class MeshViewer implements GLEventListener, MouseListener, MouseMotionLi
 
         gl.glBegin(GL.GL_TRIANGLES);
         gl.glColor4f((float)0.5, (float)0.5, (float)0.5, (float)0.8);
-        //draw(gl, false, goal);
+        draw(gl, false, goal);
         gl.glEnd();
 
 
@@ -117,7 +142,7 @@ public class MeshViewer implements GLEventListener, MouseListener, MouseMotionLi
         for(Matrix m : translations) {
             //if (v1.z==0 && v1.y==0) continue;
             i++;
-            if (i != 1 /*&& i!=4*/) continue;
+            if (i != 7 /*&& i!=4*/) continue;
             Point p = new Point(0, 0, 0).times(m);
             Vec v = new Vec(p.x, p.y, p.z);
             v = v.times((float)1.04);
@@ -126,6 +151,7 @@ public class MeshViewer implements GLEventListener, MouseListener, MouseMotionLi
             gl.glTranslatef(-v.x, -v.y, -v.z);
         }
         //gl.glEnable(GL.GL_DEPTH_TEST);
+        gl.glEnable (GL.GL_LIGHTING);
     }
 
     private synchronized void draw(GL gl, boolean triangles, Mesh mesh) {
@@ -140,11 +166,14 @@ public class MeshViewer implements GLEventListener, MouseListener, MouseMotionLi
             green -= .12f;
             blue -= .15f;
 
-            if (triangles) switch(t.color) {
+            if (triangles) switch(t.color/*class*/) {
                 case 0: gl.glColor4f((float)0.25, (float)0.25, (float)0.75, (float)0.3); break;
                 case 1: gl.glColor4f((float)0.25, (float)0.75, (float)0.25, (float)0.3); break;
                 case 2: gl.glColor4f((float)0.75, (float)0.25, (float)0.25, (float)0.3); break;
                 case 3: gl.glColor4f((float)0.50, (float)0.50, (float)0.50, (float)0.3); break;
+                case 4: gl.glColor4f((float)0.25, (float)0.75, (float)0.75, (float)0.3); break;
+                case 5: gl.glColor4f((float)0.25, (float)0.75, (float)0.75, (float)0.3); break;
+                case 6: gl.glColor4f((float)0.75, (float)0.25, (float)0.75, (float)0.3); break;
             }
             //gl.glBegin(GL.GL_LINES);
 
@@ -153,7 +182,9 @@ public class MeshViewer implements GLEventListener, MouseListener, MouseMotionLi
                 t.glVertices(gl);
                 gl.glEnd();
             } else {
+                gl.glDisable(GL.GL_LIGHTING);
                 gl.glBegin(GL.GL_LINES);
+                gl.glColor3f(1, 1, 1);
                 t.e1().p1.p.glVertex(gl);
                 t.e1().p2.p.glVertex(gl);
                 t.e2().p1.p.glVertex(gl);
@@ -161,6 +192,7 @@ public class MeshViewer implements GLEventListener, MouseListener, MouseMotionLi
                 t.e3().p1.p.glVertex(gl);
                 t.e3().p2.p.glVertex(gl);
                 gl.glEnd();
+                gl.glEnable(GL.GL_LIGHTING);
             }
 
             Point centroid = t.centroid();
@@ -173,7 +205,7 @@ public class MeshViewer implements GLEventListener, MouseListener, MouseMotionLi
 
             if (mesh==goal)
                 for(Mesh.Vert p : new Mesh.Vert[] { t.v1(), t.v2(), t.v3() }) {
-                    p.p.glVertex(gl);
+                    //p.p.glVertex(gl);
                     //p.plus(p.norm().times(p.score()*10)).glVertex(gl);
                     //p.partner().p.glVertex(gl);
                     //tile.nearest(p).centroid().glVertex(gl);