Figure 14.4 The TextureTest example loads an image
Figure 14.4 The TextureTest example loads an image and a list of texture coordinates and displays a portion of the image in a 3D scene by texture mapping it onto a TriangleArray The x, y columns are the pixel locations in the image that are returned by a bitmap editor. The origin for these 2D coordinates is at the top-left of the image. The x’ and y’ coordinates compensate for this by flipping the y coordinate (y’ = height y). The texture coordinates tx and ty are suitable for Java 3D (tx = x’/width and ty = y’/height). It is very easy to perform the coordinate conversions using a spreadsheet. The ASCII file is therefore: daniel.gif (name of the image file) 5 (size in the x direction) 1.0 (y scale factor) 13 (number of texture coordinates) 0.40 0.75 (texture coordinate 1, x y) 0.31 0.69 0.28 0.59 0.26 0.39 0.30 0.24 0.45 0.09 0.55 0.09 0.66 0.16 0.72 0.28 0.74 0.49 0.70 0.67 0.63 0.74 0.52 0.76 (texture coordinate 13, x y) The Microsoft Excel spread sheet file daniel coords.xls with the TextureTestexample contains the formulae necessary for the coordinate transformation (figure 14.5). 232
Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost Java Web Hosting services