/* best results with "powercaster -a5 -t0.9 cproj" */

DEFINITION
    output     = "pix/steiner_delta";
    xleft = 0; xright = 323;
    ylow  = 0; yhigh  = 242;
    up         = yaxis;
    startframe = 1.000000;
    endframe   = 60.000000;
    byframe = 1;
 
    triple	CameraView(0.0, 0.03, 0.0);

    scalar gravity( -1.5 );    /* the gravitational force */
    scalar mass(     1.0 );    /* the mass of the projectile */
    scalar angle(   65.0 );    /* the angle of elevation of the cannon */
    scalar dt(      1/30 );    /* the time increment */
    scalar yelasticity( 0.6 ); /* the reflective elastic coefficient */
    scalar xelasticity( 0.6 ); /* the tangential elastic coefficient */
    scalar floory( -0.2 );     /* the altitude of the ground */
    scalar drag( -0.1 );       /* the atmospheric drag */

    scalar x(0);               /* the position of the projectile */
    scalar y(0);
    scalar z(0);

    scalar xp(0);              /* position at previous iteration */
    scalar yp(0);
    scalar zp(0);

    scalar vx(0);              /* the velocity of the projectile */
    scalar vy(0);
    scalar vz(0);

    scalar fx(0);              /* the forces acting on the projectile */
    scalar fy(0);
    scalar fz(0);

    scalar az(0);              /* the acceleration of the projectile */
    scalar ay(0);
    scalar ax(0);

    scalar xi(0);              /* point of contact with floor        */

    scalar delta(0.1);
    scalar divisor(2.0);
    scalar object_size(0.04);

    pc param_curve ( in = PRE_CONSTANT, out = POST_CONSTANT, cvs = (
		pv(   1.0    ,   0.0    , TAN_LINEAR, (  -1.0    ,   0.0     ), TAN_LINEAR, (  0.1644 ,   0.98639) ),
		pv(  60.0    ,  354.0    , TAN_LINEAR, (  -0.1644 ,  -0.98639 ), TAN_LINEAR, (  1.0    ,   0.0    ) )
	) );

triple Lightview#2(0.0, 0.0, 0.0);
triple Lightup#2(0.0, 0.0, 0.0);
triple Lightview#3(0.0, 0.0, 0.0);
triple Lightup#3(0.0, 0.0, 0.0);
triple Lightview(0.0, 0.0, 0.0);
triple Lightup(0.0, 0.0, 0.0);

