[BoxTrix PIC] Chapter 12.   Introducing 3D with JSR 239


Agent Psmith: Did you know that our first 3D application, the Beatrix, was designed to be a perfect world? Where none suffered, where everyone would be happy. Jemima Puddle-Duck, Squirrel Nutkin, Benjamin Bunny. It was a disaster. No one would accept the program. Entire crops were lost. Some believed we lacked the programming language to describe your perfect world. Then came Java ME, JSR 239, and Khronos.

Oreo: Isn't that from The Incredibles?

Agent Psmith. We succeeded with our second 3D world—the Dominatrix. She's all around us. Even now, in this very room. You can see her when you look out your window or when you turn on your television, if you have the right cable package.

Drano: That sounds like a really good deal.

Agent Psmith: Choose to take this blue berry, the story ends, you wake up in your bed and believe whatever you want to believe. You take the BlackBerry, you stay in Wonderland, and I show you how deep the rabbit hole goes.

Bozo: Whoa.


With the release of the BlackBerry Java Application Development v5.0 beta 5 software, we finally get to play with a 3D API -- a Java binding for OpenGL ES, called JSR 239. In this chapter, I'll describe a simple 3D scene coded with JSR 239, grandly termed the BoxTrix. Don't get your hopes up too high; it's essentially an animation loop inside a thread, which repeatedly updates the application's state, renders the 3D scene, and perhaps sleeps for a while so the animation can maintain the desired frame rate. The rendering is done to an offscreen buffer that is painted to the BlackBerry's screen using the familiar paint() method. This chapter also shows how to:

Unfortunately, no one can be told what the BoxTrix is. You have to see it for yourself. The picture at the top of this page shows a screenshot.

Two textured boxes continuously rotate around the y-axis; the one with the green lines is centered at the origin, while the metallic cube orbits some distance above the floor. A cube's texture is repeated on each of its faces.

The floor is covered with a grass texture. The figure and tree are billboards that always stay facing the camera.

The text at the top left is drawn as a 2D overlay, which keeps it "pinned" to the screen in front of the changing 3D scene. The red text is positional and rotational information about the camera, the blue text is the camera's current mode (there are three possibilities), and the black number is how long the current frame took to render in milliseconds.




Dr. Carol Hamer
E-mail: carol.hamer@gmail.com
To Carol's blog

Dr. Andrew Davison
E-mail: ad@fivedots.coe.psu.ac.th
To Andrew's home page