//REQUIRES: Vector3D.java //jleblanc 2.14.06 //simple randomwalk that is lit and the walk ribbon has normals //also includes miniviews from x y and z import java.nio.*; // Native IO buffers: LWJGL uses these to efficiently exchange data with system memory import java.util.ArrayList; import org.lwjgl.opengl.*; import org.lwjgl.opengl.glu.GLU; import org.lwjgl.opengl.glu.Sphere; import org.lwjgl.input.Keyboard; public class walk_light { private boolean done = false; private final String windowTitle = "Lit Sphere"; private DisplayMode displayMode; float rotation = 0; // color of ambient light float ambient[] = { .5f, .5f, .5f, 1f }; // some ambient light // color of light float lightColor[] = { .9f, .9f, .7f, 1f }; // yellow-white // light position: if last value is 0, then this describes light direction. If 1, then light position. float lightPosition[] = { -3f, 4f, 6, 1f }; public ArrayList points; public ArrayList colors; //Main function just creates and runs the application. public static void main(String args[]) { walk_light app = new walk_light(); app.run(); } //Initialize the app, then sit in a render loop until done==true. public void run() { try { init(); walkinit(); while (!done) { mainloop(); render(); Display.update(); } cleanup(); } catch (Exception e) { e.printStackTrace(); System.exit(0); } } //Initialize the environment: @throws Exception private void init() throws Exception { initDisplay(); initGL(); //initialize variables points = new ArrayList(); colors = new ArrayList(); } //Create an OpenGL display, in this case a fullscreen window. private void initDisplay() throws Exception { // set to full screen, no chrome Display.setFullscreen(false); // get all possible display resolutions DisplayMode d[] = Display.getAvailableDisplayModes(); // find a resolution we like for (int i = 0; i < d.length; i++) { if (d[i].getWidth() == 800 && d[i].getHeight() == 600 && d[i].getBitsPerPixel() == 32) { displayMode = d[i]; break; } } // set the display to the resolution we picked Display.setDisplayMode(displayMode); Display.setTitle(windowTitle); // create the window Display.create(); } //Initialize OpenGL private void initGL() { // Select the Projection Matrix (controls perspective) GL11.glMatrixMode(GL11.GL_PROJECTION); GL11.glLoadIdentity(); // Reset The Projection Matrix // Define perspective GLU.gluPerspective( 45.0f, // Field Of View (float)displayMode.getWidth() / (float)displayMode.getHeight(), // aspect ratio 0.1f, // near Z clipping plane 100.0f); // far Z clipping plane // Where is the 'eye' GLU.gluLookAt( 0f, 0f, 15f, // eye position 0f, 0f, 0f, // target to look at 0f, 1f, 0f); // which way is up // Select The Modelview Matrix (controls model orientation) GL11.glMatrixMode(GL11.GL_MODELVIEW); // make sure OpenGL correctly layers objects GL11.glEnable(GL11.GL_DEPTH_TEST); // OpenGL won't draw backward facing triangles ("back faces") /////GL11.glEnable(GL11.GL_CULL_FACE); // turn lighting on (does not create a light) GL11.glEnable(GL11.GL_LIGHTING); // Create a light // diffuse is the color of direct light from this light source // ambient is the color of reflected light from this source // position is where the light is, or it's direction setLight( GL11.GL_LIGHT1, lightColor, lightPosition ); // no overall scene lighting setAmbientLight(ambient); } //Handle keyboard input. private void mainloop() { if(Keyboard.isKeyDown(Keyboard.KEY_ESCAPE)) { // Escape is pressed done = true; } if(Display.isCloseRequested()) { // Window is closed done = true; } } //Render the scene. private void render() { //enable the camera to rotate around scene float cameraX=0; float cameraZ=0; // Clear screen and depth buffer GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT); // Reset the Modelview matrix // this resets the coordinate system to center of screen GL11.glLoadIdentity(); rotation += .05f; cameraX = (float) Math.sin(Math.toRadians(rotation)); cameraZ = (float) Math.cos(Math.toRadians(rotation)); setLightPos(GL11.GL_LIGHT1, cameraX, 1, cameraZ); //setLightPos(GL11.GL_LIGHT1, 0, 10, 0); //draw main rotating ortho view GL11.glViewport(0, 0, 800, 600); //Redefine camera postion GLU.gluLookAt( cameraX, .5f, cameraZ, // 0f, 0f, 0f, // target to look at (Origin) 0f, 1f, 0f); // which way is up drawOrigin(); renderw(); //draw miniview : LOOK SIDE Z GL11.glViewport(0, 0, 200, 150);//MOVE THIS AROUND GL11.glLoadIdentity(); //Where is the 'eye' GLU.gluLookAt( 0f, 0f, 1f, // eye position //-.5,1,7 //0f,0f,15f, 0f, 0f, 0f, // target to look at 0f, 1f, 0f); // which way is up GL11.glOrtho( -1f, 1f, //X: left side, right side -.75f, .75f, //Y: bottom, top -5f, 5f //Z: near, far ); drawOrigin(); renderw(); //draw miniview : LOOK SIDE X GL11.glViewport(250, 0, 200, 150);//MOVE THIS AROUND GL11.glLoadIdentity(); //Where is the 'eye' GLU.gluLookAt( 1f, 0f, 0f, // eye position //-.5,1,7 //0f,0f,15f, 0f, 0f, 0f, // target to look at 0f, 1f, 0f); // which way is up GL11.glOrtho( -1f, 1f, //X: left side, right side -.75f, .75f, //Y: bottom, top -1f, 1f //Z: near, far ); drawOrigin(); renderw(); //draw miniview : LOOK DOWN GL11.glViewport(500, 0, 200, 150);//MOVE THIS AROUND GL11.glLoadIdentity(); //Where is the 'eye' GLU.gluLookAt( 0f, 5f, 1f, // eye position //-.5,1,7 //0f,0f,15f, 0f, 0f, 0f, // target to look at 0f, 1f, 0f); // which way is up GL11.glOrtho( -1f, 1f, //X: left side, right side -.75f, .75f, //Y: bottom, top -1f, 1f //Z: near, far ); drawOrigin(); renderw(); }//END render //this function renders the walk public void renderw() { GL11.glBegin(GL11.GL_TRIANGLE_STRIP); for(int i = 0;i