public void display(GLAutoDrawable drawable) {
// Perform ratio time-steps on the model
callback.tick();
// Clear buffer, etc.
GL gl = drawable.getGL();
gl.glClearColor(1.0f, 1.0f,1.0f, 1.0f);
gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT | GL.GL_STENCIL_BUFFER_BIT);
gl.glMatrixMode(GL.GL_MODELVIEW);
gl.glLoadIdentity();
// Set camera transform
glu.gluLookAt(cameraFrom.x, cameraFrom.y, cameraFrom.z,
cameraTo.x, cameraTo.y, cameraTo.z,
0, 1, 0);
//copy camera transform
gl.glGetDoublev(GL.GL_MODELVIEW_MATRIX, camera, 0);
for ( DrawShape shape: toDraw) {
gl.glPushAttrib(GL.GL_LIGHTING_BIT);
gl.glPushMatrix();
gl.glMultMatrixd(shape.getTransform().toArray(), 0);
if (shape.getReferenceBody().deactivated) {
float ambientLight[] = { 1.5f, 1.5f, 2.0f, 1.0f };
// float diffuseLight[] = { 0.8f, 0.0f, 0.8f, 1.0f };
// float specularLight[] = { 0.5f, 0.5f, 0.5f, 1.0f };
// float position[] = { -1.5f, 1.0f, -4.0f, 1.0f };
// Assign created components to GL_LIGHT0
gl.glLightfv(GL.GL_LIGHT0, GL.GL_AMBIENT, ambientLight,0);
// gl.glLightfv(GL.GL_LIGHT0, GL.GL_DIFFUSE, diffuseLight,0);
// gl.glLightfv(GL.GL_LIGHT0, GL.GL_SPECULAR, specularLight,0);
// gl.glLightfv(GL.GL_LIGHT0, GL.GL_POSITION, position,0);
}
//gl.glPushMatrix();
// gl.glMultMatrixd(Matrix4.pack(shape.getTransform()),0);
gl.glPolygonMode(GL.GL_FRONT_AND_BACK, GL.GL_FILL);
Iterator<Vector3[]> i = shape.getFaces();
while (i.hasNext()) {
gl.glBegin(GL.GL_POLYGON);
Vector3[] face = i.next();
//compute normal
Vector3 n =face[1].sub(face[0]).cross(face[2].sub(face[1])).normalize();
for ( Vector3 v: face) {
gl.glNormal3d(n.x, n.y, n.z);
//gl.glTexCoord2f(1.0f, 1.0f);
//gl.glColor3d(v.a1, v.a2, v.a3);
gl.glVertex3d(v.x, v.y, v.z);
gl.glTexCoord2f(0.0f, 1.0f);
}
gl.glEnd();
}
gl.glPolygonMode( GL.GL_FRONT, GL.GL_LINE );
gl.glLineWidth(1.7f);
gl.glDisable(GL.GL_LIGHTING);
gl.glScaled(1.01, 1.01, 1.01);
i = shape.getFaces();
while (i.hasNext()) {
gl.glBegin(GL.GL_POLYGON);
Vector3[] face = i.next();
//compute normal
Vector3 n =face[1].sub(face[0]).cross(face[2].sub(face[1])).normalize();
for ( Vector3 v: face) {
gl.glNormal3d(n.x, n.y, n.z);
//gl.glTexCoord2f(1.0f, 1.0f);
gl.glColor3d(0.2,0.2, 0.2);
gl.glVertex3d(v.x, v.y, v.z);
gl.glTexCoord2f(0.0f, 1.0f);
}
gl.glEnd();
}
gl.glEnable(GL.GL_LIGHTING);
gl.glPopMatrix();
gl.glPopAttrib();
}
//draw shadows
gl.glLoadIdentity();
gl.glDisable(GL.GL_LIGHTING);
// Set camera transform
glu.gluLookAt(cameraFrom.x, cameraFrom.y, cameraFrom.z,
cameraTo.x, cameraTo.y, cameraTo.z,
0, 1, 0);
gl.glMultMatrixd(shadowProjectionMatrix(new Vector3(75,350,-75), new Vector3(0,-20 + 0.0,0), new Vector3(0,-1,0)), 0);
gl.glColor3d(0.85, 0.85, 0.85);
for ( DrawShape shape: toDraw) {
gl.glPushMatrix();
gl.glMultMatrixd(shape.getTransform().toArray(), 0);
// gl.glMultMatrixd(Matrix4.pack(dt.shape.getTransform()),0);
gl.glPolygonMode(GL.GL_FRONT_AND_BACK, GL.GL_FILL);
Iterator<Vector3[]> i = shape.getFaces();
while (i.hasNext()) {
gl.glBegin(GL.GL_POLYGON);
Vector3[] face = i.next();
for ( Vector3 v: face) {
gl.glVertex3d(v.x, v.y, v.z);
}
gl.glEnd();
}
gl.glPopMatrix();
}
gl.glEnable(GL.GL_LIGHTING);
// Finish this frame
gl.glFlush();
}