//The green house with flore inside

#include "includes/bush1.inc"
#include "includes/mapleA.inc"

#declare GH_FrameColor = color srgb 0.95;
#declare GH_GlassColor = color srgb < 1, 1, 1 > filter 0.5 transmit 0.5;
#declare GH_AccessTestColor = color srgb < 1, 1, 0 >; 

#declare GH_FrameFinish = finish{ specular 0.1 roughness 0.1 }
#declare GH_GlassFinish = finish{ specular 0.1 roughness 0.2 }

#declare GH_FrameTexture = texture{ pigment{ GH_FrameColor } finish{ GH_FrameFinish } }
#declare GH_GlassTexture = texture{ pigment{ GH_GlassColor } finish{ GH_GlassFinish } }
#declare GH_GlassMaterial = material{ texture{ GH_GlassTexture } }
#declare GH_AccessTexture = texture{ pigment{ GH_AccessTestColor } finish{ GH_GlassFinish } }

#declare GH_FloorThickness = 3;
#declare GH_FrameRadius = 0.05;
#declare GH_SideNum = 8;
#declare GH_Highness = 9;
#declare GH_MidHighness = 6;
#declare GH_Radius = 6;//3 before
#declare GH_MidRadius = 3;
#declare GH_RadiusAngle = 90 - (180 - (360 / GH_SideNum) ) / 2;//Yield 22.5
#declare GH_EffectiveRadiusLength = GH_Radius / cos( radians( GH_RadiusAngle ) ); 

#declare GH_1_Coords = array[GH_SideNum]; //The lowest coordinates
#declare GH_2_Coords = array[GH_SideNum]; 
#declare GH_3_Coords = array[GH_SideNum]; //The top coordinates

#for( Side, 0, GH_SideNum - 1 )
	#declare GH_1_Coords[Side] = vrotate( < 0, GH_FloorThickness, GH_EffectiveRadiusLength >, < 0, 360 / GH_SideNum * Side + 360 / ( GH_SideNum * 2 ), 0 > );
	#declare GH_2_Coords[Side] = vrotate( < 0, GH_MidHighness, GH_EffectiveRadiusLength >, < 0, 360 / GH_SideNum * Side + 360 / ( GH_SideNum * 2 ), 0 > );
	#declare GH_3_Coords[Side] = vrotate( < 0, GH_Highness, GH_EffectiveRadiusLength / GH_Radius * GH_MidRadius >, 
									< 0, 360 / GH_SideNum * Side + 360 / ( GH_SideNum * 2 ), 0 > );
#end

#declare GreenHouseFrame =
union{
	#for( Side, 0, GH_SideNum - 1 )
		#local FirstIndex = Side;
		#local SecondIndex = mod( Side + 1, GH_SideNum );
		cylinder{ GH_1_Coords[FirstIndex] - < 0, GH_FloorThickness, 0 >, GH_2_Coords[FirstIndex] GH_FrameRadius texture{ GH_FrameTexture } }
		cylinder{ GH_2_Coords[FirstIndex], GH_3_Coords[FirstIndex] GH_FrameRadius texture{ GH_FrameTexture } }
		cylinder{ GH_2_Coords[FirstIndex], GH_2_Coords[SecondIndex] GH_FrameRadius texture{ GH_FrameTexture } }
		cylinder{ GH_3_Coords[FirstIndex], GH_3_Coords[SecondIndex] GH_FrameRadius texture{ GH_FrameTexture } }
		sphere{ GH_1_Coords[FirstIndex] - < 0, GH_FloorThickness, 0 >, GH_FrameRadius texture{ GH_FrameTexture } }
		sphere{ GH_2_Coords[FirstIndex], GH_FrameRadius texture{ GH_FrameTexture } }
		sphere{ GH_3_Coords[FirstIndex], GH_FrameRadius texture{ GH_FrameTexture } }
		
		#if( Side = 7 )
			//mesh{ triangle{ GH_1_Coords[FirstIndex], GH_1_Coords[SecondIndex], GH_2_Coords[FirstIndex] texture{ GH_AccessTexture } } }
			//mesh{ triangle{ GH_2_Coords[FirstIndex], GH_2_Coords[SecondIndex], GH_1_Coords[SecondIndex] texture{ GH_AccessTexture } } }
		#else
			mesh{ 	triangle{ GH_1_Coords[FirstIndex], GH_1_Coords[SecondIndex], GH_2_Coords[FirstIndex] }
					triangle{ GH_2_Coords[FirstIndex], GH_2_Coords[SecondIndex], GH_1_Coords[SecondIndex] } 
				material{ GH_GlassMaterial }
			}
		#end
			mesh{ 	triangle{ GH_2_Coords[FirstIndex], GH_2_Coords[SecondIndex], GH_3_Coords[FirstIndex] }
					triangle{ GH_3_Coords[FirstIndex], GH_3_Coords[SecondIndex], GH_2_Coords[SecondIndex] }
					triangle{ GH_3_Coords[FirstIndex], GH_3_Coords[SecondIndex], < 0, GH_3_Coords[FirstIndex].y, 0 > } 
				material{ GH_GlassMaterial }
			}
	#end
}

#declare GreenHouseFloor =
prism{ linear_sweep linear_spline
	0, GH_FloorThickness, GH_SideNum + 1,
	#for( Side, 0, GH_SideNum )
		#local Index = mod( Side, GH_SideNum );
		< GH_1_Coords[Index].x, GH_1_Coords[Index].z >
	#end
}

#declare CompleteGreenHouse =
union{
	object{ GreenHouseFrame }
	object{ GreenHouseFloor	texture{ GH_FrameTexture } }
	object{ GreenHouseFloor scale < 0.95, 1.01, 0.95 > texture{ T_brown3 } }
	object{ MapleA scale 6 translate GH_FloorThickness * y }
	object{ Bush1 scale 2.8 rotate 0 * y translate < GH_Radius / 2, GH_FloorThickness, GH_Radius / 2 > }
	object{ Bush1 scale 4.1 rotate 97 * y translate < GH_Radius / 2, GH_FloorThickness, -GH_Radius / 2 > }
	object{ Bush1 scale 3.1 rotate 172 * y translate < -GH_Radius / 2, GH_FloorThickness, -GH_Radius / 2 > }
	object{ Bush1 scale 3.6 rotate 282 * y translate < -GH_Radius / 2, GH_FloorThickness, GH_Radius / 2 > }
}

#declare GH_Dimensions = max_extent( CompleteGreenHouse ) - min_extent( CompleteGreenHouse );
