< Zurück | Inhalt | Weiter >

EYE_LINEAR mode


The EYE_LINEAR texture coordinate generation mode is very similar to the OBJECT_LINEAR mode with one important difference. The positions of vertices in their local coordinate system are no longer used; rather the positions of vertices in the world coordinate system are used instead. This has major consequences—as the landscape is moved within the VirtualUniverse, the texture coordinates of the vertices within the landscape are recomputed, for example, in the TexCoordTest example, by simply modifying the construction of the TexCoordGeneration object to be:


TexCoordGeneration texGen =

new TexCoordGeneration( TexCoordGeneration.EYE_LINEAR,

TexCoordGeneration.TEXTURE_COORDINATE_2, new Vector4f( 0,

(float)

(1.0/(2 * yMaxHeight)), 0,

0.5f ),

new Vector4f( 0,0,0,0 ), new Vector4f( 0,0,0,0 ) );


We define a VirtualUniverse where the texture coordinate of the landscape is calculated from the y coordinate of the landscape in the VirtualUniverse’s coordinate system. In essence we have defined a band of texture coordinates (color) that ranges from –yMaxHeight to +yMaxHeight. When the landscape falls inside this range, it will have a texture coordinate applied to it.


In mathematical terms, this is equivalent to multiplying each vertex coordinate by the result of calling

Shape3D.getLocalToVworld before computing the texture coordinate using:


s texture coordinate = (0.0 * vertex x) + (1.0/ 2 * yMaxHeight * vertex y) + (0.0 * vertex z) + 0.5;

Using the EYE_LINEAR mode allows you to define a field of texture coordinates that can produce dynamic contour lines on moving objects.


image


Figure 14.9 Using EYE_LINEAR texture coordinate generation. As the landscape is translated upward in the y axis, the texture coordinates change, resulting in a different frame. In the left−hand frame, only the peaks of the landscape are above the y = 0 plane; the rest of the landscape is either texture mapped with the water section of the texture image or does not have any texture applied since the calculated texture coordinate is less than 0.0. In the right−hand frame, most of the landscape is above the y = 0 plane, and only the deepest hollows in the landscape are textured using the water section of the texture image