Java Reference
In-Depth Information
install Python (at least v2.5.x) and you need to copy m3g_export.py to
your blender script directory - normally C: \ Program Files \ Blender
Foundation \ Blender \ .blender \ scripts .
When that is working you can create entire 3D worlds and easily use
them in Java MIDlets by using the static Loader class which de-serializes
a stream of classes that derive from Object3D into a convenient array.
In the sample game, we use a sphere mesh to represent distant planets
and orbiting objects. Below is the code which shows how the sphere
model shown in Figure 8.8 is loaded from the M3G file into the MIDlet
proper:
Mesh sphere;
private void loadModels() {
Object3D[] objects = null;
try objects = Loader.load(... + "sphere.m3g");
World world = null;
// find the world node first
for(int i = 0; i < objects.length; i++) {
if(objects[i] instanceof World) {
world = (World) objects[i];
break;
}
} if(world != null) {
for(int i = 0; i < world.getChildCount(); i++) {
Node node = world.getChild(i);
if(node instanceof Mesh) {
sphere = (Mesh) node;
break;
}
} if(sphere != null) {
setUpUniverse();
}
...
Before we can draw anything with M3G we need to set up our graphics
environment. Since this game is a first-person-shooter game, we always
position the camera at the point of view of the player. In this case, our
model only includes the sphere mesh so we have to add our own camera
and lights during setup:
private void initialiseGraphics(float width, float height) {
// set up a camera
camera = new Camera();
// set up a 60 degree FOV
camera.setPerspective(60.0f, width / height, 0.1f, ...);
...
// set up basic lighting
Search WWH ::




Custom Search