Java Reference
In-Depth Information
Having loaded the image, the created ImageComponent2D object must be added to the
appropriate appearance bundle. The code segment from lines 4 to 7 in Figure 1 illustrates
how this can be done.
texture coordInates
After loading the texture image and adding the created texture object to an appearance,
we will now need to specify the texture coordinates that will be applied to each of all the
vertices of the geometry object. This serves to define the 2D mapping that maps the 2D
texture image to each face of the geometry object.
The texture coordinate is specified in the form of normalized (x, y) units, where (0, 0)
is the bottom left corner and (1, 1) is the top right corner of the texture image. Using one
of the several setTextureCoordinates methods, the code segment in Figure 2 illustrates
how these coordinates can be specified and the result obtained in a simple example. The
geometry is a 2D plane created using quad array, while the texture image consists of three
compasses arranged in a row. The specification of the texture coordinates in the code
segment is such that the entire texture image will be mapped to the entire 2D geometrical
plane. It is therefore the most straightforward mapping with no rotation and distortion of
the texture image.
To illustrate this mapping of the texture image to a surface more clearly, Figure 3 shows
a more complicated example where a rectangular texture image is mapped to a triangular
geometrical surface. The texture image consists of a red circle in blue background in a jpg
file. As can be seen, the specification of the texture coordinates as shown lead to a non-
linear mapping and the red circle becomes distorted.
Figure 2. Specifying texture coordinates without any distortion for a quad array plane
Plane = new TextPlane("");
quad = (QuadArray) Plane.getGeometry();
quad.setTextureCoordinate(0, new Point2f( 1.0f, 1.0f));
quad.setTextureCoordinate(1, new Point2f( 1.0f, 0.0f));
quad.setTextureCoordinate(2, new Point2f( 0.0f, 0.0f));
quad.setTextureCoordinate(3, new Point2f( 0.0f, 1.0f));
Search WWH ::

Custom Search