/*
	Author: Antoine FAURE.
	Licence of this file: free for educational, commercial or other usage.

	Content of file: the parts of a military hovercraft model
	Note: Everything in this file as been prefixed with 'HoverCraft_' in order 
		to avoid names collisions as much as possible.
	
	Usage: use the object statement like this: 
		object{ HoverCraftObject }
*/

#declare HoverCraft_FloaterColor = color srgb 0.35;
#declare HoverCraft_FloaterTexture = texture{ pigment{ HoverCraft_FloaterColor } finish{ specular 0.1 roughness 0.01 phong 0 phong_size 0 } }

#declare HoverCraft_MetalColor1 = color srgb < 184 / 255, 168 / 255, 144 / 255 >;
#declare HoverCraft_MetalColor2 = color srgb < 142 / 255, 130 / 255, 93 / 255 >;
#declare HoverCraft_MetalColor3 = color srgb < 111 / 255, 101 / 255, 79 / 255 >;
#declare HoverCraft_MetalFinish = finish{ roughness 0.01 specular 0.1 }
#declare HoverCraft_MilitaryTexture = texture{ pigment{ gradient z color_map{ 
												[ 0 HoverCraft_MetalColor1 ]
												[ 0.3 HoverCraft_MetalColor1 ]
												[ 0.3 HoverCraft_MetalColor2 ]
												[ 0.6 HoverCraft_MetalColor2 ]
												[ 0.6 HoverCraft_MetalColor3 ]
												[ 1 HoverCraft_MetalColor3 ]
															}
													scale < 1, 1, 4 >
													warp{ turbulence < 0, 0.1, 1 > octaves 1 lambda 1 }
												} 
												finish{ HoverCraft_MetalFinish }
										}

#declare HoverCraft_FanBladeColor = color srgb 0.65;
#declare HoverCraft_FanBladeTexture = texture{ pigment{ HoverCraft_FanBladeColor } finish{ specular 0.3 roughness 0.01 } }
#declare HoverCraft_TurningFanBladesTexture = 
texture{ pigment{ radial color_map{ 
								[ 0 HoverCraft_FanBladeColor transmit 0.5 ]
								[ 0.5 HoverCraft_FanBladeColor transmit 0.75 ]
								[ 0.5 HoverCraft_FanBladeColor transmit 1 ]
						} 
					frequency 8
					rotate 90 * x
					warp{ turbulence < 0.1, 0.1, 0 > }
		} 
		finish{ specular 0.3 roughness 0.01 } 
}

#declare HoverCraft_PilotBoxFacilityTexture = texture{ pigment{ HoverCraft_MetalColor1 } finish{ HoverCraft_MetalFinish } }

#declare HoverCraft_GlassColor = color srgb < 23 / 255, 119 / 255, 157 / 255 > transmit 0.6;
#declare HoverCraft_GlassTexture = texture{ pigment{ HoverCraft_GlassColor } finish{ specular 0.2 roughness 0.01 } }

#declare HoverCraft_Length = 18;
#declare HoverCraft_Width = 10;
#declare HoverCraft_FloaterRadius = 1;
#declare HoverCraft_FloaterCornerBigRadius = 2;
#declare HoverCraft_FloaterCornerHorizontalSize = HoverCraft_FloaterRadius + HoverCraft_FloaterCornerBigRadius * 2;
#declare HoverCraft_FloorHighness = HoverCraft_FloaterRadius / 10;

#declare HoverCraft_FanRoundRadius = 1.8;
#declare HoverCraft_FanRoundBorder = 0.1;
#declare HoverCraft_FanDepth = 1.8;
#declare HoverCraft_FanStalkRadius = 0.25;
#declare HoverCraft_FanShutterThickness = 0.035; 
#declare HoverCraft_StructWidthPercent = 0.75;
#declare HoverCraft_StructSlopeLength = HoverCraft_Length / 7;

#declare HoverCraft_PilotBoxZStart = HoverCraft_Length / 4;
#declare HoverCraft_PilotBoxLength = HoverCraft_Length / 6;
#declare HoverCraft_PilotBoxWidth = HoverCraft_Width / 3.5;
#declare HoverCraft_PilotBoxHeightPercent = 1.25;
#declare HoverCraft_PilotBoxArmoured = 0.05;
#declare HoverCraft_PilotBoxWindowHeightPercent = 0.4;

