Sweeps

TSweep3D lets you create cylinders, cones, spheres, rotation sweeps, rounded boxes, rounded cylinders, tori, linear sweeps, and flat surfaces for creating 3D polygons and ellipses without your needing to understand the details of surface geometry. The CreateSweepSurface creates the surface on which a sweep is based. The code example below creates sweeps and gets the surface geometry to model a torus created from a series of tiles. See Chapter 15 for code examples and descriptions on how to create the many kinds of available sweeps.

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 4 through 10: Create two torus sweeps and their sweep surfaces. Retrieve the surfaces.

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.


[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