Java Reference
In-Depth Information
attributes tell M3G how much of the scene needs to be computed and rendered; anything
outside of the field of view and clipping panes is not computed.
The following code from Listing 15-1 sets up the Camera to have a 60-degree field of view
(controls how much of the scene you can see), an aspect ratio that is the same as the Canvas ,
and two clipping panes that allow you to see the entire triangle when it is rotated.
mCamera.setPerspective( 60.0f, (float)getWidth()/ (float)getHeight(),
1.0f, 1000.0f );
mLight.setColor(0xffffff);
mLight.setIntensity(1.25f);
Like a Camera , a Light is an M3G object that has a position and an orientation. It can also
have other attributes such as a color, different modes (for example, spotlight versus diffused
light), intensity, etc. Here, the color of our light is set to white (RGB 0xffffff ), and its intensity
is set to slightly brighter than default (default is a directional spotlight with an intensity of 1).
Transforms: Moving 3D Objects About
Each frame of a 3D animation is rendered through an iteration of the while loop within the
run() method. A fragment of the code from this loop is reproduced here:
mGraphics3D.bindTarget(g);
mGraphics3D.clear(mBackground);
mTransform.setIdentity();
mTransform.postTranslate(0.0f, 0.0f, 10.0f);
mGraphics3D.setCamera(mCamera, mTransform);
mGraphics3D.resetLights();
mGraphics3D.addLight(mLight, mTransform);
Here is what is happening in the code:
First, the Graphics3D instance is bound to the Canvas 's Graphics context.
Next, the Background is cleared out.
•Then the Camera and Light are moved around the scene.
Transform is an M3G object that can be used to move objects around the 3D world. To
those familiar with 3D math, this type of object actually encapsulates a 4×4 matrix that will be
multiplied with the coordinates of a 3D mesh to achieve scaling, translation, rotation, and
orientation. However, it is not necessary to know the mathematical details to work with a
Transform . A Transform has the following methods:
void setScale(float sx, float xy, float sz);
void setTranslation(float tx, float ty, float tz);
void preRotate(float angle, float ax, float ay, float az);
void postRotate(float angle, float ax, float ay, float az);
void setOrientation(float angle, float ax, float ay, float az);
Search WWH ::




Custom Search