/** * Returns the location in world space of the point (x, y) on the screen. * * @param x x coordinate in the image * @param y y coordinate in the image * @return true if there is an object at x, y , false otherwise */ public boolean getPoint(int x, int y, double xyz[]) { if (renderer.bufferg == false) { renderer.bufferg = true; isDamage = true; } return renderer.getPoint(x, y, xyz); }
/** main renderer */ public void run() { // MEASURE ELAPSED TIME AND FRAMERATE elapsed += getCurrentTime() - currentTime; currentTime = getCurrentTime(); if (isDamage) { frameRate = .9 * frameRate + .1 / elapsed; elapsed = 0; // LET THE APPLICATION PROGRAMMER MOVE THINGS INTO PLACE identity(); // APPLIC. MATRIX STARTS UNTRANSFORMED // isDamage = true; renderer.rotateView(theta, phi); theta = phi = 0; ianimate(currentTime - startTime); // APPLICATION ANIMATES THINGS // SHADE AND SCAN CONVERT GEOMETRY INTO FRAME BUFFER renderer.refresh(); renderer.render(); // KEEP REFINING LEVEL OF DETAIL UNTIL PERFECT (WHEN LOD=1) if (renderer.lod > 1) { isDamage = true; renderer.lod--; } } }
/** * Listens for mouse release and controls aspects of the renderer. A release in the upper left * corner toggles {@link Renderer#tableMode}. A release in the upper right corner toggle * visibility of the {@link Material#table}display. When true, the current material table is * displayed in the upper left corner of the window. Position of the mouse determines current * material. A release in the lower right toggles {@link Renderer#showMesh} * * @param event Event * @param x current x coordinate * @param y current y coordinate * @return true */ public boolean mouseUp(int x, int y) { Renderer.setDragging(false); if (x < 35 && y < 35) { Renderer.tableMode = !Renderer.tableMode; } if (x > W - 35 && y < 35) { seeMaterial = !seeMaterial; renderer.bufferg = !renderer.bufferg; damage(); } if (x > W - 35 && y > H - 35) { renderer.showMesh = !renderer.showMesh; damage(); } return true; }
/** * Adds light source with direction (x, y, z) & color (r, g, b). Arguments x,y,z indicate light * direction. Arguments r,g,b indicate light direction. * * @see Renderer#addLight(double x,double y,double z, double r,double g,double b) */ public void addLight( double x, double y, double z, // ADD A LIGHT SOURCE double r, double g, double b) { renderer.addLight(x, y, z, r, g, b); }
/** * Initializes the applet and internal variables. To initialize components of the application * program use {@link #initialize()}. * * @see #initialize() */ public void init() { startTime = getCurrentTime(); world = renderer.getWorld(); // GET ROOT OF GEOMETRY for (int i = 0; i < matrix.length; i++) matrix[i] = new Matrix(); identity(); initialize(); if (world != null && world.child != null) for (int n = 0; n < world.child.length; n++) if (world.child[n] != null && world.child[n].material != null) mat = world.child[n].material; }
/** * Handles commands received (generally for unicode commands from the KeyListener, but also for * commands from any other sources, like buttons from webpages) : various default control keys to * modify render style (Use CTRL + key). * * <p>'e' - toggles {@link Renderer#showMesh}, that just displays the shapes as mesh wireframes * <br> * 'l' - toggles {@link Renderer#getOutline()}which produces a sketch-line drawing rendition of * the scene <br> * 'm' - toggles {@link Renderer#seeMesh}which determines mesh visibility <br> * 't' - toggles global texture manipulation method (MIP on/off) (@link Texture#useMIP) * * <p> * * @param event Event * @param key value of the key released * @return true if one of the above keys was just released, false otherwise. */ public boolean processCommand(int key) { switch (key) { case 'e' - ('a' - 1): renderer.showMesh = !renderer.showMesh; damage(); return true; case 'l' - ('a' - 1): renderer.outline(-renderer.getOutline()); damage(); return true; case 'm' - ('a' - 1): renderer.seeMesh = !renderer.seeMesh; damage(); return true; case 't' - ('a' - 1): Texture.useMIP = !Texture.useMIP; damage(); return true; } return false; }
/** * Dragging the mouse causes gradual view rotation in the phi and theta directions. * * <p> * * @param event Event * @param x new x coordinate * @param y new y coordinate */ public boolean mouseDrag(int x, int y) { if (Renderer.isDragging()) { theta += .03 * (double) (x - mx); // HORIZONTAL VIEW ROTATION phi += .03 * (double) (y - my); // VERTICAL VIEW ROTATION mx = x; my = y; } if (frameRate < 10 && renderer.lod < 4) if (enableLod) renderer.lod++; isDamage = true; return true; }
/** * @param m * @param n * @param w * @param h * @param pix */ public InteractiveRenderer(int m, int n, int w, int h) { W = w; H = h; renderer = new Renderer(); pixels = renderer.init(W, H); Geometry g = this.add(); texture = new Texture(pixels, W, H, "grid", false); Material material = new Material(); material.setTexture(texture); g.setMaterial(material); g.setDoubleSided(true); g.mesh(m, n); g.name = "mesh"; init(); }
/** * Sets the background color ( RGB values range: 0..1) * * @param r red component 0..1 * @param g green component 0..1 * @param b blue component 0..1 */ public void setBgColor(double r, double g, double b) { renderer.setBgColor(r, g, b); }
/** * Sets the camera's focal length. * * @param value focal length * @see Renderer#setFL(double value) */ public void setFL(double value) { renderer.setFL(value); }
/** Forces a refresh of the renderer. Sets isDamage true. */ public void damage() { renderer.refresh(); isDamage = true; }
/** * Listener for mouse down. Mouse down starts a view rotation. * * @return true */ public boolean mouseDown(int x, int y) { Renderer.setDragging(true); mx = x; my = y; return true; }
public void draw(Renderer r) { r.draw(this); }