#declare HoverCraft_FloaterCornerGeom = 
difference{
	torus{ HoverCraft_FloaterCornerBigRadius, HoverCraft_FloaterRadius }
	box{ < -HoverCraft_FloaterCornerHorizontalSize, -HoverCraft_FloaterRadius * 1.1, 0 >,
		< HoverCraft_FloaterCornerHorizontalSize, HoverCraft_FloaterRadius * 1.1, -HoverCraft_FloaterCornerBigRadius * 2 > } // -z box
	box{ < 0, -HoverCraft_FloaterRadius * 1.1, -HoverCraft_FloaterCornerHorizontalSize >,
		< HoverCraft_FloaterCornerBigRadius * 2, HoverCraft_FloaterRadius * 1.1, HoverCraft_FloaterCornerHorizontalSize > } // +x box
}

#declare HoverCraft_FloaterCornersPos = 
array[4]{ < -HoverCraft_Width / 2 + HoverCraft_FloaterRadius + HoverCraft_FloaterCornerBigRadius, HoverCraft_FloaterRadius, 
			HoverCraft_Length / 2 - HoverCraft_FloaterRadius - HoverCraft_FloaterCornerBigRadius >,
		< HoverCraft_Width / 2 - HoverCraft_FloaterRadius - HoverCraft_FloaterCornerBigRadius, HoverCraft_FloaterRadius, 
			HoverCraft_Length / 2 - HoverCraft_FloaterRadius - HoverCraft_FloaterCornerBigRadius >,
		< HoverCraft_Width / 2 - HoverCraft_FloaterRadius - HoverCraft_FloaterCornerBigRadius, HoverCraft_FloaterRadius, 
			-HoverCraft_Length / 2 + HoverCraft_FloaterRadius + HoverCraft_FloaterCornerBigRadius >,
		< -HoverCraft_Width / 2 + HoverCraft_FloaterRadius + HoverCraft_FloaterCornerBigRadius, HoverCraft_FloaterRadius, 
			-HoverCraft_Length / 2 + HoverCraft_FloaterRadius + HoverCraft_FloaterCornerBigRadius > }

#declare HoverCraft_FloaterGeom =
union{
	object{ HoverCraft_FloaterCornerGeom translate HoverCraft_FloaterCornersPos[0] } //-x +z pos
	object{ HoverCraft_FloaterCornerGeom rotate 90 * y translate HoverCraft_FloaterCornersPos[1] } //+x +z pos
	object{ HoverCraft_FloaterCornerGeom rotate 180 * y translate HoverCraft_FloaterCornersPos[2] } //+x -z pos
	object{ HoverCraft_FloaterCornerGeom rotate -90 * y translate HoverCraft_FloaterCornersPos[3] } //-x -z pos
	cylinder{ HoverCraft_FloaterCornersPos[0], HoverCraft_FloaterCornersPos[1], HoverCraft_FloaterRadius translate HoverCraft_FloaterCornerBigRadius * z }
	cylinder{ HoverCraft_FloaterCornersPos[1], HoverCraft_FloaterCornersPos[2], HoverCraft_FloaterRadius translate HoverCraft_FloaterCornerBigRadius * x }
	cylinder{ HoverCraft_FloaterCornersPos[0], HoverCraft_FloaterCornersPos[3], HoverCraft_FloaterRadius translate -HoverCraft_FloaterCornerBigRadius * x }
	cylinder{ HoverCraft_FloaterCornersPos[2], HoverCraft_FloaterCornersPos[3], HoverCraft_FloaterRadius translate -HoverCraft_FloaterCornerBigRadius * z }
	texture{ HoverCraft_FloaterTexture }
}

#declare HoverCraft_Floor =
union{
	cylinder{ HoverCraft_FloaterCornersPos[0], HoverCraft_FloaterCornersPos[0] + < 0, HoverCraft_FloorHighness, 0 >, HoverCraft_FloaterCornerBigRadius }
	cylinder{ HoverCraft_FloaterCornersPos[1], HoverCraft_FloaterCornersPos[1] + < 0, HoverCraft_FloorHighness, 0 >, HoverCraft_FloaterCornerBigRadius }
	cylinder{ HoverCraft_FloaterCornersPos[2], HoverCraft_FloaterCornersPos[2] + < 0, HoverCraft_FloorHighness, 0 >, HoverCraft_FloaterCornerBigRadius }
	cylinder{ HoverCraft_FloaterCornersPos[3], HoverCraft_FloaterCornersPos[3] + < 0, HoverCraft_FloorHighness, 0 >, HoverCraft_FloaterCornerBigRadius }
	box{ HoverCraft_FloaterCornersPos[0] + < 0, HoverCraft_FloorHighness, HoverCraft_FloaterCornerBigRadius >, 
			HoverCraft_FloaterCornersPos[2] + < 0, 0, -HoverCraft_FloaterCornerBigRadius > }//+z -z floor
	box{ HoverCraft_FloaterCornersPos[0] + < -HoverCraft_FloaterCornerBigRadius, HoverCraft_FloorHighness, 0 > , 
			HoverCraft_FloaterCornersPos[2] + < HoverCraft_FloaterCornerBigRadius, 0, 0 > }//+x -x floor
	translate HoverCraft_FloaterRadius * y
}

