Java Reference
In-Depth Information
tion is perhaps on specifying the texture coordinates as realistic objects usually have many
vertices.
The generation of texture coordinates can be performed automatically for objects cre-
ated from geometries in the utility class. An example is given in Figure 8, which shows
that, by using the optional argument Primitive.GENERATE_TEXTURE_COORDS in the
constructor in line 24, automatic generation of texture coordinates will be carried out.
Automatic generation of texture coordinates can also be carried out through the use
of TexCoordGeneration for any graphical object. Figure 9 shows how this is done and the
results obtained. The code segment is straightforward and the most crucial lines are from
lines 9 to 11, where a TexCoordGeneration object is created for reference by the appear-
ance bundle.
The first argument, TexCoordGeneration.OBJECT_LINEAR, in line 9 dictates the
use of an object based linear projection technique in the generation process. Another
linear projection method that can be selected is EYE_LINEAR, and the results for both
methods are shown. Under OBJECT_LINEAR, the texture supplied will rotate with the
object, whereas under the other mode, the texture will not rotate with the geometry and
will appear more stationary.
For applications where the visual object is spherical in nature and the texture image is
obtained from a fisheye lens, TexCoordGeneration offers yet another technique that may
be useful. As illustrated in Figure 10, this can be selected by specifying SPHERE_MAP
for sphere mapping. Clearly, under this mode, a visual effect that the object is reflecting
its surrounding can be obtained.
Figure 8. Code segment and result for Myearth.java
1.
Appearance createAppearance(String filename)
2.
{
3.
Appearance Appear = new Appearance();
4.
5.
System.out.println("attempt to load texture from file: "+filename);
6.
TextureLoader loader = new NewTextureLoader(filename);
7.
ImageComponent2D image = loader.getImage();
8.
if(image == null) System.out.println("load failed for texture: "+filename);
9.
10.
Texture2D texture = new Texture2D(Texture.BASE_LEVEL, Texture.RGBA,
11.
image.getWidth(), image.getHeight());
12.
texture.setImage(0, image);
13.
texture.setEnable(true);
14.
15.
texture.setMagFilter(Texture.BASE_LEVEL_LINEAR);
16.
texture.setMinFilter(Texture.BASE_LEVEL_LINEAR);
17.
18.
Appear.setTexture(texture);
19.
20.
return Appear;
21. }
22.
23.
Appearance appear = createAppearance("sun.gif");
24.
objSpin.addChild(new Sphere(0.5f, Primitive.GENERATE_TEXTURE_COORDS, appear));
Search WWH ::




Custom Search