// (C) 2001 SyGem Software import java.awt.*; import java.applet.*; import com.sygem.jazz3d3.*; import com.sygem.jazz3d3.primitive.Torus3d; public class transparency extends Applet implements Runnable { Thread m_ce; World myWorld; int light1; int pid; RenderTransparent tranny = new RenderTransparent(); RenderSolid solid = new RenderSolid(); int downx = 0; int downy = 0; double ddx = 0; double ddy = 0; boolean down = false; boolean antialias = false; boolean bilinear = false; //Construct the applet public transparency() { } //Initialize the applet public void init() { myWorld = new World(this); setLayout(new BorderLayout()); add("Center",myWorld); } //Start the applet public void start() { if (m_ce == null) { m_ce = new Thread(this); m_ce.start(); } } //Stop the applet public void stop() { if (m_ce != null) { m_ce.stop(); m_ce = null; } } //Destroy the applet public void destroy() { } public void run() { int iCount = 0; long lTime0 = System.currentTimeMillis(); double z; ddx = 0.16; ddy = 0.35; z = 0.21; myWorld.prep(); myWorld.prepareCanvas(); myWorld.drawImage(); Graphics g = myWorld.getCanvas(); g.setColor(new Color(255,0,0)); g.drawString("Initializing demo...",20,80); myWorld.finishCanvas(); myWorld.setBackground(TextureLoader.loadImage("images/Jazz3D_logo_large.gif")); Torus3d sp1 = new Torus3d(0.5,0.2,0.2,15,15,0,0,6); sp1.setColour(255,50,50); solid.setTransparency(0.5); tranny.setTransparency(0.5); sp1.setRenderer(solid); myWorld.enableTransparentObjects(); pid = myWorld.addObject(sp1); Light l1 = new Light(0,0,1); myWorld.addLight(l1); myWorld.prepNewObjects(); while (true) { myWorld.getParentObject(pid).rotateWorld(ddy,ddx,z); myWorld.redraw(); } } public boolean mouseDown(Event evt, int x, int y) { downx = x; downy = y; down = true; return true; } public boolean mouseUp(Event evt, int x, int y) { down = false; return true; } public boolean mouseDrag(Event evt, int x, int y) { if (down) { double dx = x - downx; double dy = y - downy; ddx = (dx / (this.size().width))*10.0; ddy = (dy / (this.size().height))*10.0; } return true; } public boolean keyDown(Event evt,int key) { if ((char)key=='a') {antialias=!antialias; myWorld.setAntiAliasing(antialias); return true; } if ((char)key=='b') {bilinear=!bilinear; myWorld.setBilinear(bilinear); return true; } if ((char)key=='t') { myWorld.getParentObject(pid).setRenderer(tranny); return true; } if ((char)key=='s') { myWorld.getParentObject(pid).setRenderer(solid); return true; } if ((char)key=='g') { myWorld.getParentObject(pid).getRenderer().setDrawingMode(Render.GOURAUD); return true; } if ((char)key=='f') { myWorld.getParentObject(pid).getRenderer().setDrawingMode(Render.FLAT); return true; } return true; } }