TSweep3D | GetContourList | GetTwistCurve | |
GetInitialContourXDirection | SetScalingCurve | ||
GetMatrix | SetInitialContourXDirection | ||
GetScalingCurve | SetTrajectory | ||
GetSurface | SetTwistCurve | ||
GetTrajectory |
The following code creates two sweeps and gets their surfaces. It uses the surfaces to create a series of tiles in a torus shape. The torus shown in Figure 167 has additional code to set up the camera, lighting, and shaders. See Chapter 16 for information on shaders, and Chapter 17 for information on camera and lighting.
1 long i, j; 2 const kNumSteps = 7; 3 4 TSweep3D * torusSweep = TTorus3D( 150, 75 ).CreateSweepSurface(); 5 TGSurface3D outerTorus = *torusSweep->GetSurface(); 6 delete torusSweep; 7 8 torusSweep = TTorus3D( 150, 65 ).CreateSweepSurface(); 9 TGSurface3D innerTorus = *torusSweep->GetSurface(); 10 delete torusSweep; 11 12 GParametric ustep = outerTorus.GetMaxParameter( TGSurface3D::kuDirection ) / kNumSteps; 13 GParametric vstep = outerTorus.GetMaxParameter( TGSurface3D::kvDirection ) / kNumSteps; 14 GParametric ugap = ustep / 5.0; 15 GParametric vgap = vstep / 5.0; 16 17 for ( i = 0; i < kNumSteps; i++) 18 for ( j = 0; j < kNumSteps; j++) 19 { 20 TGSurface3D topSection; 21 TGSurface3D botSection; 22 outerTorus.GetSectionOfSurface( ustep * i, ustep * (i + 1) - ugap, 23 vstep * j, vstep * (j + 1) - vg, topSection ); 24 25 innerTorus.GetSectionOfSurface( ustep * i, ustep * (i + 1) - ugap, 26 vstep * j, vstep * (j + 1) - vgap, botSection ); 27 28 TGSurface3D sideSection( topSection, botSection, 0.02, 0.02 ); 29 port->Draw( topSection ); 30 port->Draw( sideSection ); 31 32 botSection.ReverseDirection( TGSurface3D::kuDirection ); 33 port->Draw( botSection ); 34 }
Lines 12 through 15: Set up the gaps between the tiles.
Lines 17 through 26: Build the top and bottom sections.
Line 28: Create the side section, which is the edge between the top and bottom tiles. The 0.02 tangent values give slightly rounded corners on edges of the side section.
Lines 29 and 30: Draw the top and side sections.
Line 32: The bottom surface needs to be inside-out, since it faces inward.
Line 33: Draw the bottom section.