#declare HoverCraft_FanShutter =
box{ < -HoverCraft_FanShutterThickness / 2, -HoverCraft_FanRoundRadius, 0 >, 
		< HoverCraft_FanShutterThickness / 2, HoverCraft_FanRoundRadius, -HoverCraft_FanDepth / 2 > 
	translate < 0, 0, -HoverCraft_FanDepth - HoverCraft_FanRoundBorder >
}

#declare HoverCraft_FanGeomPosition =
< 0, max_extent( HoverCraft_Floor ).y + HoverCraft_FanRoundRadius * 1.2, min_extent( HoverCraft_Floor ).z + HoverCraft_FanDepth * 1.2 >;

#declare HoverCraft_FanGeom =
union{
	torus{ HoverCraft_FanRoundRadius - HoverCraft_FanRoundBorder, HoverCraft_FanRoundBorder rotate 90 * x }
	torus{ HoverCraft_FanRoundRadius - HoverCraft_FanRoundBorder, HoverCraft_FanRoundBorder rotate 90 * x translate -HoverCraft_FanDepth * z }
	difference{
		cylinder{ < 0, 0, 0 >, < 0, 0, -HoverCraft_FanDepth >, HoverCraft_FanRoundRadius }
		cylinder{ < 0, 0, 1 >, < 0, 0, -HoverCraft_FanDepth * 2 >, HoverCraft_FanRoundRadius - HoverCraft_FanRoundBorder * 2 }
	}
	sphere_sweep{ linear_spline 3, 
		< 0, 0, HoverCraft_FanDepth / 8 >, HoverCraft_FanStalkRadius,
		< 0, 0, HoverCraft_FanDepth >, HoverCraft_FanStalkRadius,
		< 0, -HoverCraft_FanRoundRadius * 1.2, HoverCraft_FanDepth * 1.5 >, HoverCraft_FanStalkRadius
	}
	object{ HoverCraft_FanShutter }
	object{ HoverCraft_FanShutter translate -HoverCraft_FanRoundRadius / 2 * x }
	object{ HoverCraft_FanShutter translate HoverCraft_FanRoundRadius / 2 * x }
	translate HoverCraft_FanGeomPosition
}

#declare HoverCraft_FanBlade =
intersection{
	box{ < -HoverCraft_FanStalkRadius * 2, 0, -HoverCraft_FanShutterThickness / 2 >, 
		< HoverCraft_FanStalkRadius * 2, HoverCraft_FanRoundRadius, HoverCraft_FanShutterThickness / 2 > rotate 35 * y }
	cylinder{ < 0, 0, -HoverCraft_FanDepth >,< 0, 0, HoverCraft_FanDepth >, HoverCraft_FanRoundRadius - HoverCraft_FanRoundBorder * 4 }
	texture{ HoverCraft_FanBladeTexture }
}

#macro HoverCraft_PlaceFanBlade(BladeNumber, CustomPosition)
	#for( It, 0, BladeNumber - 1 )
		object{ HoverCraft_FanBlade rotate 360 / BladeNumber * It * z 
				translate HoverCraft_FanGeomPosition + CustomPosition + < 0, 0, -HoverCraft_FanDepth / 4 > 
		}
	#end
	cylinder{ < 0, 0, HoverCraft_FanDepth / 8 >, < 0, 0, -HoverCraft_FanDepth / 3 >, HoverCraft_FanStalkRadius * 0.8 
		translate HoverCraft_FanGeomPosition + CustomPosition 
		texture{ HoverCraft_FanBladeTexture }
	}
#end

#macro HoverCraft_PlaceTurningFansEffect(CustomPosition)
	disc{ < 0, 0, 0 >, z, HoverCraft_FanRoundRadius - HoverCraft_FanRoundBorder * 4
		texture{ HoverCraft_TurningFanBladesTexture } 
		translate HoverCraft_FanGeomPosition + CustomPosition + < 0, 0, -HoverCraft_FanDepth / 4 > 
	}
#end

#declare HoverCraft_BoxUnderTheFans =
box{ < min_extent( HoverCraft_Floor ).x * HoverCraft_StructWidthPercent, 
		min_extent( HoverCraft_Floor ).y - 0.001, 
		HoverCraft_FanDepth * 1.5 + min_extent( HoverCraft_Floor ).z >, 
	< max_extent( HoverCraft_Floor ).x * HoverCraft_StructWidthPercent, 
		max_extent( HoverCraft_FanGeom ).y - HoverCraft_FanRoundRadius * 2, 
		min_extent( HoverCraft_Floor ).z > 
}