light Light#2 ( model = spot,
	active = ON,
	exclusive = FALSE,
	light_emission = ON,
	color = (191.573456, 193.107498, 210.077713),
	shadow_color = (0.0, 0.0, 0.0),
	intensity = 33.720932,
	force_type = OFF,
	force_intensity = 1.0,
	warp = OFF,
	glow_type = OFF,
	halo_type = OFF,
	fog_type = OFF,
	flare = OFF,
	psys_emission = OFF,
	shadow = FALSE,
	soft_shadows = FALSE,
	light_radius = 1.0,
	shadow_samples = 2.0,
	use_shadow_map = 0.0,
	dropoff = 0.0,
	spread = 90.0,
	penumbra = 0.0,
	shadow_resolution = 512,
	shadow_edge_quality = 2,
	fog_samples = 50,
	shadow_min_depth = 0.050000,
	shadow_blend_offset = 1.000000,
	shine_along  = forward(Lightview#2),
	up_spot  = forward(Lightup#2),
	decay = 1.0
);

light Light#3 ( model = spot,
	active = ON,
	exclusive = FALSE,
	light_emission = ON,
	color = (247.435364, 255.0, 232.538864),
	shadow_color = (0.0, 0.0, 0.0),
	intensity = 39.534885,
	force_type = OFF,
	force_intensity = 1.0,
	warp = OFF,
	glow_type = OFF,
	halo_type = OFF,
	fog_type = OFF,
	flare = OFF,
	psys_emission = OFF,
	shadow = FALSE,
	soft_shadows = FALSE,
	light_radius = 1.0,
	shadow_samples = 2.0,
	use_shadow_map = 0.0,
	dropoff = 0.0,
	spread = 90.0,
	penumbra = 0.0,
	shadow_resolution = 512,
	shadow_edge_quality = 2,
	fog_samples = 50,
	shadow_min_depth = 0.050000,
	shadow_blend_offset = 1.000000,
	shine_along  = forward(Lightview#3),
	up_spot  = forward(Lightup#3),
	decay = 1.0
);

light Light ( model = spot,
	active = ON,
	exclusive = FALSE,
	light_emission = ON,
	color = (249.653412, 255.0, 240.466324),
	shadow_color = (0.0, 0.0, 0.0),
	intensity = 52.325581,
	force_type = OFF,
	force_intensity = 1.0,
	warp = OFF,
	glow_type = OFF,
	halo_type = OFF,
	fog_type = OFF,
	flare = OFF,
	psys_emission = OFF,
	shadow = FALSE,
	soft_shadows = FALSE,
	light_radius = 1.0,
	shadow_samples = 2.0,
	use_shadow_map = 0.0,
	dropoff = 0.0,
	spread = 90.0,
	penumbra = 0.0,
	shadow_resolution = 512,
	shadow_edge_quality = 2,
	fog_samples = 50,
	shadow_min_depth = 0.050000,
	shadow_blend_offset = 1.000000,
	shine_along  = forward(Lightview),
	up_spot  = forward(Lightup),
	decay = 1.0
);

shader DefaultShader ( model = phong,
        diffuse = 1.0,
        specular = (0.127907, 0.127907, 0.037113),
        shinyness = 11,
        reflectivity = 0.139535,
        reflect_background = OFF,
        color = (208.756485, 208.756485, 48.67379),
        incandescence = (17.790699, 17.790699, 9.863237),
        transparency = (0.0, 0.0, 0.0), /* (70.075485, 79.053925, 88.911911), */
        shading_map = (0.0, 0.0, 0.0),
        translucence = 0.0,
        translucence_depth = 0.5,
        opacity_depth = 0.0,
        use_background_color = OFF,
        matte_fraction = 0.0,
        psys_emission = OFF,
        glow_intensity = 0.0,
        hide_glow_source = OFF,
        refractive_index = 1.6,
        reflection_limit = 1,
        refraction_limit = 6,
        shadow_level_limit = 0,
        surface_width = 0.0,
        transparency_shade = 0.0,
        transparency_depth = 0.0,
        chromatic_abberation = 0.0,
        refraction_jitter = 0.0,
        refraction_samples = 0,
        respect_reflection_map = OFF,
        use_fill_color = ON,
        fill_color = (255.0, 255.0, 255.0),
        u_patch_lines = 0,
        v_patch_lines = 0,
        density = 1.0,
        elasticity = 0.707,
        friction = 0.0,
        drag_coeff = 0.5
);

patch sphere_patch (
	udegree = 3, vdegree = 3,
	doublesided = FALSE, opposite = FALSE,
	subdivide = adaptive,
	divisions = (2, 4),
	curvature = 0.96,
	uclosed = ON, shader = (DefaultShader),
	casts_shadow = ON, motion_blur = OFF,
	active = ON,
	uknots = ( 0.0      ,  1.0      ,  2.0      ,  3.0      ,  4.0      ,
				 5.0      ,  6.0      ,  7.0      ,  8.0      ,  9.0      ,
				 10.0      ,  11.0      ,  12.0      ),
	vknots = ( 2.0      ,  2.0      ,  2.0      ,  3.0      ,  4.0      ,
				 5.0      ,  6.0      ,  6.0      ,  6.0      ),
	cvs = (
			(cv((0.0, 0.0, -0.5), 1.0),
			 cv((0.102341, -0.102341, -0.5), 1.0),
			 cv((0.307024, -0.307024, -0.391806), 1.0),
			 cv((0.434197, -0.434197, 0.0), 1.0),
			 cv((0.307024, -0.307024, 0.391806), 1.0),
			 cv((0.102341, -0.102341, 0.5), 1.0),
			 cv((0.0, 0.0, 0.5), 1.0) ),

			(cv((0.0, 0.0, -0.5), 1.0),
			 cv((0.144732, 0.0, -0.5), 1.0),
			 cv((0.434197, 0.0, -0.391806), 1.0),
			 cv((0.614047, 0.0, 0.0), 1.0),
			 cv((0.434197, 0.0, 0.391806), 1.0),
			 cv((0.144732, 0.0, 0.5), 1.0),
			 cv((0.0, 0.0, 0.5), 1.0) ),

			(cv((0.0, 0.0, -0.5), 1.0),
			 cv((0.102341, 0.102341, -0.5), 1.0),
			 cv((0.307024, 0.307024, -0.391806), 1.0),
			 cv((0.434197, 0.434197, 0.0), 1.0),
			 cv((0.307024, 0.307024, 0.391806), 1.0),
			 cv((0.102341, 0.102341, 0.5), 1.0),
			 cv((0.0, 0.0, 0.5), 1.0) ),

			(cv((0.0, 0.0, -0.5), 1.0),
			 cv((0.0, 0.144732, -0.5), 1.0),
			 cv((0.0, 0.434197, -0.391806), 1.0),
			 cv((0.0, 0.614047, 0.0), 1.0),
			 cv((0.0, 0.434197, 0.391806), 1.0),
			 cv((0.0, 0.144732, 0.5), 1.0),
			 cv((0.0, 0.0, 0.5), 1.0) ),

			(cv((0.0, 0.0, -0.5), 1.0),
			 cv((-0.102341, 0.102341, -0.5), 1.0),
			 cv((-0.307024, 0.307024, -0.391806), 1.0),
			 cv((-0.434197, 0.434197, 0.0), 1.0),
			 cv((-0.307024, 0.307024, 0.391806), 1.0),
			 cv((-0.102341, 0.102341, 0.5), 1.0),
			 cv((0.0, 0.0, 0.5), 1.0) ),

			(cv((0.0, 0.0, -0.5), 1.0),
			 cv((-0.144732, 0.0, -0.5), 1.0),
			 cv((-0.434197, 0.0, -0.391806), 1.0),
			 cv((-0.614047, 0.0, 0.0), 1.0),
			 cv((-0.434197, 0.0, 0.391806), 1.0),
			 cv((-0.144732, 0.0, 0.5), 1.0),
			 cv((0.0, 0.0, 0.5), 1.0) ),

			(cv((0.0, 0.0, -0.5), 1.0),
			 cv((-0.102341, -0.102341, -0.5), 1.0),
			 cv((-0.307024, -0.307024, -0.391806), 1.0),
			 cv((-0.434197, -0.434197, 0.0), 1.0),
			 cv((-0.307024, -0.307024, 0.391806), 1.0),
			 cv((-0.102341, -0.102341, 0.5), 1.0),
			 cv((0.0, 0.0, 0.5), 1.0) ),

			(cv((0.0, 0.0, -0.5), 1.0),
			 cv((0.0, -0.144732, -0.5), 1.0),
			 cv((0.0, -0.434197, -0.391806), 1.0),
			 cv((0.0, -0.614047, 0.0), 1.0),
			 cv((0.0, -0.434197, 0.391806), 1.0),
			 cv((0.0, -0.144732, 0.5), 1.0),
			 cv((0.0, 0.0, 0.5), 1.0) ),

			(cv((0.0, 0.0, -0.5), 1.0),
			 cv((0.102341, -0.102341, -0.5), 1.0),
			 cv((0.307024, -0.307024, -0.391806), 1.0),
			 cv((0.434197, -0.434197, 0.0), 1.0),
			 cv((0.307024, -0.307024, 0.391806), 1.0),
			 cv((0.102341, -0.102341, 0.5), 1.0),
			 cv((0.0, 0.0, 0.5), 1.0) ),

			(cv((0.0, 0.0, -0.5), 1.0),
			 cv((0.144732, 0.0, -0.5), 1.0),
			 cv((0.434197, 0.0, -0.391806), 1.0),
			 cv((0.614047, 0.0, 0.0), 1.0),
			 cv((0.434197, 0.0, 0.391806), 1.0),
			 cv((0.144732, 0.0, 0.5), 1.0),
			 cv((0.0, 0.0, 0.5), 1.0) ),

			(cv((0.0, 0.0, -0.5), 1.0),
			 cv((0.102341, 0.102341, -0.5), 1.0),
			 cv((0.307024, 0.307024, -0.391806), 1.0),
			 cv((0.434197, 0.434197, 0.0), 1.0),
			 cv((0.307024, 0.307024, 0.391806), 1.0),
			 cv((0.102341, 0.102341, 0.5), 1.0),
			 cv((0.0, 0.0, 0.5), 1.0) )
	)
);



ENVIRONMENT
background ( 
        color = (232.538864, 230.460007, 221.695068)
);
shader_glow ( 
,
        glow_type =  LINEAR_GLOW,
        halo_type =  LINEAR_GLOW,
        auto_exposure = ON,
        quality = 0.5,
        threshold = 0.0,
        glow_color = (100.0, 100.0, 100.0),
        glow_intensity = 1.0,
        glow_spread = 0.05,
        glow_eccentricity = 0.1,
        glow_radial_noise = 0.0,
        glow_star_level = 0.0,
        glow_opacity = 0.0,
        halo_color = (100.0, 100.0, 100.0),
        halo_intensity = 1.0,
        halo_spread = 0.3,
        halo_eccentricity = 0.1,
        halo_radial_noise = 0.0,
        halo_star_level = 0.0,
        halo_lens_flare = 0.0,
        rotation = 0.0,
        radial_noise_frequency = 0.5,
        star_points = 4.0
);
photo_effects ( 
,
        film_grain = 0.0,
        filter = (255.0, 255.0, 255.0)
);
master_light ( 
,
        intensity = 1.860465,
        light_color = (255.0, 255.0, 255.0)
);

MODEL

{
    camera( /*eye = (1.0, 1.0, 1.0)*/
           /* eye = (1.0 - frame/135.0, 1.0 - frame/135.0, 1.0 - frame/135.0) */
           eye = (1.6, 0.0, 0.8)
           ,view  = CameraView
           ,fov   = (40.0),
            viewport = (xleft, xright, ylow, yhigh),
            aspect   = ((xright-xleft)+1)/((yhigh-ylow)+1)
    );
}
{
	trn(-120.317893, 9.256924, -147.570633);
	rot (zaxis, 205.2);
	rot (yaxis, 104.1);
	rot (xaxis, -1.6);
	{
		trn(-28.324287, -13.416588, 23.308075);
		inst Light#2();
	}
	{
		trn(-41.105949, -2.465721, 0.576248);
		Lightview#2 = current_position(( 0.0,  0.0,  0.0));
	}
	{
		trn(-57.98341, -40.685493, 114.835098);
		Lightup#2 = current_position(( 0.0,  0.0,  0.0));
	}
}
{
	trn(14.272966, 138.957579, 211.720094);
	{
		trn(-21.141764, 16.729355, 2.818878);
		inst Light#3();
	}
	{
		trn(-20.036221, 0.268448, -20.155396);
		Lightview#3 = current_position(( 0.0,  0.0,  0.0));
	}
	{
		trn(-87.261337, 30.992035, 76.471954);
		Lightup#3 = current_position(( 0.0,  0.0,  0.0));
	}
}
{
	trn(160.47639, 2.56537, 161.996174);
	rot (zaxis, 34.7);
	rot (yaxis, -0.7);
	rot (xaxis, -0.9);
	{
		trn(-5.138031, -13.812805, 0.027298);
		inst Light();
	}
	{
		trn(-20.774277, -0.479225, -19.407806);
		Lightview = current_position(( 0.0,  0.0,  0.0));
	}
	{
		trn(-20.372261, -44.951378, 93.826569);
		Lightup = current_position(( 0.0,  0.0,  0.0));
	}
}

{
    if( frame == 1.0 )
    {
        x  = -1.0;
        y  =  0.0;
        z  =  0.0;
        vx = (1.5 * cosd( angle ));
        vy = (1.5 * sind( angle ));
        vz =  0.0;
    }
    fx = (vx * drag);
    fy = (vy * drag) + (gravity * mass);
    fz = (vz * drag);
    ax = (fx / mass);
    ay = (fy / mass);
    az = (fz / mass);
    vx = (vx + (ax * dt));
    vy = (vy + (ay * dt));
    vz = (vz + (az * dt));
    xp = (x+0.0);
    yp = (y+0.0);
    zp = (z+0.0);
    x  = (x + (vx * dt) + ((0.5 * ax * dt) * dt));
    y  = (y + (vy * dt) + ((0.5 * ay * dt) * dt));
    z  = (z + (vz * dt) + ((0.5 * az * dt) * dt));
    if( y < floory )
    {
        vx = (vx * xelasticity);
        vy = (-vy * yelasticity);
        xi = (xp + (((x - xp) * (floory - yp)) / (y - yp)));
        x  = (xi + ((x - xp) * xelasticity));
        y  = (floory - ((y - floory) * yelasticity));
    }
    /*translate (x, y, z);*/

delta = ((0.02 - 0.06)/60.0)*(frame - 1) + 0.06;

rot (yaxis, animate( param_curve, frame ));    
{
    for (x = -0.5; x < 0.5; x = x + delta;) 
    {
        for (y = -0.5; y < 0.5; y = y + delta;) 
        {
            if (((x*x) + (y*y)) != 0) 
            {
                if (1 - (divisor*divisor*((x*x) + (y*y))) >= 0.0) 
                {
                    {
                        z = -x*y + (x*y*sqrt(1 - (divisor*divisor*((x*x) + (y*y)))) / (divisor * ((x*x) + (y*y))));
                        translate (x,y,z);
                        scale (object_size, object_size, object_size );
                        instance sphere_patch();
                    }
                    {
                        z = -x*y - (x*y*sqrt(1 - (divisor*divisor*((x*x) + (y*y)))) / (divisor * ((x*x) + (y*y))));
                        translate (x,y,z);
                        scale (object_size, object_size, object_size);
                        instance sphere_patch();
                    }
                }
            }
        }
    }
    for (z = -0.5; z < 0.5; z = z + delta;) 
    {
        for (y = -0.5; y < 0.5; y = y + delta;) 
        {
            if (((z*z) + (y*y)) != 0) 
            {
                if (1 - (divisor*divisor*((z*z) + (y*y))) >= 0.0) 
                {
                    {
                        x = -z*y + (z*y*sqrt(1 - (divisor*divisor*((z*z) + (y*y)))) / (divisor * ((z*z) + (y*y))));
                        translate (x,y,z);
                        scale (object_size, object_size, object_size);
                        instance sphere_patch();
                    }
                    {
                        x = -z*y - (z*y*sqrt(1 - (divisor*divisor*((z*z) + (y*y)))) / (divisor * ((z*z) + (y*y))));
                        translate (x,y,z);
                        scale (object_size, object_size, object_size);
                        instance sphere_patch();
                    }
                }
            }
        }
    }
    for (x = -0.5; x < 0.5; x = x + delta;) 
    {
        for (z = -0.5; z < 0.5; z = z + delta;) 
        {
            if (((x*x) + (z*z)) != 0) 
            {
                if (1 - (divisor*divisor*((x*x) + (z*z))) >= 0.0) 
                {
                    {
                        y = -x*z + (x*z*sqrt(1 - (divisor*divisor*((x*x) + (z*z)))) / (divisor * ((x*x) + (z*z))));
                        translate (x,y,z);
                        scale (object_size, object_size, object_size);
                        instance sphere_patch();
                    }
                    {
                        y = -x*z - (x*z*sqrt(1 - (divisor*divisor*((x*x) + (z*z)))) / (divisor * ((x*x) + (z*z))));
                        translate (x,y,z);
                        scale (object_size, object_size, object_size);
                        instance sphere_patch();
                    }
                }
            }
        }
    }
}

}