www.pudn.com > j3dme-0.3.0.rar > Renderer.java


/*
 * J3DME Fast 3D software rendering for small devices
 * Copyright (C) 2001 Onno Hommes
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

package net.jscience.j3dme;

/**
 * This abstart class defines the methods to be implemented
 * by platform specific renderers. The renderer is responsible for
 * drawing on the display of the device the engine is running on.
 * This abstract class disconnects the 3D engine from the platform that
 * it is runnning on. The platform specific renderer will use the platform
 * specific drawing capabilities to implement the abstract drawing methods.
 */
public abstract class Renderer {

  private int[] transformation;

  /**
   * Draws a line on the screen

* @param x1 Start x coordinate * @param y1 Start y coordinate * @param x2 End x coordinate * @param y2 End y coordinate */ public abstract void drawLine(int x1,int y1,int x2,int y2); /** * Clears a portion of the screen

* @param x Top left x coordinate of area to clear * @param y Top left y coordinate * @param w Width of the area * @param h Height ot the area */ public abstract void clearArea(int x,int y,int w,int h); /** * Define the drawregion on the screen

* @param x Top left x coordinate * @param y Top left y coordinate * @param w Width of the area * @param h Height of the area */ public abstract void setDrawRegion(int x,int y,int w,int h); /** * * @param x Top left x coordinate * @param y Top left y coordinate * @param w Width of the area * @param h Height of the area */ public void drawRectangle(int x,int y,int w,int h){ drawLine(x,y,x+w,y); drawLine(x+w,y,x+w,y+h); drawLine(x+w,y+h,x,y+h); drawLine(x,y+h,x,y); } public void drawScene(ViewPort view){ boolean[] visible_faces; int cx = view.cx; int cy = view.cy; int offset=0; Camera camera = view.camera; World world = camera.getWorld(); // Take a Picture camera.captureScene(); // Clear Display //setDrawRegion(view.x,view.y,view.width,view.height); clearArea(view.x,view.y,view.width,view.height); int size = world.getNumberOfModels(); for (int mi=0;mi> 8; int sy = camera.y_tfx[si] * viewscale >> 8; int ex = camera.x_tfx[ei] * viewscale >> 8; int ey = camera.y_tfx[ei] * viewscale >> 8; drawLine(cx+sx, cy-sy, cx+ex, cy-ey); } } offset += wires; } } public boolean isWireVisible(int surface_mask,int w_index, Surface geometry){ int[] wires = geometry.wires; for (int wi=0;wi= geometry.polygons_from[si] && wi <= geometry.polygons_to[si]){ // Determine bit_mask int bit_mask = 1 << si; // If visible return true otherwise keep on searching if ((surface_mask & bit_mask) == bit_mask) return true; } } } } // Wire not visible return false; } }