#declare HoverCraft_StructRearSlope =
prism{ linear_sweep linear_spline -min_extent( HoverCraft_Floor ).x * HoverCraft_StructWidthPercent, -max_extent( HoverCraft_Floor ).x * HoverCraft_StructWidthPercent, 5,
	< 0, 0 >, 
	< 0, -HoverCraft_StructSlopeLength >, 
	< max_extent( HoverCraft_BoxUnderTheFans ).y - min_extent( HoverCraft_BoxUnderTheFans ).y, -HoverCraft_StructSlopeLength >,
	< ( max_extent( HoverCraft_BoxUnderTheFans ).y - min_extent( HoverCraft_BoxUnderTheFans ).y ) * 4, 0 >,
	< 0, 0 >
	rotate 90 * z
	translate < 0, min_extent( HoverCraft_Floor ).y - 0.001, HoverCraft_FanDepth * 1.5 + min_extent( HoverCraft_Floor ).z + HoverCraft_StructSlopeLength >
}

#declare HoverCraft_CenterBlockYTop = min_extent( HoverCraft_Floor ).y - 0.001 + ( max_extent( HoverCraft_BoxUnderTheFans ).y 
										- min_extent( HoverCraft_BoxUnderTheFans ).y ) * 4;
#declare HoverCraft_CenterBlockZMin = HoverCraft_FanDepth * 1.5 + min_extent( HoverCraft_Floor ).z + HoverCraft_StructSlopeLength;
#declare HoverCraft_CenterBlockHighness = HoverCraft_CenterBlockYTop - min_extent( HoverCraft_Floor ).y;

#declare HoverCraft_CenterBlock =
union{
	box{ < -min_extent( HoverCraft_Floor ).x * HoverCraft_StructWidthPercent,
			min_extent( HoverCraft_Floor ).y - 0.001, 
			HoverCraft_CenterBlockZMin >,
		< -max_extent( HoverCraft_Floor ).x * HoverCraft_StructWidthPercent, 
			min_extent( HoverCraft_Floor ).y + HoverCraft_CenterBlockHighness * 0.25,
			HoverCraft_PilotBoxZStart > 
	}
	box{< -min_extent( HoverCraft_Floor ).x * HoverCraft_StructWidthPercent * 0.96, 
			min_extent( HoverCraft_Floor ).y + HoverCraft_CenterBlockHighness * 0.25, 
			HoverCraft_CenterBlockZMin >,
		< -max_extent( HoverCraft_Floor ).x * HoverCraft_StructWidthPercent * 0.96, 
			min_extent( HoverCraft_Floor ).y + HoverCraft_CenterBlockHighness * 0.75, 
			HoverCraft_PilotBoxZStart > }
	box{< -min_extent( HoverCraft_Floor ).x * HoverCraft_StructWidthPercent * 0.92, 
			min_extent( HoverCraft_Floor ).y + HoverCraft_CenterBlockHighness * 0.75, 
			HoverCraft_CenterBlockZMin >,
		< -max_extent( HoverCraft_Floor ).x * HoverCraft_StructWidthPercent * 0.92, 
			HoverCraft_CenterBlockYTop, 
			HoverCraft_PilotBoxZStart > }
}

#declare HoverCraft_CenterBlockSize = max_extent( HoverCraft_CenterBlock ) - min_extent( HoverCraft_CenterBlock );
#declare HoverCraft_PilotBoxTopZCoord = HoverCraft_PilotBoxLength * 3 / 4;

#declare HoverCraft_CenterBlockPlaqueWidth = HoverCraft_CenterBlockSize.x * 0.8;
#declare HoverCraft_CenterBlockPlaqueThickness = HoverCraft_CenterBlockSize.y * 0.075;

#declare HoverCraft_CenterBlockPlaque =
box{ < -HoverCraft_CenterBlockPlaqueWidth / 2, max_extent(HoverCraft_CenterBlock).y, min_extent(HoverCraft_CenterBlock).z >,
		< HoverCraft_CenterBlockPlaqueWidth / 2, max_extent(HoverCraft_CenterBlock).y + HoverCraft_CenterBlockPlaqueThickness, max_extent(HoverCraft_CenterBlock).z > 
}

#declare HoverCraft_CenterBlockLines =
prism{ linear_sweep linear_spline 
	-HoverCraft_CenterBlockPlaqueWidth / 2, HoverCraft_CenterBlockPlaqueWidth / 2, 4,
	< 0, HoverCraft_CenterBlockPlaqueThickness / 3 >, < 0, -HoverCraft_CenterBlockPlaqueThickness / 3 >, 
	< HoverCraft_CenterBlockPlaqueThickness / 2, 0 >, < 0, HoverCraft_CenterBlockPlaqueThickness / 3 > 
	rotate 90 * z
}

