Java Reference
In-Depth Information
VertexBuffer verbuf = mVertexBuffer = new VertexBuffer();
verbuf.setPositions(vertexArray, 1.0f, null);
verbuf.setNormals(normalsArray);
The two methods used in VertexBuffer are as follows:
void setPositions(VertexArray position, float scale, float [] bias);
void setNormals(VertexArray normals);
The setPositions() method has a scale and bias that can be used to modify the position
values. Since the input values are integer values (in the VertexArray ), using a float scale and a
float bias allow you to convert these values into floating point numbers. This is one example of
a computation optimization used in M3G to cater for the limitations (that is, little or no hardware
support for floating-point calculations) of mobile devices. If you do specify a scale and bias ,
the scale will be used to multiply each of the three coordinates by; the bias is a three-element
array, whereby the element values will be added to the x, y, and z components, respectively.
Note Specifying a float scale and bias can substantially slow down operations with a large
VertexBuffer if the device in question does not have hardware floating-point support.
In Listing 15-1, no scaling or bias is used (by specifying a scale of 1 and null for bias).
Defining a Submesh with a TriangleStripArray
An object that can be rendered in M3G is contained in a submesh. In M3G 1.0, the only submesh
available is a TriangleStripArray . The TriangleStripArray itself is a subclass of an IndexBuffer .
An IndexBuffer , as its name implies, contain indices. An IndexBuffer is associated with a
VertexBuffer ; the indices contained in the IndexBuffer refer to the associated VertexBuffer .
Specifically, the members of a TriangleStripArray tell M3G where the triangle strips are within
the VertexBuffer . In Listing 15-1, the TriangleStripArray is defined with this code:
int[] stripLength = { 3 };
mIndexBuffer = new TriangleStripArray( 0, stripLength );
This tells M3G that only one single triangle is defined in the submesh, it starts at the index 0 in
verbuf , and the number of indices occupied by this triangle is 3. In other words, M3G will use
the first three indices in the verbuf VertexBuffer to render the object.
Giving Your Submesh an Appearance
In Listing 15-1, the code that associates an appearance with the triangle submesh is as follows:
Material mMaterial = new Material();
Appearance mAppearance = new Appearance();
Background mBackground = new Background();
....
 
Search WWH ::




Custom Search