home *** CD-ROM | disk | FTP | other *** search
/ Game Level Design / GLDesign.bin / Software / UnrealEngine2Runtime / UE2Runtime-22262001_Demo.exe / Editor / Classes / CylinderBuilder.uc < prev    next >
Text File  |  2003-10-22  |  2KB  |  77 lines

  1. //=============================================================================
  2. // CylinderBuilder: Builds a 3D cylinder brush.
  3. //=============================================================================
  4. class CylinderBuilder
  5.     extends BrushBuilder;
  6.  
  7. var() float Height, OuterRadius, InnerRadius;
  8. var() int Sides;
  9. var() name GroupName;
  10. var() bool AlignToSide, Hollow;
  11.  
  12. function BuildCylinder( int Direction, bool AlignToSide, int Sides, float Height, float Radius )
  13. {
  14.     local int n,i,j,Ofs;
  15.     n = GetVertexCount();
  16.     if( AlignToSide )
  17.     {
  18.         Radius /= cos(pi/Sides);
  19.         Ofs = 1;
  20.     }
  21.  
  22.     // Vertices.
  23.     for( i=0; i<Sides; i++ )
  24.         for( j=-1; j<2; j+=2 )
  25.             Vertex3f( Radius*sin((2*i+Ofs)*pi/Sides), Radius*cos((2*i+Ofs)*pi/Sides), j*Height/2 );
  26.  
  27.     // Polys.
  28.     for( i=0; i<Sides; i++ )
  29.         Poly4i( Direction, n+i*2, n+i*2+1, n+((i*2+3)%(2*Sides)), n+((i*2+2)%(2*Sides)), 'Wall' );
  30. }
  31.  
  32. function bool Build()
  33. {
  34.     local int i,j;
  35.  
  36.     if( Sides<3 )
  37.         return BadParameters();
  38.     if( Height<=0 || OuterRadius<=0 )
  39.         return BadParameters();
  40.     if( Hollow && (InnerRadius<=0 || InnerRadius>=OuterRadius) )
  41.         return BadParameters();
  42.  
  43.     BeginBrush( false, GroupName );
  44.     BuildCylinder( +1, AlignToSide, Sides, Height, OuterRadius );
  45.     if( Hollow )
  46.     {
  47.         BuildCylinder( -1, AlignToSide, Sides, Height, InnerRadius );
  48.         for( j=-1; j<2; j+=2 )
  49.             for( i=0; i<Sides; i++ )
  50.                 Poly4i( j, i*2+(1-j)/2, ((i+1)%Sides)*2+(1-j)/2, ((i+1)%Sides)*2+(1-j)/2+Sides*2, i*2+(1-j)/2+Sides*2, 'Cap' );
  51.     }
  52.     else
  53.     {
  54.         for( j=-1; j<2; j+=2 )
  55.         {
  56.             PolyBegin( j, 'Cap' );
  57.             for( i=0; i<Sides; i++ )
  58.                 Polyi( i*2+(1-j)/2 );
  59.             PolyEnd();
  60.         }
  61.     }
  62.     return EndBrush();
  63. }
  64.  
  65. defaultproperties
  66. {
  67.     Height=256
  68.     OuterRadius=512
  69.     InnerRadius=384
  70.     Sides=8
  71.     GroupName=Cylinder
  72.     AlignToSide=true
  73.     Hollow=false
  74.     BitmapFilename="BBCylinder"
  75.     ToolTip="Cylinder"
  76. }
  77.