#macro HoverCraft_PlaceCenterBlockLines(LinesNumber)
	#for( It, 0, LinesNumber - 1 )
		object{ HoverCraft_CenterBlockLines 
			translate < 0, max_extent(HoverCraft_CenterBlockPlaque).y, 
				max_extent(HoverCraft_CenterBlockPlaque).z - max_extent(HoverCraft_CenterBlockPlaque).z * 0.1
				- It * (HoverCraft_CenterBlockSize).z / LinesNumber >
		}
	#end
#end

#declare HoverCraft_PilotBox =
prism{ linear_sweep linear_spline 0, HoverCraft_PilotBoxWidth, 6,
	< 0, 0 >, 
	< HoverCraft_CenterBlockSize.y * HoverCraft_PilotBoxHeightPercent, 0 >, 
	< HoverCraft_CenterBlockSize.y * HoverCraft_PilotBoxHeightPercent, HoverCraft_PilotBoxTopZCoord >,
	< HoverCraft_CenterBlockSize.y * 0.2, HoverCraft_PilotBoxLength >,
	< 0, HoverCraft_PilotBoxLength >,
	< 0, 0 >
	rotate 90 * z
}

#declare HoverCraft_PilotBoxWindowYTop = max_extent( HoverCraft_PilotBox ).y - HoverCraft_PilotBoxArmoured;
#declare HoverCraft_PilotBoxWindowYBottom = max_extent( HoverCraft_PilotBox ).y * ( 1 - HoverCraft_PilotBoxWindowHeightPercent ) 
											- HoverCraft_PilotBoxArmoured;

#declare HoverCraft_PilotBoxFrontSlopeBend = HoverCraft_PilotBoxLength - HoverCraft_PilotBoxTopZCoord;
#declare HoverCraft_PilotBoxSlopeHighness = HoverCraft_CenterBlockSize.y * HoverCraft_PilotBoxHeightPercent - HoverCraft_CenterBlockSize.y * 0.2;
#declare HoverCraft_PilotBoxMiddleWindowFront = HoverCraft_PilotBoxFrontSlopeBend * ( HoverCraft_PilotBoxWindowYTop - HoverCraft_PilotBoxWindowYBottom ) / HoverCraft_PilotBoxSlopeHighness;

#declare HoverCraft_PilotBoxMiddleWindow =
prism{ linear_sweep linear_spline -1, HoverCraft_PilotBoxWidth + 1, 5,
	< 0, 0 >, 
	< HoverCraft_PilotBoxWindowYTop - HoverCraft_PilotBoxWindowYBottom, 0 >,
	< HoverCraft_PilotBoxWindowYTop - HoverCraft_PilotBoxWindowYBottom, 
		HoverCraft_PilotBoxLength * 3 / 4 - HoverCraft_PilotBoxLength * 0.25 - HoverCraft_PilotBoxArmoured * 3 >,
	< 0, HoverCraft_PilotBoxLength * 3 / 4 - HoverCraft_PilotBoxLength * 0.25 - HoverCraft_PilotBoxArmoured * 3 + HoverCraft_PilotBoxMiddleWindowFront >,
	< 0, 0 >
	rotate 90 * z
	translate < 0, HoverCraft_PilotBoxWindowYBottom, HoverCraft_PilotBoxLength * 0.25 + HoverCraft_PilotBoxArmoured >
}

#declare HoverCraft_PilotBoxRearWindow =
box{ < -HoverCraft_PilotBoxWidth * 2, 
		HoverCraft_PilotBoxWindowYTop, 
		HoverCraft_PilotBoxArmoured >,
	< HoverCraft_PilotBoxWidth * 2, 
		HoverCraft_PilotBoxWindowYBottom, 
		HoverCraft_PilotBoxLength * 0.25 > 
}

#declare HoverCraft_PilotBoxFrontWindow =
box{ < -HoverCraft_PilotBoxArmoured, 
		HoverCraft_PilotBoxWindowYTop, 
		HoverCraft_PilotBoxLength * 2 >, 
	< -HoverCraft_PilotBoxWidth + HoverCraft_PilotBoxArmoured,
		HoverCraft_PilotBoxWindowYBottom,
		HoverCraft_PilotBoxArmoured * 2 >
}

#declare HoverCraft_PilotBoxBulk =
difference{
	object{ HoverCraft_PilotBox }
	object{ HoverCraft_PilotBox scale 1 - (HoverCraft_PilotBoxArmoured  * 2) translate -HoverCraft_PilotBoxArmoured / 2 }
}

