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 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.