// (C) 2001 SyGem Software import java.awt.*; import java.applet.*; import com.sygem.jazz3d3.*; import com.sygem.jazz3d3.primitive.Cube3d; public class animatedBackgrounds extends Applet implements Runnable { Thread m_ce; World myWorld; int light1; int pid; 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 animatedBackgrounds() { } //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; int tt = 0; myWorld.prep(); RenderTextured texture_mapper = new RenderTextured(); Texture bgTex[] = new Texture[7]; painter(1); String temp = "images/koli/koli0.gif"; Texture tx = TextureLoader.loadImage(temp); bgTex[0] = tx; painter(2); String temp1 = "images/koli/koli1.gif"; Texture tx1 = TextureLoader.loadImage(temp1); bgTex[1] = tx1; painter(3); String temp2 = "images/koli/koli2.gif"; Texture tx2 = TextureLoader.loadImage(temp2); bgTex[2] = tx2; painter(4); String temp3 = "images/koli/koli3.gif"; Texture tx3 = TextureLoader.loadImage(temp3); bgTex[3] = tx3; painter(5); String temp4 = "images/koli/koli4.gif"; Texture tx4 = TextureLoader.loadImage(temp4); bgTex[4] = tx4; painter(6); String temp5 = "images/koli/koli5.gif"; Texture tx5 = TextureLoader.loadImage(temp5); bgTex[5] = tx5; painter(7); String temp6 = "images/koli/koli6.gif"; Texture tx6 = TextureLoader.loadImage(temp6); bgTex[6] = tx6; texture_mapper.setTexture(tx); texture_mapper.setTexture(tx1); texture_mapper.setTexture(tx2); texture_mapper.setTexture(tx3); texture_mapper.setTexture(tx4); texture_mapper.setTexture(tx5); texture_mapper.setTexture(tx6); Cube3d cube = new Cube3d(0,0,8); cube.setRenderer(texture_mapper); pid = myWorld.addObject(cube); Light l1 = new Light(0,0,1); myWorld.addLight(l1); myWorld.prepNewObjects(); while (true) { myWorld.setBackground(bgTex[tt]); myWorld.getParentObject(pid).rotateWorld(ddy,ddx,z); ((RenderTextured)(myWorld.getParentObject(pid).getRenderer())).setTexture(tt++); if (tt > 6) tt = 0; myWorld.redraw(); } } void painter(int i) { myWorld.prepareCanvas(); myWorld.drawImage(); Graphics g = myWorld.getCanvas(); g.setColor(new Color(255,0,0)); g.drawString("Loading image "+i,20,80); myWorld.finishCanvas(); } 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; } // Also add some code for moving camera? return true; } }