#declare HoverCraft_PilotBoxGlasses =
union{
	intersection{
		object{ HoverCraft_PilotBoxBulk }
		object{ HoverCraft_PilotBoxFrontWindow }
	}
	intersection{
		object{ HoverCraft_PilotBoxBulk }
		object{ HoverCraft_PilotBoxMiddleWindow }
	}
	intersection{
		object{ HoverCraft_PilotBoxBulk }
		object{ HoverCraft_PilotBoxRearWindow }
	}
	texture{ HoverCraft_GlassTexture }
}

#declare HoverCraft_HollowPilotBox =
union{
	difference{
		object{ HoverCraft_PilotBoxBulk }
		object{ HoverCraft_PilotBoxFrontWindow }
		object{ HoverCraft_PilotBoxMiddleWindow }
		object{ HoverCraft_PilotBoxRearWindow }
	}
	object{ HoverCraft_PilotBoxGlasses }
	translate < min_extent( HoverCraft_Floor ).x * HoverCraft_StructWidthPercent + HoverCraft_PilotBoxWidth, 
					min_extent( HoverCraft_Floor ).y - 0.001, 
					HoverCraft_PilotBoxZStart >
}

#declare HoverCraft_HollowPilotBoxSize = max_extent(HoverCraft_HollowPilotBox) - min_extent(HoverCraft_HollowPilotBox);
#declare HoverCraft_PilotBoxCoverObjACenterXPos = min_extent(HoverCraft_HollowPilotBox).x + HoverCraft_HollowPilotBoxSize.x * 0.15;
#declare HoverCraft_PilotBoxCoverObjACenterZPos = min_extent(HoverCraft_HollowPilotBox).z + HoverCraft_HollowPilotBoxSize.z * 0.55;

#declare HoverCraft_PilotBoxCoverObjA = //A flat cylinder as a decoration over the pilot box
union{
	cylinder{ < HoverCraft_PilotBoxCoverObjACenterXPos, max_extent(HoverCraft_HollowPilotBox).y, HoverCraft_PilotBoxCoverObjACenterZPos >, 
				< HoverCraft_PilotBoxCoverObjACenterXPos, max_extent(HoverCraft_HollowPilotBox).y + 0.125, HoverCraft_PilotBoxCoverObjACenterZPos >, 
				HoverCraft_PilotBoxWidth / 14 }
	cylinder{ < HoverCraft_PilotBoxCoverObjACenterXPos, max_extent(HoverCraft_HollowPilotBox).y + 0.125, HoverCraft_PilotBoxCoverObjACenterZPos >,
				< HoverCraft_PilotBoxCoverObjACenterXPos, max_extent(HoverCraft_HollowPilotBox).y + 0.165, HoverCraft_PilotBoxCoverObjACenterZPos >, 
				HoverCraft_PilotBoxWidth / 7.5 }
}

#declare HoverCraft_PilotBoxCoverObjBCenterXPos = min_extent(HoverCraft_HollowPilotBox).x + HoverCraft_HollowPilotBoxSize.x * 0.35;
#declare HoverCraft_PilotBoxCoverObjBCenterZPos = min_extent(HoverCraft_HollowPilotBox).z + HoverCraft_HollowPilotBoxSize.z * 0.2;

#declare HoverCraft_PilotBoxCoverObjB = //A kind of radar as a decoration over the pilot box
union{
	box{ < -HoverCraft_PilotBoxWidth / 2 * 0.18, 0, -HoverCraft_PilotBoxWidth / 2 * 0.17 >, 
			< HoverCraft_PilotBoxWidth / 2 * 0.18, 0.18, HoverCraft_PilotBoxWidth / 2 * 0.21 > }
	box{ < -HoverCraft_PilotBoxWidth / 2 * 0.2, 0.18, -HoverCraft_PilotBoxWidth / 2 * 0.19 >, 
			< HoverCraft_PilotBoxWidth / 2 * 0.2, 0.3, HoverCraft_PilotBoxWidth / 2 * 0.19 > }
	cylinder{ < 0, 0.3, 0 >, < 0, 0.36, 0>, HoverCraft_PilotBoxWidth / 2 * 0.15 }
	box{ < -HoverCraft_PilotBoxWidth / 2 * 0.14, 0.36, -HoverCraft_PilotBoxWidth / 2 * 0.46 >, 
			< HoverCraft_PilotBoxWidth / 2 * 0.14, 0.48, HoverCraft_PilotBoxWidth / 2 * 0.46 > }
	
	translate < HoverCraft_PilotBoxCoverObjBCenterXPos, max_extent(HoverCraft_HollowPilotBox).y, HoverCraft_PilotBoxCoverObjBCenterZPos >
}

