//The file for a zodiac boat

#declare MotorBlackColor = color srgb 0.20;
#declare MotorRedColor = color srgb < 0.65, 0, 0 >;

#declare FloatersWhitePig = pigment{ color srgb 1 }                      
#declare FloatersBluePig = pigment{ color srgb < 37 / 255, 47 / 255, 82 / 255 > }
#declare MotorBlackPig = pigment{ MotorBlackColor }
#declare MotorRedLine = pigment{ gradient y color_map{ 
													[0.6 MotorBlackColor]
													[0.6 MotorRedColor ]
													[0.85 MotorRedColor ]
													[0.85 MotorBlackColor ] 
												} 
						} 


#declare FloatersFinish = finish{ specular 0.1 roughness 0.01 }
#declare MotorFinish = finish{ specular 0.05 roughness 0.1 } 


#declare Rear_x = 19;
#declare RearRegul_x = 174;
#declare FrontLess_x = 222;
#declare FrontFinal_x = 298;
#declare TopRegul_z = 60; 
#declare TopLess_z = 56;
#declare TopFinal_z = 26;
#declare FloaterRadius = 20;
#declare TopFinal_y = 20;

#declare RearPanel_X = 39;

//x is the forward vector of the boat
#declare Pt_left_A = <Rear_x, 0, TopRegul_z>;
#declare Pt_left_B = <RearRegul_x, 0, TopLess_z>;
#declare Pt_left_C = <FrontFinal_x, TopFinal_y, TopFinal_z>;
#declare Pt_right_A = <Rear_x, 0, -TopRegul_z>;
#declare Pt_right_B = <RearRegul_x, 0, -TopLess_z>;
#declare Pt_right_C = <FrontFinal_x, TopFinal_y, -TopFinal_z>;

#declare Pt_leftTopPanel = <RearPanel_X, FloaterRadius, TopRegul_z>;
#declare Pt_rightTopPanel = <RearPanel_X, FloaterRadius, -TopRegul_z>;
#declare Pt_leftBottomPanel = <RearPanel_X, 0, TopRegul_z>;
#declare Pt_rightBottomPanel = <RearPanel_X, 0, -TopRegul_z>;
                      
#declare Floaters = merge{
						union{
							sphere{0, FloaterRadius scale <0.5, 1, 1> translate Pt_left_A}
							cylinder{ Pt_left_A, Pt_left_B, FloaterRadius }
							sphere{0, FloaterRadius scale <0.5, 1, 1> translate Pt_right_A}
							cylinder{ Pt_right_A, Pt_right_B, FloaterRadius }
                          
							pigment{ FloatersBluePig }
							finish{ FloatersFinish }
                         }
                         union{
                          sphere{ Pt_right_B, FloaterRadius }
                          cylinder{ Pt_right_B, Pt_right_C, FloaterRadius }
                          sphere{ Pt_left_B, FloaterRadius }
							cylinder{ Pt_left_B, Pt_left_C, FloaterRadius }
							
                          
                          sphere{ Pt_left_C, FloaterRadius }
                          sphere{ Pt_right_C, FloaterRadius }
                          pigment{ FloatersWhitePig }
                          finish{ FloatersFinish }
                         }
                         
                          cylinder{ Pt_left_C, Pt_right_C, FloaterRadius - 0.0001 
								pigment{ FloatersBluePig }
								finish{ FloatersFinish }
                          }
                          
                    }

#declare StepWidth = 30;
#declare StepInterval = 2;
#declare GroundStep = prism{ linear_sweep linear_spline TopLess_z, -TopLess_z, 5, <-StepWidth/2, 0>, <-StepWidth/2 + StepInterval, StepInterval>, <StepWidth/2 - StepInterval, StepInterval>, <StepWidth/2, 0>, <-StepWidth / 2, 0> rotate -90*x 
							pigment{ FloatersWhitePig }
						}
                    
#declare SimpleZodiacGround = mesh{
							//triangle{ Pt_leftBottomPanel, Pt_left_B, Pt_rightBottomPanel }
							//triangle{ Pt_left_B, Pt_right_B, Pt_rightBottomPanel }
							triangle{ Pt_left_B, Pt_right_B, Pt_left_C }
							triangle{ Pt_left_C, Pt_right_C, Pt_right_B }
							
							triangle{Pt_leftTopPanel, Pt_rightTopPanel, Pt_rightBottomPanel}
							triangle{Pt_leftTopPanel, Pt_rightBottomPanel, Pt_leftBottomPanel}
							
							pigment{ FloatersWhitePig }
							finish{ FloatersFinish }
						}

#declare ComplexZodiacGround = union{ 
									#local X_Position = RearRegul_x - StepWidth / 2;
									#while( X_Position > StepWidth / 2 )
										object{ GroundStep translate <X_Position, -FloaterRadius / 2, 0> }
										#local X_Position = X_Position - StepWidth;
									#end 
								}

#declare MotorScale = 40;
                    
#declare MotorTop = prism{ conic_sweep linear_spline 40/MotorScale, 30/MotorScale, 7, 
							<30, -10>/MotorScale,
							< 30, 10>/MotorScale, 
							<-10, 20>/MotorScale ,
							<-20, 10>/MotorScale,
							< -20,-10>/MotorScale,
							<-10,-20>/MotorScale,
							<30, -10>/MotorScale 
							rotate 180*x translate y }
							
#declare MotorBody = prism{ linear_sweep linear_spline 0, 20, 7, <30, -10>,< 30, 10>, <-10, 20> ,<-20, 10>,< -20,-10>,<-10,-20>,<30, -10> }

#declare MotorGlobal = merge{ 
							object{MotorTop scale MotorScale translate 20*y
								pigment{ MotorBlackColor }
								finish{ MotorFinish }
							} 
							object{ MotorBody 
								pigment{ MotorRedLine scale <1, 20, 1> }
								finish{ MotorFinish }
							} 
							translate <20, 20, 0>
						}
                    
#declare ZodiacBoat = 
union{
	object{ Floaters } 
	object{ ComplexZodiacGround }
	object{ SimpleZodiacGround }
	object{ MotorGlobal }
}
