triple y_axis = triple( 0, 1, 0 );
initial_fire_alt = 14 kilometer;

physical component booster {
  shape "booster_shape.txt", ( 0, 20000, 0 ) ( 1, 0, 0, 0 ) ( 15, 6, 15 );
  triple position = <nil>;
  triple velocity = <nil>;
  mass = 180 kg + fuel;
}

y_vel = dot( y_axis, booster.velocity );

altitude = dot( y_axis, booster.position );
triple thrust = if( fuel <= 0 kg || altitude > initial_fire_alt, 
		    triple( 0, 0, 0 ) newton,
		    altitude > 500 m && y_vel < -50 m/s, 
		    -gravity * ( 2 - altitude / initial_fire_alt ),
		    y_vel < -5 m/s, gravity * -1.1, 
		    altitude > 25 m, -gravity,
		    altitude < 3.1 m, triple( 0, 0, 0 ) newton,
		    y_vel < -1 m/s, gravity * -1.1, gravity * -.9 );
		     
real g_acc = -9.81 m/s2 * 1/2; /* acceleration due to gravity */
triple gravity = y_axis * g_acc * booster.mass;

link booster : force thrust, ( 0, -1, 0 ), ( 0, 0, 0 );
link booster : force gravity, ( 0, 0, 0 ), ( 0, 0, 0 ); // gravity

//triple blah = triple( 1, 0, 0 ) * 20;

//contact_vel = .5 m/s;
//triple max_thrust = -gravity * 2;

constraint check_high = altitude > 10 kilometer;
constraint check_low = altitude > 2.5 kilometer;
constraint check_landed = altitude > 3.75 meter; /* height is 6m so com will rest at 3m */

constraint no_crash = check_landed || mag( velocity ) < 5 m/s;

//triple act_vel = ( velocity - old velocity ) * ( 1 / delta_time );

isp = 220 sec;
fuel_rate( triple thrust ) = mag( thrust ) / isp / 9.81 m/s2;
fuel = fuel - ( fuel_rate( old thrust ) * delta_time ) : 145 kg;

/*
adv_t adv_t adv_t adv_t adv_t adv_t  adv_t adv_t adv_t  adv_t adv_t adv_t  adv_t adv_t adv_t  

adv_t position velocity
 */

blah = mag( thrust );





