Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // SimpleRenderer.java
- // Easel
- //
- // Created by Philip Rhodes on 7/22/05.
- // Copyright 2005 __MyCompanyName__. All rights reserved.
- //
- import java.awt.*;
- import java.awt.image.*;
- /** SimpleRenderer renders Shapes to the screen by simply ignoring the z
- * coordinate of every vertex. There is no perspective. Triangles are
- * drawn using lines, so there is no shading either. Also, triangles that
- * are in the "back" of an object are still drawn, so objects look
- * transparent.
- */
- public class SimpleRenderer extends VolatileImageRenderer {
- float [] poly_vertices;
- Polygon poly;
- Matrix projectionMatrix;
- /** Create a SimpleRenderer that renders the shapes in the World w.
- */
- SimpleRenderer(World w, int width, int height, boolean showFPS){
- super(w, width, height, showFPS);
- Matrix s = new ScalingMatrix(1, -1, 0);
- Matrix t = new TranslationMatrix(width/2, height/2, 0);
- this.projectionMatrix = new Matrix(t,s);
- this.poly = new Polygon();
- this.poly_vertices = new float[9];
- }
- /** Draw the shapes in the World associated with this renderer to the
- * backing image, which will then be drawn to the screen when
- * paintComponent is called by Swing.
- */
- public void render(){
- super.render();
- int numTriangles = this.world.numTriangles();
- this.world.computeWorldCoords();
- synchronized(this.backingImage){
- waitUntilPainted();
- this.imageGraphics.setColor(Color.blue);
- for(int ti=0; ti < numTriangles; ti++){
- this.world.getTriangleVertices(ti, this.poly_vertices);
- this.poly.reset();
- this.projectionMatrix.transform(this.poly_vertices);
- for(int vi=0; vi<3; vi++){
- this.poly.addPoint((int) (this.poly_vertices[vi*3]),
- (int) (this.poly_vertices[vi*3 + 1]));
- }
- this.imageGraphics.drawPolygon(this.poly);
- }
- readyForPainting();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement