// POVRay code to render a nice array of StrongARM chips. Requires
// version >= 3.1
// (C) Marc Joosen 1999, 2000

#include "colors.inc"
#include "metals.inc"

// comment out a line to disable rendering

//#declare showorigin = 1;

//#declare Pins = 0;
//#declare Pins = 1;
#declare Pins = 52;

#declare showtexture = 1;
#declare showellipsoid = 1;
#declare showbumps = 1;
#declare showtext = 1;

//#declare Traces = 0;
//#declare Traces = 1;
#declare Traces = 52;

//#declare ClusterX = 1;
//#declare ClusterX = 2;
#declare ClusterX = 4;

//#declare ClusterZ = 1;
//#declare ClusterZ = 2;
#declare ClusterZ = 4;

#declare showplane = 1;

// Look at chip (0, 0)
#declare Pos = <10, 20, -10>; #declare Look = <-2, 0, 4>; // Corner 1
//#declare Pos = <10, 20, 170>; #declare Look = <-2, 0, 157>; // Corner 2
//#declare Pos = <-170, 20, 170>; #declare Look = <-155, 0, 157>; // Corner 3
//#declare Pos = <-170, 20, -10>; #declare Look = <-155, 0, 4>; // Corner 4
//#declare Pos = <-80, 250, 80>; #declare Look = <-80, 0, 80>; // Center

// These were from the single LART
//#declare Pos = <100, 120, -20>; #declare Look = <-60, 0, 80>; // Overview1
//#declare Pos = <125, 150, -15>; #declare Look = <-60, 0, 85>; // Overview2

//#declare Pos = <-75, 180, 185>; #declare Look = <-270, 0, 290>;

camera {  
	//angle 60
	angle 52
	location Pos
	look_at Look
}

//light_source { <-80, 80, 80> color White }
//light_source { Pos+20*y color Gray80 }
//light_source { Pos+<-100, 2000, 100> color Gray75  }
light_source {
	Pos+<-80, 500, 80>
	color Gray85

	area_light 50*x, 50*z, 4, 4
	adaptive 1
	jitter
}
light_source {
	Pos + <160, 200, 320>
	color White
	spotlight //cylinder
	point_at Look
	radius 10
	falloff 13
	tightness 40 

	area_light <20, 0, 0>, <0, 20, 0>, 4, 4
	adaptive 1
	jitter
}

// Show the origin
#ifdef(showorigin)
cylinder { 0, x 0.1 pigment { Red } }
cylinder { 0, y 0.1 pigment { Green } }
cylinder { 0, z 0.1 pigment { Blue } }
#end

#declare Pin = merge {
	box {
		<0, -1, 0>,
		<1, -2, -2>
	}
	lathe {
		linear_spline
		5,
		<1,0>, <2,0>, <2,1>, <1,1>, <1,0>
		rotate 90*z
		translate 1*x
		clipped_by { plane { <0,0,-1>, 0 } }
		clipped_by { plane { <0,1,0>, 0 } }
	}
	box {
		<0, 0, 1>,
		<1, 1, 2>
	}
	lathe {
		linear_spline
		5,
		<1,0>, <2,0>, <2,1>, <1,1>, <1,0>
		rotate 90*z
		translate 1*x
		clipped_by { plane { <0,0,-1>, 0 } }
		clipped_by { plane { <0,1,0>, 0 } }
		rotate 180*x
		translate <0,1,3>
	}
	box {
		<0, -1, 0>,
		<1, -2, -2>
		translate <0, 4, 5>
	}
	texture { T_Silver_1A }
	translate <-1, 2, -3>
}

// The chip texture
#ifdef(showtexture)
	#declare ChipTexture = texture {
		pigment { color Gray30 }
		finish {
			ambient 0.02
			diffuse 0.5
			reflection 0.1
			brilliance 3
			specular 0.4
		}
		normal {
			bumps 0.1
			scale 0.05
		}
	}
	#declare BumpTexture = texture {
		ChipTexture
	}
#else
	#declare ChipTexture = texture {
		pigment { color Gray30 }
	}
	#declare BumpTexture = texture {
		pigment { Black }
	}
#end

#declare Chip = difference {
	// The body
	#ifdef(showellipsoid)
		superellipsoid {
			<0.045, 0.040>
			scale <81, 3, 81>
			translate <-77, 4.5, 82>
			texture { ChipTexture }
		}
	#else
		box {
			<4, 2.5, 1>, <-159, 7.5, 163>
			//pigment { Yellow }
			texture { ChipTexture }
		}
	#end

	// The bumps and the text
	// These cutaway objects don't actually touch, but this is easier
	union {
		#ifdef(showbumps)
			sphere {
				<-2, 9, 7>, 2
				texture { BumpTexture }
			}
			cylinder {
				<-12, 7, 147>, <-12, 8, 147>, 8
				texture { BumpTexture }
			}
			cylinder {
				<-141, 7, 17>, <-141, 8, 17>, 8
				texture { BumpTexture }
			}
		#end
		#ifdef(showtext)
			text {
				ttf "impact.ttf",
				"Cluster",
				1, 0
				scale <44.5, 44.5, 1>
				rotate 90*x
				rotate -90*y
				translate <-92, 8, 16>
				pigment {Red} finish {ambient 0.3}
			}
			text {
				ttf "impact.ttf",
				"LART",
				1, 0
				scale <72, 72, 1>
				rotate 90*x
				rotate -90*y
				translate <-25, 8, 16>
				pigment {Red} finish {ambient 0.3}
			}
		#end
	}
}

// A trace
#declare Trace = box {
	<0, -0, 2>,
	<1, -0.2, -32>
	texture { T_Copper_1A }
	translate <-1, 0, -3>
}

#macro PlacePin(at)
	#local Count = 0;

	#while (Count < Pins)
		object { Pin              translate <-3*Count, 0, 0>     translate at }
		object { Pin rotate  90*y translate <-159, 0, 5+3*Count> translate at }
		object { Pin rotate 180*y translate <-1-3*Count, 0, 164> translate at }
		object { Pin rotate 270*y translate <5, 0, 6+3*Count>    translate at }
		#declare Count = Count+1;
	#end
#end

#macro PlaceChip(at)
	object { Chip translate at }
#end

#macro PlaceTrace(at)
	#local Count = 0;

	#while (Count < Traces)
		object { Trace              translate <-3*Count, 0, 0>     translate at }
//		object { Trace rotate  90*y translate <-159, 0, 5+3*Count> translate at }
//		object { Trace rotate 180*y translate <-1-3*Count, 0, 164> translate at }
		object { Trace rotate 270*y translate <5, 0, 6+3*Count>    translate at }
		#declare Count = Count+1;
	#end
#end

#declare Countx = 0;
#while (Countx < ClusterX)
	#declare Countz = 0;
	#while (Countz < ClusterZ)
		PlacePin(<-200*Countx, 0, 200*Countz>)
		PlaceChip(<-200*Countx, 0, 200*Countz>)
		PlaceTrace(<-200*Countx, 0, 200*Countz>)
		#declare Countz = Countz+1;
	#end
	#declare Countx = Countx+1;
#end

#ifdef(showplane)
plane { y, -0.2
//	pigment { Green }
	pigment {color rgb <0.1328 0.543 0.1328>}
	finish { ambient 0.3 }
}
#end
