14
Nov
Each fWorld keeps track of its own time
In the following example you will see how you can use the core by extending the cornerstone classes. You should read the description and look at the code at the same time to get the most out of it. The headers for the core classes mentioned can be found on the CD-ROM. We will first extend the generic fMovingObject with a BouncingBox object. After that the fWorld class will be extended by the BouncingBoxWorld. Finally, these classes will be put together in an applet. We will start by looking at how the generic core class fMovingObject can be extended to make a bouncing box, as shown in Listing 12-1 and Figure 12-3. Listing 12-1 The bouncing box 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)); //– //– 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.y Hint: This post is supported by Gama hrvatski web hosting services
