Java Reference
In-Depth Information
allows a
World
to contain everything in a scene. The code from Listing 15-4 to load the
.m3g
file
is as follows:
World mWorld;
...
mWorld = (World) Loader.load("/pogoroo.m3g")[0];
Once a
World
is created, you can use some of its methods to obtain familiar objects. The
active
Camera
is obtained using this method:
Camera getActiveCamera();
The
Background
is obtained using this method:
Background getBackgroud();
In addition, the 3D modeling tool used to create the
.m3g
file will allow you to assign special
integer IDs to any
Object3D
subclass that you create. You can then use the
find()
method to
locate any object within the
World
:
Object3D find(int userID);
Retrieving the Active Camera in the Retained Mode World
In Listing 15-4, the
Camera
is retrieved from the
World
and moved to the front of the jumping
kangaroo. The following code from the
init()
method illustrates this:
mCam = mWorld.getActiveCamera();
mCam.translate(0, 0, -1.5f);
mCam.setOrientation(180, 0, 1, 0);
It is necessary to change the orientation of the
Camera
. Initially, the
Camera
is facing the
back of the kangaroo in the
World
defined within the
.m3g
file.
Rendering a Retained Mode World
Rendering a frame in retained mode is significantly simpler than in immediate mode. The code
in the rendering loop that follow is from Listing 15-4:
startTime = System.currentTimeMillis() - mWorldStartTime;
mWorld.animate((int)startTime);
mGraphics3D.bindTarget(g);
mGraphics3D.render(mWorld);
mGraphics3D.releaseTarget();
flushGraphics();
The
animate()
method on the
World
is called to animate the hopping kangaroo (using
predefined animation within the
World
). The entire
World
is rendered using the
Graphic3D
's
retained mode rendering method:
void render(World world);
Search WWH ::
Custom Search