SLIDE 6 Jan-22-04 SMD159, 3D Graphics in OpenGL 16 L
Modifications to Declarations & Projection
// initial tetrahedron private static final double[][] tetra = { {0., 0., 0.} , {250., 150., 100.} , {250., 500., 0.} , {500., 0., 0.} }; … public void init(GLDrawable drawable) { gl = drawable.getGL(); glu = drawable.getGLU(); gl.glMatrixMode(GL.GL_PROJECTION); gl.glLoadIdentity(); gl.glOrtho(0.0, 500.0, 0.0, 500.0, -500.0, 500.0); gl.glMatrixMode(GL.GL_MODELVIEW); gl.glClearColor(1.0f, 1.0f, 1.0f, 1.0f); }
Jan-22-04 SMD159, 3D Graphics in OpenGL 17 L
Triangle Code
private void triangle(double[] a,double[] b,double[] c) { gl.glBegin(GL.GL_TRIANGLES); gl.glVertex3dv(a); gl.glVertex3dv(b); gl.glVertex3dv(c); gl.glEnd();
Jan-22-04 SMD159, 3D Graphics in OpenGL 18 L
Subdivision Code
private void divide_triangle(double[] a, double[] b, double[] c, int m) { // triangle subdivision using vertex numbers double [] v0 = new double[3], v1 = new double[3], v2 = new double[3]; int j; if(m>0) { for(j=0; j<3; j++) v0[j]=(a[j]+b[j])/2; for(j=0; j<3; j++) v1[j]=(a[j]+c[j])/2; for(j=0; j<3; j++) v2[j]=(b[j]+c[j])/2; divide_triangle(a, v0, v1, m-1); divide_triangle(c, v1, v2, m-1); divide_triangle(b, v2, v0, m-1); } else { triangle(a, b, c); } // draw tri. @end of recursion }