Skip Headers
Oracle® Java Micro Edition Software Development Kit Developer's Guide
Release 3.3 for Eclipse on Windows
E37550-03
  Go To Table Of Contents
Contents
Go To Index
Index

Previous
Previous
 
Next
Next
 

21 JSR 184: Mobile 3D Graphics

The Mobile 3D Graphics API (JSR 184) provides 3D graphics capabilities with a low-level API and a high-level scene graph API. This chapter provides a brief overview and general guidelines for working with JSR 184.

JSR 184 is a specification that defines the Mobile 3D Graphics (M3G) API for Java ME. This API provides 3D functionality in a compact package that's appropriate for CLDC/MIDP devices. The API provides two methods for displaying 3D graphics content:

For more information, consult the JSR 184 specification at http://jcp.org/en/jsr/detail?id=184.

21.1 Choosing a Graphics Mode

Applications are free to use whichever approach is most appropriate or to use a combination of the retained mode and immediate mode APIs.

JSR 184 provides a standard API for CLDC/MIDP devices, enabling a new generation of 3D applications. The immediate mode API, in turn, is compatible with OpenGL ES, a standard lightweight API for 3D graphics. See http://khronos.org/ for more information on OpenGL ES.

21.1.1 Immediate Mode

Immediate mode is appropriate for applications that generate 3D graphics content algorithmically, such as scientific visualizations or statistical graphs. The application creates 3D objects and manipulates them directly.

For an example of immediate mode, see the Life3D MIDlet in the Demo3D example application.

21.1.2 Retained Mode

Most applications, particularly games, use the retained mode or scene graph API. In this approach, a graphic designer or artist uses 3D modeling software to create a scene graph. The scene graph is saved in the JSR 184 file format. The scene graph file is bundled with the application. At runtime, the application uses the scene graph API to load and display the file.

Applications can manipulate parts of a loaded scene graph to animate characters or create other effects. The basic strategy is to do as much work as possible in the modeling software. At runtime, the application can grab and manipulate parts of the scene graph, which can also include paths for animation or other effects.

For an example of retained mode, see the retainedmode MIDlet in the Demo3D example application.

21.2 Quality Versus Speed

One of the challenges of MIDP development is the constrained environment of typical devices. Compared to desktop computers, MIDP devices have slow processors and little memory. These challenges extend into the arena of 3D graphics. To accommodate a wide variety of implementations, the JSR 184 specification provides various mechanisms to make the display of a 3D scene as efficient as possible.

One approach is scoping, a technique where you tell the 3D graphics implementation when objects are not going to interact with each other. For example, if you defined a scene graph for a house, you could use scoping to specify that the light in the basement does not affect the appearance of the bedroom on the second floor. Scoping simplifies the implementation's task because it reduces the number of calculations required to show a scene.

In general, the best way to improve the rendering speed of 3D scenes is to make some compromises in quality. The Mobile 3D Graphics API includes rendering hints so that applications can suggest how the implementation can compromise quality to improve rendering speed.

21.3 Content for Mobile 3D Graphics

Most mobile 3D applications use scene graphs in resource files to describe objects, scenes, and characters. Usually it is not programmers but graphic designers or artists who create the scene graphs, using standard 3D modeling tools.

Several vendors offer tools for authoring content and converting files to the JSR 184 format.

Because it is relatively difficult to create and manipulate 3D graphics content in an application using the immediate mode API, most applications rely as much as possible on a scene graph file. By putting as much as possible into the scene graph file at design time, the application's job at runtime is considerably simplified.

21.4 Running Demo3D Samples

Demo3D contains MIDlets that demonstrate JSR 184 features.

Select File > New > Project.... In the Categories window, click Example and select Java ME Sample Applications. Then single-click Demo3D and click Next. Specify a name and location and click Finish.

21.4.1 Life3D

Life3D implements the popular Game of Life in three dimensions. Live cells are represented by cubes. Each cell has 26 possible neighbors (including diagonals). For each step of the animation, cells with fewer than four neighbors die of loneliness, while cells with more than five neighbors die of overcrowding. An empty cell with exactly four neighbors becomes a new live cell.

The view of the playing board rotates slowly so you can view the board from all angles.

The keypad buttons in Table 21-1 provide control over the game.

Table 21-1 Controls for Life3D

Button Description

0

Pause the animation.

1

Resume the animation at its default speed.

2

Speed up the animation.

3

Slow down the animation.

4

Choose the previous preset configuration from an arbitrary list. The name of the configuration is shown at the top of the screen.

5

Choose the next preset configuration from the list.

*


Generate a random configuration and animate until it stabilizes or dies. If it dies, generate a new random configuration.


The source code for this example can be found at:

projects\Demo3D\src\com\superscape\m3g\wtksamples\life3d\Life3D.java

Where projects is the directory you are using to store your Eclipse projects.

21.4.2 RetainedMode

The RetainedMode MIDlet plays a scene file that shows a skateboarder in an endless loop. The source code is found at:

projects\Demo3D\src\com\superscape\m3g\wtksamples\retainedmode

21.4.3 PogoRoo

PogoRoo displays a kangaroo bouncing up and down on a pogo stick. To steer the kangaroo, use the arrow keys. Press up to go forward, down to go backward, and left and right to change direction. Try holding down the key to see an effect. The source code is found at:

projects\Demo3D\src\com\superscape\m3g\wtksamples\pogoroo