# SpatialED.TarquinPanoramaBuilder

00001 00002 00003 00004 00005 00006 00007 00008 00009 00010 00011 00012 00013 00014 00015 00016 00017 00018 00019 00020 00021 00022 00023 00024 00025 00026 00027 00028 00029 00030 00031 00032 00033 00034 00035 00036 00037 00038 00039 00040 00041 00042 00043 00044 00045 00046 00047 00048 00049 00050 00051 00052 00053 00054 00055 00056 00057 00058 00059 00060 00061 00062 00063 00064 00065 00066 00067 00068 00069 00070 00071 00072 00073 00074 00075 00076 00077 00078 00079 00080 00081 00082 00083 00084 00085 00086 00087 00088 00089 00090 |
    //=============================================================================
    // Spatial Fear
    // Class: TarquinPanoramaBuilder
    // Description: builds a set of sheets in an open tube: to make landscapes in
    //				the skybox.
    //
    // Author: Tarquin
    // + Used with permission for packaging with SpatialED v2.1
    //=============================================================================
    class TarquinPanoramaBuilder
    	expands BrushBuilder;

    var() float Height, PanelWidth, Radius;
    var() int Sides, PanelsPerSide;
    var() bool AlignToSide;
    var() name GroupName;

    function bool Build()
    {
    	local int i, j, k;
    	local vector BaseVector, SideVector, HeightVector;
    	local rotator SpinTransformation;

    	// ^^^^^^^^^^^^^^^^^^^^ check user input
    	if( Sides < 3 || PanelsPerSide < 1 )
    		return BadParameters("Must have at least three sides and one panel per side.");
    	if( Height <= 0 )
    		return BadParameters("Height must be positive.");
    	if( PanelWidth < 0 || Radius < 0 )
    		return BadParameters("PanelWidth or Radius may not be negative.");
    	// we ensure we have ONE positive, ONE zero.
    	if( ! ( PanelWidth == 0 ^^ Radius == 0 ) )
    		return BadParameters("Set either the PanelWidth, or the Radius. Whichever you want the builder to ignore, set to zero. You cannot set both!");
    	// ^^^^^^^^^^^^^^^^^^^^ define some new variables. leave user entered data intact
    	if( Radius > 0 )
    		BaseVector.x = Radius ;
    	else
    		BaseVector.x = ( PanelWidth * PanelsPerSide / 2 ) / sin( pi / Sides ) ;
    	HeightVector.z = Height ;
    	SpinTransformation.Yaw = 65536.0f / Sides ;

    	// user entered radius/width, height, sides converted to vector / rotator; modify them if aligned to side
    	if ( AlignToSide )
    	{
    		if( Radius > 0 )
    			BaseVector.x /= cos( pi / Sides ) ;
    		// perceptual shift: a/!a leads to essentially diff r, but same w will be expected
    		BaseVector = BaseVector >> ( SpinTransformation / 2 ) ;
    		// set the new effective radius to a corner. Then spin the vector so it points to first corner.
    	}

    	SideVector = ( ( BaseVector >> SpinTransformation ) - BaseVector ) / PanelsPerSide ;

    	BeginBrush( false, GroupName );

    	// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ build vertices
    	for( k = 0 ; k < 2 ; k++ )
    		for( j = 0 ; j < Sides ; j ++ )
    			for( i = 0 ; i < PanelsPerSide ; i ++ )
    				Vertexv(
    					k * HeightVector
    					+ ( ( BaseVector + i*SideVector ) >> ( SpinTransformation * j ) )
    					);
    	// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ build polys
    	for( i = 0 ; i < Sides * PanelsPerSide ; i++ )
    	{
    		Poly4i( 1,
    			i,
    			i + ( Sides * PanelsPerSide ),
    			(( i+1 )%(Sides * PanelsPerSide)) + Sides * PanelsPerSide ,
    			( i+1 )%(Sides * PanelsPerSide) ,
    			'panorama',
    			0x00000108 );// flags for sheet, two-sided.
    			// the order of vertices is important: produces inner-facing polys, right way up.
    	}
    	return EndBrush();
    }

    defaultproperties
    {
         Height=128.000000
         PanelWidth=128.000000
         Sides=4
         PanelsPerSide=2
         AlignToSide=True
         GroupName=Skybox
         BitmapFilename="SFEDBBTarquinPanorama"
         ToolTip="Skybox Builder"
    }

class file time: 12/7/2003 3:58:26 PM - creation time: 12/7/2003 4:03:46 PM
Created with UnCodeX