//jleblanc: 2.27.06 //rudimentry exploration of branching //Needs Node.java and Vector3D.java import org.lwjgl.opengl.*; import org.lwjgl.opengl.glu.GLU; import org.lwjgl.input.Keyboard; public class Recurse { private boolean done = false; private final String windowTitle = "Basic OpenGL App"; private DisplayMode displayMode; float rotation = 0f; Node core; //Main function just creates and runs the application. public static void main(String args[]) { Recurse app = new Recurse(); app.run(); } //Initialize the app, then sit in a render loop until done==true. public void run() { try { init(); while (!done) { mainloop(); render(); Display.update(); } cleanup(); } catch (Exception e) { e.printStackTrace(); System.exit(0); } } //Initialize the environment private void init() throws Exception { initDisplay(); initGL(); core = new Node(0,0,0); buildtree(core, 0, 10); } //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( -.5f, 2f, 7f, // eye position //-.5,1,7 //0f,0f,15f, 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); // depth GL11.glEnable(GL11.GL_DEPTH_TEST); } //Handle keyboard input. Just check for escape key or user 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() { Node temp, temp2; float mvy, mvx; rotation += .08f; // 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(); // rotate coord system around Y GL11.glRotatef(rotation, 0,1,0); GL11.glTranslatef(0, -.5f, 0); // draw crosshairs drawOrigin(); drawtree(core,0,0,0); mvx=.005f*(float)Math.cos(rotation/10); mvy=.001f*(float)Math.sin(rotation/10); messtreeX(core, mvx, mvy); } void buildtree(Node root, int level, int mlevel) { Node temp; float div; div=(float)level; div=2*(1-div/10); if(level