//the high tower to the center

#declare TW_BldColor = color srgb 0.5;
#declare TW_GlassColor = color srgb < 1, 1, 1 > filter 0.5 transmit 0.5;
#declare TW_NecklaceColor = color srgb 1;
#declare TW_BldFinish = finish{ specular 0.1 roughness 0.1 }
#declare TW_GlassFinish = finish{ specular 0.1 roughness 0.2 }

#declare TW_BldTexture = texture{ pigment{ TW_BldColor } finish{ TW_BldFinish } }
#declare TW_NecklaceTexture = texture{ pigment{ TW_NecklaceColor } finish{ TW_BldFinish } }
#declare TW_GlassesTexture = texture{ pigment{ TW_GlassColor } finish{ TW_GlassFinish } }

#declare TW_BaseBuildingHighness = 6;
#declare TW_BottleNeckHighness = 8;
#declare TW_NecklaceHighness = 1;
#declare TW_BaseHighness = 1 / 3;
#declare TW_BaseYScale = 3;
#declare TW_GlassColumnRadius = 0.025;

#declare TW_GlassesPosScale = 0.95;
#declare TW_SideNum = 8;
#declare TW_RadiusLength = 1.15;
#declare TW_NeckLength = 1;
#declare TW_RadiusAngle = 90 - (180 - (360 / TW_SideNum) ) / 2;
#declare TW_EffectiveRadiusLength = TW_RadiusLength / cos( radians( TW_RadiusAngle ) );
#declare TW_EffectiveNeckLength = TW_NeckLength / cos( radians( TW_RadiusAngle ) );

#declare TW_Coords = array[TW_SideNum];
#declare TW_NeckPrismCoords = array[TW_SideNum];

#for( Side, 0, TW_SideNum - 1 )
	#declare TW_Coords[Side] = vrotate( < 0, 1, TW_EffectiveRadiusLength >, < 0, 360 / TW_SideNum * Side + 360 / ( TW_SideNum * 2 ), 0 > );
	#declare TW_NeckPrismCoords[Side] = vrotate( < 0, 1, TW_EffectiveNeckLength >, < 0, 360 / TW_SideNum * Side + 360 / ( TW_SideNum * 2 ), 0 > );
#end

#declare TW_Base = prism{ conic_sweep linear_spline 1, 1 - TW_BaseHighness, 9 
							#for( Side, 0, TW_SideNum - 1)
								< TW_Coords[Side].x, TW_Coords[Side].z >
							#end
								< TW_Coords[0].x, TW_Coords[0].z >
						translate -(1 - TW_BaseHighness ) * y
						scale < 1, TW_BaseYScale, 1 >
						texture{ TW_BldTexture }
					}

#declare TW_BottleNeck = cylinder{ < 0, 0, 0, >, < 0, 1, 0 >, 1 texture{ TW_NecklaceTexture } }

#declare TW_Neck = prism{ linear_sweep linear_spline 0, TW_BottleNeckHighness, 9
							#for( Side, 0, TW_SideNum - 1 )
								< TW_NeckPrismCoords[Side].x, TW_NeckPrismCoords[Side].z >
							#end
								< TW_NeckPrismCoords[0].x, TW_NeckPrismCoords[0].z >
						texture{ TW_BldTexture }
					}
					
#declare TW_GlassesWalls = prism{ linear_sweep linear_spline 0, 1, 9
									#for( Side, 0, TW_SideNum - 1 )
										< TW_Coords[Side].x * TW_GlassesPosScale, TW_Coords[Side].z * TW_GlassesPosScale >
									#end
										< TW_Coords[0].x * TW_GlassesPosScale, TW_Coords[0].z * TW_GlassesPosScale >
								texture{ TW_GlassesTexture }	
							}

#declare TW_GlassesColumns = union{
									#for( Count, 0, TW_SideNum - 1 )
										cylinder{ < TW_Coords[Count].x * TW_GlassesPosScale, 0, TW_Coords[Count].z * TW_GlassesPosScale >
												, < TW_Coords[Count].x * TW_GlassesPosScale, 1, TW_Coords[Count].z * TW_GlassesPosScale >,
												TW_GlassColumnRadius 
											texture{ TW_BldTexture }
										}
									#end
								}

#declare TW_BaseBuilding =
prism{ linear_sweep linear_spline
	0, 8, 7
	< 4, 0 >, < 4, 4 >, < 2, 6 >, < -2, 6 >, < -4, 4 >, < -4, 0 >, < 4, 0 > 
	rotate -90 * x
	translate 4 * z
	texture{ TW_NecklaceTexture }
}

#declare CompleteRadarTower =
union{
	object{ TW_Neck translate TW_BaseBuildingHighness * y }
	object{ TW_BottleNeck translate ( TW_BaseBuildingHighness + TW_BottleNeckHighness ) * y }
	object{ TW_Base translate ( TW_BaseBuildingHighness + TW_BottleNeckHighness + TW_NecklaceHighness ) * y }
	object{ TW_GlassesWalls translate ( TW_BaseBuildingHighness + TW_BottleNeckHighness + TW_NecklaceHighness + TW_BaseHighness * TW_BaseYScale ) * y }
	object{ TW_GlassesColumns translate ( TW_BaseBuildingHighness + TW_BottleNeckHighness + TW_NecklaceHighness + TW_BaseHighness * TW_BaseYScale ) * y }
	object{ TW_Base rotate 180 * x 
					translate TW_BaseHighness * TW_BaseYScale * 3 * y 
					translate ( TW_BaseBuildingHighness + TW_BottleNeckHighness + TW_NecklaceHighness ) * y }
	object{ TW_BaseBuilding }
}