/* Parameter:
 *	R1, R2:	Durchmesser des Torus
 *	Ringwulst_Triebwerk_An: (-45, 0, 45) Sind Triebwerke an, und
 *	wenn ja, in welche Richtung?
 */

#if (!defined(Ringwulst_Triebwerk_An))
    #declare Ringwulst_Triebwerk_An = 0;
#end

#declare Hangars_Ringwulst_neg = 
    difference {
	union {
	    #declare i = 10;
	    #declare ii = 10;
	    #while (i < 360) 
		union {
		    box {
			<-50, 40, 0>
			< 50, 80, R1+R2>
		    }
		    box {
			<-50, 120, 0>
			< 50, 220, R1+R2>
		    }
		    box {
			<-50, -40, 0>
			< 50, -80, R1+R2>
		    }
		    box {
			<-50, -120, 0>
			< 50, -220, R1+R2>
		    }
		    rotate <0, i, 0>
		}
		#declare i = i + ii;
		#declare ii = 30 - ii;

	    #end
	}
	torus {
	    R1, R2-10
	}
	texture {
	    Ynkelonium_Texture
	}
    }

#declare Geschuetze_Ringwulst_aussen =
    union {
	#declare w = -45;
	#while (w <= 45) 
	    #declare i = 10;
	    #declare ii = 10;
	    #while (i < 360) 
		union {
		    sphere {
			<0, 0, 0> 20
		    }
		    cone {
			<0, 0, 0> 10
			<30, 30, 0> 5
		    }
		    cone {
			<0, 0, 0> 10
			<30, -30, 0> 5
		    }
		    translate <R2, 0, 0>
		    rotate <0, 0, w>
		    translate <R1, 0, 0>
		    rotate <0, i, 0>
		}
		#declare i = i + ii;
		#declare ii = 30 - ii;
	    #end
	    #declare w = w + 90;
	#end
	texture {
	    Ynkelonium_Texture
	}

    }

#declare Geschuetze_Ringwulst_mitte =
    union {
	#declare w = 0;
	#while (w <= 0) 
	    #declare i = 0;
	    #while (i < 360) 
		union {
		    sphere {
			<0, 0, 0> 20
		    }
		    cone {
			<0, 0, 0> 10
			<30, 30, 0> 5
		    }
		    cone {
			<0, 0, 0> 10
			<30, -30, 0> 5
		    }
		    translate <R2, 0, 0>
		    rotate <0, 0, w>
		    translate <R1, 0, 0>
		    rotate <0, i, 0>
		}
		#declare i = i + 10;
	    #end
	    #declare w = w + 90;
	#end
	texture {
	    Ynkelonium_Texture
	}

    }

#declare Ringwulst = 
    union {
	difference {
	    torus {
		R1, R2
	    }
	    #declare i = 0;
	    #while (i < 360) 
		object {
		    Triebwerk_neg
		    rotate <0, 0, 45>
		    translate <R1, 0, 0>
		    rotate <0, i, 0>
		}
		object {
		    Triebwerk_neg
		    rotate <0, 0, -45>
		    translate <R1, 0, 0>
		    rotate <0, i, 0>
		}
		#declare i = i + 30;
	    #end
	    object {Hangars_Ringwulst_neg}
	}
	#if (Ringwulst_Triebwerk_An)
	    #local i = 0;
	    #while (i < 360) 
		intersection {
		    cylinder {
			<0, 0, 0> <1, 0, 0> 1
		    }
		    sphere {
			<0, 0, 0>, 1
		    }
		    hollow on
		    pigment { rgbt 1.0 }
		    interior {
			media {
			    emission rgb <0.2, 0.4, 0.8>
			    density {
				gradient x
				density_map {
				    [0.0 rgb 0.05]
				    [0.5 rgb 0.01]
				    [1.0 rgb 0.0]
				}
			    }
			}
		    }
		    scale <500, 60, 60>
		    translate <350, 0, 0>
		    rotate <0, 0, Ringwulst_Triebwerk_An>
		    translate <R1, 0, 0>
		    rotate <0, i, 0>
		}
		#local i = i + 30;
	    #end
	#end
	cone {
	    <0, -R2, 0>, R1, 
	    <0, R2, 0>, R1
	}
	object {Geschuetze_Ringwulst_aussen}
	object {Geschuetze_Ringwulst_mitte}

	texture {
	    Ynkelonium_Texture
	}

    }
