global_settings {
        
radiosity{
    pretrace_start 1 
    pretrace_end 1
    count 1600 error_bound 0.02 
    nearest_count 4
    recursion_limit 1
    low_error_factor 1
    gray_threshold 0
    minimum_reuse 0.015
    brightness 2
    adc_bailout 0.01/2 
    normal on
} }

//background { color rgb <1, 1, 1> }


#macro Camera( xpos, ypos, zpos, lookatx, lookaty, lookatz)
camera {
        location <xpos,-ypos, zpos>
        sky <0, 0, 1>
        look_at <lookatx, -lookaty, lookatz>
}
light_source 
{ 
   <0, 0, 8> rgb <0.8,0.8,0.8> 
   // area_light <1, 0, 0>, <0, 0, 1>, 20, 20
   // adaptive 1
   // jitter
    //circular

   spotlight 
   point_at <lookatx, lookaty, lookatz>  
   radius 15
   falloff 25
   tightness 0 
 
}
#end  




// JOINTS 

#macro Joint(xpos,ypos,zpos,Radius, xvel, yvel, zvel, xavel, yavel, zavel, r, g, b)

sphere { <xpos, -ypos, zpos>, Radius

	finish { ambient 0.45 phong .9 roughness 0.001 }

	pigment { color rgb <1, 1, 1>
        }

}
#end


// BLOOD
#macro Blood (xpos, ypos, zpos, Radius, xvel, yvel, zvel, xavel, yavel, zavel, r, g, b)
threshold 0.1
sphere {<xpos, -ypos, zpos>, Radius*5, 0.1 
	pigment { color rgb <0.8, 0, 0 > }
        finish {
                ambient .1
                diffuse .1
                specular 1
                roughness .001
                metallic
                reflection { .75 metallic }
	}
}
#end

// HEAD

#macro BodySphere (r, g, b, Radius,  rot0, rot3, rot6, rot1, rot4, rot7,  
rot2, rot5, rot8,  rot9, rot10, rot11, xvel, yvel, zvel, xavel, yavel, zavel)
sphere {

        <0, 0, 0>, Radius

    	matrix <rot0, -rot1, rot2,
	        rot3, -rot4, rot5,
	        rot6, -rot7, rot8,
                rot9, -rot10, rot11>

	finish { ambient 0.45 phong .9 roughness 0.001 }

        pigment { color rgb <r, g, b>
        }

}

#end



// LEGS

#macro BodyCapsule (r, g, b, Radius, length, rot0, rot3, rot6,  rot1, rot4, 
rot7,  rot2, rot5, rot8,  rot9, rot10, rot11, xvel, yvel, zvel, xavel, yavel, zavel)
union {

	cylinder {

		<0,0,-length*0.5>,
         	<0, 0, length - length*0.5>,
       		Radius
	}

	sphere   { <0, 0, -length*0.5>,  Radius }
       	sphere   { <0, 0, length - length *0.5>, Radius }

       	matrix <rot0, -rot1, rot2,
       	        rot3, -rot4, rot5,
       	        rot6, -rot7, rot8,
       	        rot9, -rot10, rot11>

	finish { ambient 0.45 phong .9 roughness 0.001 }

	pigment { color rgb <r, g, b>
        }

}

#end



// BODY PART

#macro Body (r, g, b, sidex, sidey, sidez, rot0, rot3, rot6,  rot1, rot4, 
rot7,  rot2, rot5, rot8,  rot9, rot10, rot11, xvel, yvel, zvel, xavel, yavel, zavel)
box {
       	<-(sidex*0.5), -(sidey*0.5), -(sidez*0.5)>,
       	<sidex*0.5, sidey*0.5, sidez*0.5>
       
	matrix <
       	rot0, -rot1, rot2,
       	rot3, -rot4, rot5,
       	rot6, -rot7, rot8,
       	rot9, -rot10, rot11>
// y == x

	finish { ambient 0.45 phong .9 roughness 0.001 }
       	pigment { color rgb <r, g, b>
        }
       
}

#end

/*#macro EnvBox (r, g, b, a, sidex, sidey, sidez, rot0, rot3, rot6,  rot1, rot4, rot7,  rot2, rot5, rot8,  rot9, rot10, rot11)
box {   
        <-(sidex*0.5), -(sidey*0.5), -(sidez*0.5)>,
        <sidex*0.5, sidey*0.5, sidez*0.5>
                
        matrix <rot0, -rot1, rot2, 
                rot3, -rot4, rot5, 
                rot6, -rot7, rot8, 
                rot9, -rot10, rot11>

	//Need Texture for this alpha
        pigment { color rgbf <0.8,0.8,0.8,0.8> }
	finish  {
                reflection 0.1  
                ambient 0.5     
                phong .5        
                specular 0.1    
                roughness .001
        }       
}  
#end

#macro EnvCapsule (r, g, b, a, Radius, length, rot0, rot3, rot6,  rot1, rot4, rot7,  rot2, rot5, rot8,  rot9, rot10, rot11)
union {
        cylinder {
                <0,0,-length*0.5>,
                <0, 0, length - length*0.5>,
                Radius
        }
        sphere   { <0, 0, -length*0.5>,  Radius }
        sphere   { <0, 0, length - length *0.5>, Radius }

        matrix <rot0, -rot1, rot2,
                rot3, -rot4, rot5,
                rot6, -rot7, rot8,
                rot9, -rot10, rot11>
	
	//Need Texture for this alpha
        pigment { color rgbf <0.8,0.8,0.8,0.8> }
        finish {
                reflection 0.1
                ambient 0.5
                phong .5
                specular 0.1
                roughness .001
        }
}
#end


#macro EnvSphere (r, g, b, a, Radius, rot0, rot3, rot6,  rot1, rot4, rot7,  rot2, rot5, rot8,  rot9, rot10, rot11)
sphere {
        <0, 0, 0>, Radius
        matrix <rot0, -rot1, rot2,
                rot3, -rot4, rot5,
                rot6, -rot7, rot8,
                rot9, -rot10, rot11>

	//Need Texture for this alpha
        pigment { color rgbf <0.8,0.8,0.8,0.8> }
        finish  {
                reflection 0.1
		ambient 0.5
		phong .5
                specular 0.1
                reflection .001
        }
}
#end */


#macro Impact (xpos, ypos, zpos, Radius, time, r, g, b, a)
torus {
        Radius, 0.5
	scale <1, 0.05, 1>
	rotate <90, 0, 90>
	translate <xpos, -ypos, zpos>
	
        pigment { 
		color rgb <r, g, b>
		filter (1-a)	//aka alpha 		
	}

        finish  {
       		reflection 0.2
               	ambient 0.5
               	phong .5
               	specular 0.1
               	refraction 1
       	}
}
#end

// GROUND
plane { z, 0
	pigment { rgb <1,1,1> }
       	finish {
       		ambient .01
       		diffuse .1
       		specular 1
       		roughness .001
       		metallic
       		reflection {.10
       		metallic
       		}
       	}

}







