Texture mapping matrix

A texture is a pattern created by modulating a surface property such as color or intensity. The texture is mapped to the inside or outside surface of a 3D graphic so that the texture appears attached to the surface from all views of the graphic and enhances the visual richness of the 3D graphic. Information on creating and using texture maps is under the heading "Shaders and Texture maps" on page 310.

A texture mapping matrix, by default, is the identity matrix and causes the texture map to have a onetoone correspondence with the inside or outside surface to which it is applied. You can define the texture mapping to be any 3D matrix you wish. Figure 205 shows the TGrafBundle3D functions for the texture mapping matrix.


The following code example creates a matrix and calls the TGrafMatrix3D::ScaleBy function with a value of 2. When the matrix is passed to the SetTextureMappingMatrix function, the (u,v) coordinates of the texture map shader are put through the matrix and then mapped to the (u,v) coordinates of the surface. This process changes the appearance of the texture map on the surface.

    1  TGrafMatrix3D aMatrix;
    2  aMatrix.ScaleBy( TGPoint3D( 2, 2, 2) );
    3  
    4  TGrafBundle* matrixBundle = new TGrafBundle(new TRGBColor( 0, 1, 0 ),
    5                                          TAttributeState::kFill );
    6  matrixBundle.SetTextureMappingMatrix( aMatrix );
    7  
    8  TGLoop contour( TGEllipse( TGRect( 0, 0, 200, 200 ) ) );
    9  contour.ReverseDirection();
    10  
    11  TGCurve3D trajectory( TGPoint3D( 100, 0 , 100 ), 
    12                      TGPoint3D( 100, 50, 100 ), 
    13                      TGPoint3D( 100, 75, 100), 
    14                      TGPoint3D( 100, 100, 100 ) );
    15  
    16  TSweep3D simpleSweep( contour, trajectory, TGPoint3D( 1, 0, 0 ) );
    17  simpleSweep.AdoptBundle( matrixBundle );
    18  
    19  TGPolygon polygonGeometry;
    20  polygonGeometry.Append( TGPoint( 25, 0 ) );
    21  polygonGeometry.Append( TGPoint( 0, 00 ) );
    22  polygonGeometry.Append( TGPoint( 50, 50 ) );
    23  TPolygon* triangle = new TPolygon( polygonGeometry );
    24  
    25  TA8R8G8B8Image image( TGPoint( 0, 0 ), 50, 50, TGImage::k72DPI );
    26  TGrafPort* imagePort = image.GetGrafPort();
    27  triangle->Draw( *imagePort );
    28  
    29  TBumpTextureMap bumpTexture( image );
    30  TBumpMapShader* bumpMapShader = new TBumpMapShader( bumpTexture );
    31  matrixBundle->AdoptOutsideShader( bumpMapShader );
    32  
    33  simpleSweep.Draw( thePort );
Lines 1 through 6: Create a matrix and a bundle. Adopt the matrix to the bundle as the texture mapping matrix.

Lines 8 through 17: Create a hollow cylinder sweep and adopt the matrix bundle.

Lines 19 through 27: Create a triangle image to use for a bump map texture.

Lines 29 through 33: Adopt the image to a bump texture map, adopt the texture map to a bump map shader, adopt the shader to the matrix bundle, and draw the sweep.


[Contents] [Previous] [Next]
Click the icon to mail questions or corrections about this material to Taligent personnel.
Copyright©1995 Taligent,Inc. All rights reserved.

Generated with WebMaker