Java Reference
In-Depth Information
g3d = Graphics3D.getInstance();
g3d.resetLights();
// add a white ambient light at full intensity
Light light = new Light();
light.setMode(Light.AMBIENT);
light.setColor(0xffffff);
light.setIntensity(1.0f);
light.setRenderingEnable(true);
g3d.addLight(light, identity);
...
In M3G, many of the visual properties that describe a Mesh can be
specified using the Appearance class. This is a container class that holds
child objects such as Material (how the object responds to different
light colors), PolygonMode (shading model, winding and culling mode)
and Fog .
Once you're an experienced 3Dmodeler you can specify these features
during the design phase but for now we define them in code for two
reasons: it gives us the flexibility to experiment easily and it allows us to
demonstrate a very useful technique. A mesh is expensive to create and
takes up a fair bit of memory when you consider all the vertices, texture
coordinates, material data, and so on. So in a mobile game we want to
re-use the same mesh as much as possible.
In our sample game, the HiggsParticle class is a subclass of the
Mesh class. When a new attack is launched at the player consisting of,
say, 10 particles, we do not want 10 copies of the same mesh in memory.
What we can do instead is to use a single mesh and change the material
properties of its Appearance object. If we do this, we can simply render
the same mesh multiple times by specifying different transforms and
materials.
In Figure 8.3, you can see a large blue-green planet off in the distance
and a small red-orange orbiting planetoid at the lower right. The following
code snippet shows how, during game setup, we create materials and
transforms for each of these while re-using the same mesh:
// setup an Appearance object and Materials
private void setUpUniverse() {
appearance = sphere.getAppearance(0);
polygonMode = appearance.getPolygonMode();
polygonMode.setCulling(PolygonMode.CULL_BACK);
polygonMode.setShading(PolygonMode.SHADE_SMOOTH);
planetoidMaterial = new Material();
planetoidMaterial.setColor(Material.AMBIENT, 0x00ff8000);
planetoidMaterial.setColor(Material.DIFFUSE, 0xFF876A56);
planetoidMaterial.setColor(Material.SPECULAR, 0x00C0C0C0);
planetoidMaterial.setShininess(35.0f);
blueGreenMaterial = new Material();
blueGreenMaterial.setColor(Material.AMBIENT, 0x00000ff8);
blueGreenMaterial.setColor(Material.EMISSIVE, 0x0000002a);
Search WWH ::




Custom Search