public class Main implements GLEventListener {
- public static StlFile stlf = null;
+ private Geom geom = new Geom();
+
+ 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));
+ }
+ }
/**
* Take care of initialization here.
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;
gl.glClear(GL.GL_COLOR_BUFFER_BIT);
gl.glPointSize(5.0f);
- for(int i=0; i<stlf.coordArray.length; i+=3) {
+ for(Geom.T t : geom) {
red -= .09f;
green -= .12f;
blue -= .15f;
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);
+ t.glVertices(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 {
- stlf = new StlFile();
+ StlFile stlf = new StlFile();
stlf.load("teapot.stl");
-
- Main main = new Main();
-
- Geom geom = new Geom();
- for(int i=0; i<stlf.coordArray.length; i+=3) {
- for(int j=0; j<3; j++)
- geom.newP(stlf.coordArray[i+j].x,
- stlf.coordArray[i+j].y,
- stlf.coordArray[i+j].z);
- }
-
+ Main main = new Main(stlf);
Frame f = new Frame();
GLCapabilities glcaps = new GLCapabilities();
GLCanvas glcanvas = new GLCanvas();