#declare HoverCraft_DiveBoardRoundRadius = 0.1;
#declare HoverCraft_DiveBoardWidth = ( HoverCraft_CenterBlockSize.x - HoverCraft_PilotBoxWidth ) / 2;
#declare HoverCraft_DiveBoardDepth = HoverCraft_PilotBoxLength * 0.6825; // 0.7825
#declare HoverCraft_DiveBoard1_Edge = 0.45;
#declare HoverCraft_DiveBoardsYLink = 0.85;

#declare HoverCraft_DiveBoard1 = 
prism{ linear_sweep linear_spline 0, HoverCraft_CenterBlockSize.x - HoverCraft_PilotBoxWidth, 6
	< 0, 0 >,
	< HoverCraft_CenterBlockSize.y, 0 >,
	< HoverCraft_CenterBlockSize.y, HoverCraft_DiveBoardDepth * 0.3 >,
	< HoverCraft_CenterBlockSize.y * HoverCraft_DiveBoardsYLink, HoverCraft_DiveBoardDepth * HoverCraft_DiveBoard1_Edge >,
	< 0, HoverCraft_DiveBoardDepth * HoverCraft_DiveBoard1_Edge >,
	< 0, 0 >
	rotate 90 * z
	translate < min_extent( HoverCraft_Floor ).x * HoverCraft_StructWidthPercent + HoverCraft_PilotBoxWidth + HoverCraft_DiveBoardWidth * 2, 
				min_extent( HoverCraft_Floor ).y - 0.001, 
				HoverCraft_PilotBoxZStart >
}

#declare HoverCraft_DiveBoard1_Size = max_extent( HoverCraft_DiveBoard1 ) - min_extent( HoverCraft_DiveBoard1 );

#declare HoverCraft_DiveBoard2_Interstice = 0.025;

#declare HoverCraft_DiveBoard2_DivePlace =
prism{ linear_sweep linear_spline HoverCraft_DiveBoardWidth * 0.1,
										HoverCraft_DiveBoardWidth * 0.4, 
										5,
		< HoverCraft_CenterBlockSize.y * HoverCraft_DiveBoardsYLink * 0.94, HoverCraft_DiveBoardDepth * 0.1 >,
		< HoverCraft_CenterBlockSize.y * HoverCraft_DiveBoardsYLink * 0.775, HoverCraft_DiveBoardDepth * 0.3 >,
		< HoverCraft_CenterBlockSize.y * HoverCraft_DiveBoardsYLink * 2, HoverCraft_DiveBoardDepth * 0.3 >,
		< HoverCraft_CenterBlockSize.y * HoverCraft_DiveBoardsYLink * 2, HoverCraft_DiveBoardDepth * 0.1 >,
		< HoverCraft_CenterBlockSize.y * HoverCraft_DiveBoardsYLink * 0.94, HoverCraft_DiveBoardDepth * 0.1 >
		
}

#declare HoverCraft_DiveBoard2_CylinderRadius = 0.05;
#declare HoverCraft_DiveBoard2_ExtremityAngleVector = vrotate( < 0, 0, -HoverCraft_DiveBoard2_CylinderRadius >, < 45, 0, 0 > );

#declare HoverCraft_DiveBoard2_Cylinder =
cylinder{ < 0, HoverCraft_DiveBoard2_Interstice, 0 >, < 0, HoverCraft_DiveBoardWidth - HoverCraft_DiveBoard2_Interstice, 0 >, 
			HoverCraft_DiveBoard2_CylinderRadius }

#declare HoverCraft_DiveBoard2 =
union{
	object{ HoverCraft_DiveBoard2_Cylinder 
		translate < HoverCraft_CenterBlockSize.y * HoverCraft_DiveBoardsYLink * 0.3, 0, HoverCraft_DiveBoardDepth * 1.1 > }
	difference{
		prism{ linear_sweep linear_spline HoverCraft_DiveBoard2_Interstice, 
										HoverCraft_DiveBoardWidth - HoverCraft_DiveBoard2_Interstice, 
										10,
			< 0, 0 >,
			< HoverCraft_CenterBlockSize.y * HoverCraft_DiveBoardsYLink, 0 >,
			< HoverCraft_CenterBlockSize.y * HoverCraft_DiveBoardsYLink * 0.95, HoverCraft_DiveBoardDepth * 0.1 >,
			< HoverCraft_CenterBlockSize.y * HoverCraft_DiveBoardsYLink * 0.875, HoverCraft_DiveBoardDepth * 0.3 >,
			< HoverCraft_CenterBlockSize.y * HoverCraft_DiveBoardsYLink * 0.25, HoverCraft_DiveBoardDepth * 0.73 >,
			< HoverCraft_CenterBlockSize.y * HoverCraft_DiveBoardsYLink * 0.25, HoverCraft_DiveBoardDepth * 0.91 >,
			< HoverCraft_CenterBlockSize.y * HoverCraft_DiveBoardsYLink * 0.3 + HoverCraft_DiveBoard2_ExtremityAngleVector.y, 
					HoverCraft_DiveBoardDepth * 1.1 + HoverCraft_DiveBoard2_ExtremityAngleVector.z >,
			< HoverCraft_CenterBlockSize.y * HoverCraft_DiveBoardsYLink * 0.3 - HoverCraft_DiveBoard2_ExtremityAngleVector.y, 
					HoverCraft_DiveBoardDepth * 1.1 - HoverCraft_DiveBoard2_ExtremityAngleVector.z >,
			< 0, HoverCraft_DiveBoardDepth >
			< 0, 0 >
		}
		object{ HoverCraft_DiveBoard2_DivePlace }
		object{ HoverCraft_DiveBoard2_DivePlace translate HoverCraft_DiveBoardWidth * 0.5 * y }
	}
	rotate 90 * z						
	translate < min_extent( HoverCraft_Floor ).x * HoverCraft_StructWidthPercent + HoverCraft_PilotBoxWidth + HoverCraft_DiveBoardWidth * 2, 
			min_extent( HoverCraft_Floor ).y - 0.001, 
			HoverCraft_PilotBoxZStart + HoverCraft_DiveBoard1_Size.z >
}

