import java.net.*; import java.io.*; import java.applet.*; import java.util.*; import java.awt.*; class BouncingBox extends fMovingObject{ BouncingBox(fWorld w, fPoint3d p ) { //-- construct the base class super(w, p, new fAngle3d(0,0,0), new fPoint3d(0,0,0), new fAngle3d(0,Math.PI,0)); // new fAngle3d(0, 0, 0)); //-- //-- every non-abstract object MUST have a polyhedron instance. //-- this line of code MUST be somewhere in the constructor //-- usePolyhedronInstance (new fPolyhedronInstance (ourDefaultPolyhedron,ourScale)); } //-- override the update method public void update (double dt) { //-- always let the base class do the default action for //-- an overridden method. Never forget this! super.update(dt); //-- retrieve the position and velocity of the box fPoint3d dp=getdPosition(); fPoint3d p=getPosition(); //-- check if the box has hit the ground if(p.y0.2) dt=0.2; angle += Math.PI / 1000; x = Math.sin(angle) * radius; z = Math.cos(angle) * radius; camera.setOrientation(new fPoint3d(x, y, z), new fAngle3d(0, angle, 0) ); world.update(dt); camera.update(dt); //-- to speed up the repaint we tell the Applet to update //-- directly instead of calling repaint if(getPeer()==null) return; System.out.println("I am alive..."); Graphics g=getGraphics(); if(g==null) return; Dimension dim=size(); if(dim.width==0 || dim.height==0) return; update(g); } System.out.println("My alive is " + alive); } public void start () { if(myThread==null){ myThread=new Thread(this); myThread.start(); alive=true; } } public void paint(Graphics g){ //-- update the screen size for the camera camera.setScreenSize(size().width,size().height); //-- erase the screen g.clearRect(0,0,size().width,size().height); //-- paint the world camera.paint(g); } public void stop () { if(myThread!=null){ myThread.stop(); myThread=null; alive=false; } } }