Java Reference
In-Depth Information
4.
Use the M3G API to set up and update the 3D scene.
Call one of the render() methods of Graphics3D to render a frame of the 3D scene.
5.
6.
Call the Graphics3D 's releaseTarget() method to flush the rendered image to the
2D Graphics .
Call the 2D Graphic 's flushGraphics() method to flush the drawing and update the
visible component with the rendered frame.
7.
The typical usage of M3G for 3D graphics rendering is very similar to a 2D game loop.
When used in conjunction with a GameCanvas , it will look like the following:
Graphics g = getGraphics();
Graphics3D g3d = Graphics3D.getInstance();
while(true) {
g3d.bindTarget(g);
// ...
// Perform setup of the 3D scene to render.
// ...
g3d.render(...);
mGraphics3D.releaseTarget();
flushGraphics();
}
If you compare the preceding rendering loop to the one used in the last chapter, in which
we discussed the Game API, you will understand that it is essentially the same. The only exception
is that now the M3G API is used to draw the graphics that will be displayed onto the 2D Canvas .
In fact, this is the very essence of the M3G API: it is used to draw graphics that represent a 3D scene
onto a 2D display area.
The M3G API encompasses many classes. Instead of covering all the details of every class
in the confines of this chapter, only the foundations will be introduced. There will be three
examples that allow you to see the API in action. These examples are designed for easy modifi-
cation and experimentation with the full API.
To introduce some basic 3D graphics concepts and to cut through a bunch of frequently
used M3G APIs, we'll start immediately with an example.
Getting Started with 3D
Many developers think that programming 3D graphics requires great mathematical skills. In
reality, APIs such as M3G enable developers with little mathematical background to participate
in the exciting world of 3D application programming.
Search WWH ::




Custom Search