#declare HoverCraftObject =
union{
	object{ HoverCraft_FloaterGeom }
	union{
		object{ HoverCraft_Floor }
		object{ HoverCraft_FanGeom translate -HoverCraft_FanRoundRadius * 1.2 * x }
		object{ HoverCraft_FanGeom translate HoverCraft_FanRoundRadius * 1.2 * x }
		HoverCraft_PlaceFanBlade( 6, < -HoverCraft_FanRoundRadius * 1.2, 0, 0 > )
		HoverCraft_PlaceFanBlade( 6, < HoverCraft_FanRoundRadius * 1.2, 0, 0 > )
		object{ HoverCraft_BoxUnderTheFans }
		object{ HoverCraft_StructRearSlope }
		object{ HoverCraft_CenterBlock }
		object{ HoverCraft_CenterBlockPlaque }
		HoverCraft_PlaceCenterBlockLines(6)//This is a macro with the number of lines as parameter
		object{ HoverCraft_HollowPilotBox translate -0.02 * x }
		object{ HoverCraft_DiveBoard1 }
		object{ HoverCraft_DiveBoard2 }
		object{ HoverCraft_DiveBoard2 translate -HoverCraft_DiveBoardWidth * x }
		texture{ HoverCraft_MilitaryTexture }
	}
	object{ HoverCraft_PilotBoxCoverObjA texture{ HoverCraft_PilotBoxFacilityTexture } }
	object{ HoverCraft_PilotBoxCoverObjB texture{ HoverCraft_PilotBoxFacilityTexture } }
}

#macro HoverCraft_PlaceObject(AreFansTurning, Transform)
	union{
		object{ HoverCraft_FloaterGeom }
		union{
			object{ HoverCraft_Floor }
			object{ HoverCraft_FanGeom translate -HoverCraft_FanRoundRadius * 1.2 * x }
			object{ HoverCraft_FanGeom translate HoverCraft_FanRoundRadius * 1.2 * x }
			#if( AreFansTurning )
				HoverCraft_PlaceTurningFansEffect( < -HoverCraft_FanRoundRadius * 1.2, 0, 0 > )
				HoverCraft_PlaceTurningFansEffect( < HoverCraft_FanRoundRadius * 1.2, 0, 0 > )
			#else
				HoverCraft_PlaceFanBlade( 6, < -HoverCraft_FanRoundRadius * 1.2, 0, 0 > )
				HoverCraft_PlaceFanBlade( 6, < HoverCraft_FanRoundRadius * 1.2, 0, 0 > )
			#end
			object{ HoverCraft_BoxUnderTheFans }
			object{ HoverCraft_StructRearSlope }
			object{ HoverCraft_CenterBlock }
			object{ HoverCraft_CenterBlockPlaque }
			HoverCraft_PlaceCenterBlockLines(6)//This is a macro with the number of lines as parameter
			object{ HoverCraft_HollowPilotBox translate -0.02 * x }
			object{ HoverCraft_DiveBoard1 }
			object{ HoverCraft_DiveBoard2 }
			object{ HoverCraft_DiveBoard2 translate -HoverCraft_DiveBoardWidth * x }
			texture{ HoverCraft_MilitaryTexture }
		}
		object{ HoverCraft_PilotBoxCoverObjA texture{ HoverCraft_PilotBoxFacilityTexture } }
		object{ HoverCraft_PilotBoxCoverObjB texture{ HoverCraft_PilotBoxFacilityTexture } }
		transform{ Transform }
	}
#end