DEFINITION  
    output     = "pix/cproj";
    xleft = 0; xright = 323;
    ylow  = 0; yhigh  = 242;
    up         = yaxis;
    startframe = 1.000000;
    endframe   = 150.000000;
    byframe = 1;

	triple	CameraView(0.0, 0.0, 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        */

    shader Shader1 ( model = lambert, color = (255.0, 255.0, 255.0),
                     incandescence = (255, 255, 255) );

MODEL

{
    camera( eye   = (0.0, 0.0, 4.0)
           ,view  = CameraView
           ,fov   = (40.0),
            viewport = (xleft, xright, ylow, yhigh),
            aspect   = ((xright-xleft)+1)/((yhigh-ylow)+1)
    );
}
{
    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);
    scale     (0.1, 0.1, 0.1);
    patch (shader = ( Shader1 ),
           doublesided = FALSE, vclosed = TRUE, 
           subdivide = uniform, divisions = (2.000000, 2.000000),
           udegree = 3, vdegree = 3,
           uknots = (-0.666667, -0.333333, 0.000000, 0.333333, 0.666667,
                      1.000000,  1.333333, 1.666667),
           vknots = (-0.333333, -0.166667, 0.000000, 0.166667, 0.333333,
                      0.500000,  0.666667, 0.833333, 1.000000, 1.166667,
                      1.333333),
           cvs = ((cv( (-0.311775, -0.300000, -0.540010), 1.0 ),
                   cv( (-0.623550, -0.300000,  0.000000), 1.0 ),
                   cv( (-0.311775, -0.300000,  0.540010), 1.0 ),
                   cv( ( 0.311775, -0.300000,  0.540010), 1.0 ),
                   cv( ( 0.623549, -0.300000,  0.000000), 1.0 ),
                   cv( ( 0.311774, -0.300000, -0.540010), 1.0 ),
                   cv( (-0.311775, -0.300000, -0.540010), 1.0 ),
                   cv( (-0.623550, -0.300000,  0.000000), 1.0 ),
                   cv( (-0.311775, -0.300000,  0.540010), 1.0 )),
                  (cv( ( 0.000000, -0.600000,  0.000000), 1.0 ),
                   cv( ( 0.000000, -0.600000,  0.000000), 1.0 ),
                   cv( ( 0.000000, -0.600000,  0.000000), 1.0 ),
                   cv( ( 0.000000, -0.600000,  0.000000), 1.0 ),
                   cv( ( 0.000000, -0.600000,  0.000000), 1.0 ),
                   cv( ( 0.000000, -0.600000,  0.000000), 1.0 ),
                   cv( ( 0.000000, -0.600000,  0.000000), 1.0 ),
                   cv( ( 0.000000, -0.600000,  0.000000), 1.0 ),
                   cv( ( 0.000000, -0.600000,  0.000000), 1.0 )),
                  (cv( ( 0.311769, -0.300000,  0.539999), 1.0 ),
                   cv( ( 0.623538, -0.300000,  0.000000), 1.0 ),
                   cv( ( 0.311769, -0.300000, -0.539999), 1.0 ),
                   cv( (-0.311769, -0.300000, -0.539999), 1.0 ),
                   cv( (-0.623538, -0.300000,  0.000000), 1.0 ),
                   cv( (-0.311769, -0.300000,  0.539999), 1.0 ),
                   cv( ( 0.311769, -0.300000,  0.539999), 1.0 ),
                   cv( ( 0.623538, -0.300000,  0.000000), 1.0 ),
                   cv( ( 0.311769, -0.300000, -0.539999), 1.0 )),
                  (cv( ( 0.311769,  0.300000,  0.539999), 1.0 ),
                   cv( ( 0.623537,  0.300000,  0.000000), 1.0 ),
                   cv( ( 0.311769,  0.300000, -0.539999), 1.0 ),
                   cv( (-0.311769,  0.300000, -0.539999), 1.0 ),
                   cv( (-0.623537,  0.300000,  0.000000), 1.0 ),
                   cv( (-0.311768,  0.300000,  0.539999), 1.0 ),
                   cv( ( 0.311769,  0.300000,  0.539999), 1.0 ),
                   cv( ( 0.623537,  0.300000,  0.000000), 1.0 ),
                   cv( ( 0.311769,  0.300000, -0.539999), 1.0 )),
                  (cv( ( 0.000000,  0.599999,  0.000000), 1.0 ),
                   cv( ( 0.000000,  0.599999,  0.000000), 1.0 ),
                   cv( ( 0.000000,  0.599999,  0.000000), 1.0 ),
                   cv( ( 0.000000,  0.599999,  0.000000), 1.0 ),
                   cv( ( 0.000000,  0.599999,  0.000000), 1.0 ),
                   cv( ( 0.000000,  0.599999,  0.000000), 1.0 ),
                   cv( ( 0.000000,  0.599999,  0.000000), 1.0 ),
                   cv( ( 0.000000,  0.599999,  0.000000), 1.0 ),
                   cv( ( 0.000000,  0.599999,  0.000000), 1.0 )),
                  (cv( (-0.311775,  0.299999, -0.540010), 1.0 ),
                   cv( (-0.623549,  0.299999,  0.000000), 1.0 ),
                   cv( (-0.311775,  0.299999,  0.540010), 1.0 ),
                   cv( ( 0.311775,  0.299999,  0.540010), 1.0 ),
                   cv( ( 0.623549,  0.299999,  0.000000), 1.0 ),
                   cv( ( 0.311774,  0.299999, -0.540009), 1.0 ),
                   cv( (-0.311775,  0.299999, -0.540010), 1.0 ),
                   cv( (-0.623549,  0.299999,  0.000000), 1.0 ),
                   cv( (-0.311775,  0.299999,  0.540010), 1.0 ))
        )
    );
}
