329 lines
27 KiB
HTML
Executable File
329 lines
27 KiB
HTML
Executable File
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="generator" content="TempleOS V5.03">
|
|
<meta name="viewport" content="width=device-width">
|
|
<link rel="stylesheet" href="/style/templeos.css">
|
|
<script src="/script/templeos.js"></script>
|
|
<style type="text/css">
|
|
.cB0{color:#000000;background-color:#55ffff;}
|
|
.cBA{color:#55ff55;background-color:#55ffff;}
|
|
.cF0{color:#000000;background-color:#ffffff;}
|
|
.cF1{color:#0000aa;background-color:#ffffff;}
|
|
.cF2{color:#00aa00;background-color:#ffffff;}
|
|
.cF3{color:#00aaaa;background-color:#ffffff;}
|
|
.cF4{color:#aa0000;background-color:#ffffff;}
|
|
.cF5{color:#aa00aa;background-color:#ffffff;}
|
|
.cF6{color:#aa5500;background-color:#ffffff;}
|
|
.cF7{color:#aaaaaa;background-color:#ffffff;}
|
|
.cF8{color:#555555;background-color:#ffffff;}
|
|
.cF9{color:#5555ff;background-color:#ffffff;}
|
|
.cFA{color:#55ff55;background-color:#ffffff;}
|
|
.cFB{color:#55ffff;background-color:#ffffff;}
|
|
.cFC{color:#ff5555;background-color:#ffffff;}
|
|
.cFD{color:#ff55ff;background-color:#ffffff;}
|
|
.cFE{color:#ffff55;background-color:#ffffff;}
|
|
.cFF{color:#ffffff;background-color:#ffffff;}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<pre id="content">
|
|
<a name="l1"></a><span class=cF0>#</span><span class=cF1>define</span><span class=cF0> THRUST 1000
|
|
<a name="l2"></a>
|
|
<a name="l3"></a></span><span class=cF1>Bool</span><span class=cF0> blast_off,plane_hit;
|
|
<a name="l4"></a>
|
|
<a name="l5"></a></span><span class=cF9>CMass</span><span class=cF0> m1, </span><span class=cF2>//Bottom of rocket</span><span class=cF0>
|
|
<a name="l6"></a> m2, </span><span class=cF2>//Top of rocket</span><span class=cF0>
|
|
<a name="l7"></a> m3; </span><span class=cF2>//Plane</span><span class=cF0>
|
|
<a name="l8"></a></span><span class=cF9>CSpring</span><span class=cF0> s;
|
|
<a name="l9"></a>
|
|
<a name="l10"></a>#</span><span class=cF1>define</span><span class=cF0> ROCKET_HEIGHT 40
|
|
<a name="l11"></a>#</span><span class=cF1>define</span><span class=cF0> GROUND_Y (</span><span class=cF3>GR_HEIGHT</span><span class=cF0>-3*</span><span class=cF3>FONT_HEIGHT</span><span class=cF0>)
|
|
<a name="l12"></a></span><span class=cB0>
|
|
<a name="l13"></a>
|
|
<a name="l14"></a> </span><span class=cBA><1>/* Graphics Not Rendered in HTML */</span><span class=cB0>
|
|
<a name="l15"></a>
|
|
<a name="l16"></a>
|
|
<a name="l17"></a>
|
|
<a name="l18"></a> </span><span class=cBA><2>/* Graphics Not Rendered in HTML */</span><span class=cB0>
|
|
<a name="l19"></a>
|
|
<a name="l20"></a>
|
|
<a name="l21"></a>
|
|
<a name="l22"></a> </span><span class=cBA><3>/* Graphics Not Rendered in HTML */</span><span class=cB0>
|
|
<a name="l23"></a>
|
|
<a name="l24"></a></span><span class=cF0>
|
|
<a name="l25"></a>
|
|
<a name="l26"></a>
|
|
<a name="l27"></a>
|
|
<a name="l28"></a>
|
|
<a name="l29"></a>
|
|
<a name="l30"></a>
|
|
<a name="l31"></a>
|
|
<a name="l32"></a>
|
|
<a name="l33"></a>
|
|
<a name="l34"></a>
|
|
<a name="l35"></a>
|
|
<a name="l36"></a>
|
|
<a name="l37"></a>
|
|
<a name="l38"></a></span><span class=cFA>
|
|
<a name="l39"></a>/* Graphics Not Rendered in HTML */</span><span class=cF0>
|
|
<a name="l40"></a>
|
|
<a name="l41"></a></span><span class=cF9>CDC</span><span class=cF0> *dc2;
|
|
<a name="l42"></a></span><span class=cF9>CMathODE</span><span class=cF0> *ode;
|
|
<a name="l43"></a>
|
|
<a name="l44"></a>#</span><span class=cF1>define</span><span class=cF0> STATE_NOZZLE_ANGLE 0
|
|
<a name="l45"></a>#</span><span class=cF1>define</span><span class=cF0> STATE_NOZZLE_ANGLE_VELOCITY 1
|
|
<a name="l46"></a>#</span><span class=cF1>define</span><span class=cF0> STATE_NUM 2
|
|
<a name="l47"></a>
|
|
<a name="l48"></a></span><span class=cF9>CD3</span><span class=cF0> target;
|
|
<a name="l49"></a></span><span class=cF1>F64</span><span class=cF0> my_dbg,antispin_coefficient;
|
|
<a name="l50"></a>
|
|
<a name="l51"></a></span><span class=cF1>U0</span><span class=cF0> </span><span class=cF5>DrawIt</span><span class=cF0>(</span><span class=cF9>CTask</span><span class=cF0> *task,</span><span class=cF9>CDC</span><span class=cF0> *dc)
|
|
<a name="l52"></a>{
|
|
<a name="l53"></a> </span><span class=cF9>I64</span><span class=cF0> i,x,y,cx=</span><span class=cF3>GR_WIDTH</span><span class=cF0>/2,cy=GROUND_Y;
|
|
<a name="l54"></a> </span><span class=cF1>F64</span><span class=cF0> theta=</span><span class=cF5>Arg</span><span class=cF0>(m2.x-m1.x,m2.y-m1.y),
|
|
<a name="l55"></a> nozzle_angle=ode->state[STATE_NOZZLE_ANGLE];
|
|
<a name="l56"></a>
|
|
<a name="l57"></a> </span><span class=cF1>if</span><span class=cF0> (blast_off) </span><span class=cF7>{</span><span class=cF0>
|
|
<a name="l58"></a> x=m1.x-10*</span><span class=cF5>Cos</span><span class=cF0>(theta+nozzle_angle);
|
|
<a name="l59"></a> y=m1.y-10*</span><span class=cF5>Sin</span><span class=cF0>(theta+nozzle_angle);
|
|
<a name="l60"></a> </span><span class=cF1>for</span><span class=cF0> (i=0;i<6;i++) {
|
|
<a name="l61"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cF7>(</span><span class=cF0>i^</span><span class=cFB>winmgr</span><span class=cF0>.updates</span><span class=cF7>)</span><span class=cF0>&1)
|
|
<a name="l62"></a> dc->color=</span><span class=cF3>YELLOW</span><span class=cF0>;
|
|
<a name="l63"></a> </span><span class=cF1>else</span><span class=cF0>
|
|
<a name="l64"></a> dc->color=</span><span class=cF3>RED</span><span class=cF0>;
|
|
<a name="l65"></a> </span><span class=cF5>GrLine</span><span class=cF0>(dc,cx+</span><span class=cF7>(</span><span class=cF0>m1.x+i*</span><span class=cF5>Cos</span><span class=cF0>(theta-</span><span class=cF3>pi</span><span class=cF0>/2)</span><span class=cF7>)</span><span class=cF0>,cy-</span><span class=cF7>(</span><span class=cF0>m1.y+i*</span><span class=cF5>Sin</span><span class=cF0>(theta-</span><span class=cF3>pi</span><span class=cF0>/2)</span><span class=cF7>)</span><span class=cF0>,cx+x,cy-y);
|
|
<a name="l66"></a> </span><span class=cF5>GrLine</span><span class=cF0>(dc,cx+</span><span class=cF7>(</span><span class=cF0>m1.x+i*</span><span class=cF5>Cos</span><span class=cF0>(theta+</span><span class=cF3>pi</span><span class=cF0>/2)</span><span class=cF7>)</span><span class=cF0>,cy-</span><span class=cF7>(</span><span class=cF0>m1.y+i*</span><span class=cF5>Sin</span><span class=cF0>(theta+</span><span class=cF3>pi</span><span class=cF0>/2)</span><span class=cF7>)</span><span class=cF0>,cx+x,cy-y);
|
|
<a name="l67"></a> }
|
|
<a name="l68"></a>
|
|
<a name="l69"></a> </span><span class=cF1>for</span><span class=cF0> (i=0;i<10;i++) {
|
|
<a name="l70"></a> </span><span class=cF1>switch</span><span class=cF0> (</span><span class=cF5>RandU16</span><span class=cF0>&3) </span><span class=cF7>{</span><span class=cF0>
|
|
<a name="l71"></a> </span><span class=cF1>case</span><span class=cF0> 0: dc2->color=</span><span class=cF3>WHITE</span><span class=cF0>; </span><span class=cF1>break</span><span class=cF0>;
|
|
<a name="l72"></a> </span><span class=cF1>case</span><span class=cF0> 1: dc2->color=</span><span class=cF3>LTGRAY</span><span class=cF0>; </span><span class=cF1>break</span><span class=cF0>;
|
|
<a name="l73"></a> </span><span class=cF1>case</span><span class=cF0> 2: dc2->color=</span><span class=cF3>DKGRAY</span><span class=cF0>; </span><span class=cF1>break</span><span class=cF0>;
|
|
<a name="l74"></a> </span><span class=cF1>case</span><span class=cF0> 3: dc2->color=</span><span class=cF3>BLACK</span><span class=cF0>; </span><span class=cF1>break</span><span class=cF0>;
|
|
<a name="l75"></a> </span><span class=cF7>}</span><span class=cF0>
|
|
<a name="l76"></a> </span><span class=cF5>GrPlot</span><span class=cF0>(dc2,cx+</span><span class=cF7>(</span><span class=cF0>x+</span><span class=cF5>RandU16</span><span class=cF0>%12-6</span><span class=cF7>)</span><span class=cF0>,cy-</span><span class=cF7>(</span><span class=cF0>y+</span><span class=cF5>RandU16</span><span class=cF0>%12-6</span><span class=cF7>)</span><span class=cF0>);
|
|
<a name="l77"></a> }
|
|
<a name="l78"></a> </span><span class=cF7>}</span><span class=cF0>
|
|
<a name="l79"></a>
|
|
<a name="l80"></a> </span><span class=cF1>if</span><span class=cF0> (plane_hit)
|
|
<a name="l81"></a> </span><span class=cF5>Sprite3</span><span class=cF0>(dc,cx+m3.x,cy-m3.y,0,</span><span class=cFA><2></span><span class=cF0>);
|
|
<a name="l82"></a> </span><span class=cF1>else</span><span class=cF0>
|
|
<a name="l83"></a> </span><span class=cF5>Sprite3</span><span class=cF0>(dc,cx+m3.x,cy-m3.y,0,</span><span class=cFA><1></span><span class=cF0>);
|
|
<a name="l84"></a>
|
|
<a name="l85"></a> </span><span class=cF1>if</span><span class=cF0> (blast_off && !plane_hit) </span><span class=cF7>{</span><span class=cF0>
|
|
<a name="l86"></a> dc->color=</span><span class=cF3>ROP_COLLISION</span><span class=cF0>;
|
|
<a name="l87"></a> dc->bkcolor=</span><span class=cF3>LTCYAN</span><span class=cF0>;
|
|
<a name="l88"></a> dc->collision_cnt=0;
|
|
<a name="l89"></a> </span><span class=cF5>Sprite3ZB</span><span class=cF0>(dc,cx+</span><span class=cF7>(</span><span class=cF0>m1.x+m2.x</span><span class=cF7>)</span><span class=cF0>/2,cy-</span><span class=cF7>(</span><span class=cF0>m1.y+m2.y</span><span class=cF7>)</span><span class=cF0>/2,0,</span><span class=cFA><3></span><span class=cF0>,-theta);
|
|
<a name="l90"></a> </span><span class=cF1>if</span><span class=cF0> (dc->collision_cnt>100) {
|
|
<a name="l91"></a> </span><span class=cF5>Noise</span><span class=cF0>(1000,62,81);
|
|
<a name="l92"></a> plane_hit=</span><span class=cF3>TRUE</span><span class=cF0>;
|
|
<a name="l93"></a> } </span><span class=cF1>else</span><span class=cF0>
|
|
<a name="l94"></a> </span><span class=cF5>Snd</span><span class=cF0>(22);
|
|
<a name="l95"></a> </span><span class=cF7>}</span><span class=cF0> </span><span class=cF1>else</span><span class=cF0> </span><span class=cF1>if</span><span class=cF0> (!plane_hit)
|
|
<a name="l96"></a> </span><span class=cF5>Snd</span><span class=cF0>;
|
|
<a name="l97"></a>
|
|
<a name="l98"></a> dc->color=</span><span class=cF3>ROP_EQU</span><span class=cF0>;
|
|
<a name="l99"></a> </span><span class=cF5>Sprite3</span><span class=cF0>(dc,0,GROUND_Y,0,</span><span class=cFA><4></span><span class=cF0>);
|
|
<a name="l100"></a> </span><span class=cF5>Sprite3ZB</span><span class=cF0>(dc,cx+</span><span class=cF7>(</span><span class=cF0>m1.x+m2.x</span><span class=cF7>)</span><span class=cF0>/2,cy-</span><span class=cF7>(</span><span class=cF0>m1.y+m2.y</span><span class=cF7>)</span><span class=cF0>/2,0,</span><span class=cFA><3></span><span class=cF0>,-theta);
|
|
<a name="l101"></a>
|
|
<a name="l102"></a> dc->color=</span><span class=cF3>RED</span><span class=cF0>;
|
|
<a name="l103"></a> </span><span class=cF5>GrCircle</span><span class=cF0>(dc,cx+target.x,cy-target.y,5);
|
|
<a name="l104"></a>
|
|
<a name="l105"></a> dc->color=</span><span class=cF3>BLUE</span><span class=cF0>;
|
|
<a name="l106"></a> </span><span class=cF5>GrCircle</span><span class=cF0>(dc,cx+m3.x,cy-m3.y,5);
|
|
<a name="l107"></a>
|
|
<a name="l108"></a> dc->color=</span><span class=cF3>BLACK</span><span class=cF0>;
|
|
<a name="l109"></a> </span><span class=cF5>GrPrint</span><span class=cF0>(dc,0,</span><span class=cF3>FONT_HEIGHT</span><span class=cF0>,</span><span class=cF6>"%12.6f"</span><span class=cF0>,my_dbg);
|
|
<a name="l110"></a>}
|
|
<a name="l111"></a>
|
|
<a name="l112"></a></span><span class=cF1>U0</span><span class=cF0> MyDerivative(</span><span class=cF9>CMathODE</span><span class=cF0> *,</span><span class=cF1>F64</span><span class=cF0>,</span><span class=cF1>F64</span><span class=cF0> *state,</span><span class=cF1>F64</span><span class=cF0> *DstateDt)
|
|
<a name="l113"></a>{
|
|
<a name="l114"></a> </span><span class=cF1>F64</span><span class=cF0> d,discriminant,v,a,theta=</span><span class=cF5>Arg</span><span class=cF0>(m2.state->x-m1.state->x,m2.state->y-m1.state->y),
|
|
<a name="l115"></a> DthetaDt,collision_estimate_t,target_heading,target_angle_error,
|
|
<a name="l116"></a> desired_nozzle_angle;
|
|
<a name="l117"></a> </span><span class=cF9>CD3</span><span class=cF0> p,p_target,p_body;
|
|
<a name="l118"></a>
|
|
<a name="l119"></a> </span><span class=cF2>//Unit vect pointing to top of rocket from bottom.</span><span class=cF0>
|
|
<a name="l120"></a> </span><span class=cF5>D3Sub</span><span class=cF0>(&p_body,&m2.state->x,&m1.state->x);
|
|
<a name="l121"></a> </span><span class=cF5>D3Unit</span><span class=cF0>(&p_body);
|
|
<a name="l122"></a>
|
|
<a name="l123"></a> </span><span class=cF2>//DthetaDt lets us prevent too much spin.</span><span class=cF0>
|
|
<a name="l124"></a> DthetaDt=antispin_coefficient*
|
|
<a name="l125"></a> (m2.state->DyDt*p_body.x-m2.state->DxDt*p_body.y-
|
|
<a name="l126"></a> m1.state->DyDt*p_body.x+m1.state->DxDt*p_body.y)/ROCKET_HEIGHT;
|
|
<a name="l127"></a>
|
|
<a name="l128"></a> </span><span class=cF2>//p_target is vect from top of rocket to plane.</span><span class=cF0>
|
|
<a name="l129"></a> </span><span class=cF5>D3Sub</span><span class=cF0>(&p_target,&m3.state->x,&m2.state->x);
|
|
<a name="l130"></a>
|
|
<a name="l131"></a> </span><span class=cF2>//d=0.5at^2+vt</span><span class=cF0>
|
|
<a name="l132"></a> d=</span><span class=cF5>D3Norm</span><span class=cF0>(&p_target);
|
|
<a name="l133"></a>
|
|
<a name="l134"></a> </span><span class=cF5>D3Copy</span><span class=cF0>(&p,&p_target);
|
|
<a name="l135"></a> </span><span class=cF5>D3Unit</span><span class=cF0>(&p);
|
|
<a name="l136"></a> v=(m2.state->DxDt*p.x+m2.state->DyDt*p.y)-
|
|
<a name="l137"></a> (m3.state->DxDt*p.x+m3.state->DyDt*p.y);
|
|
<a name="l138"></a>
|
|
<a name="l139"></a> a=THRUST/(m1.mass+m2.mass);
|
|
<a name="l140"></a>
|
|
<a name="l141"></a> discriminant=v*v+4*0.5*a*d;
|
|
<a name="l142"></a> </span><span class=cF1>if</span><span class=cF0> (discriminant>0)
|
|
<a name="l143"></a> collision_estimate_t=(-v+</span><span class=cF5>Sqrt</span><span class=cF7>(</span><span class=cF0>discriminant</span><span class=cF7>)</span><span class=cF0>)/a;
|
|
<a name="l144"></a> </span><span class=cF1>else</span><span class=cF0>
|
|
<a name="l145"></a> collision_estimate_t=0;
|
|
<a name="l146"></a> my_dbg=collision_estimate_t;
|
|
<a name="l147"></a>
|
|
<a name="l148"></a> </span><span class=cF2>//Aim for projected pos of plane at time of impact.</span><span class=cF0>
|
|
<a name="l149"></a> </span><span class=cF5>D3Copy</span><span class=cF0>(&p,&m3.state->DxDt);
|
|
<a name="l150"></a> </span><span class=cF5>D3MulEqu</span><span class=cF0>(&p,collision_estimate_t);
|
|
<a name="l151"></a> </span><span class=cF5>D3AddEqu</span><span class=cF0>(&p_target,&p);
|
|
<a name="l152"></a>
|
|
<a name="l153"></a> </span><span class=cF5>D3Copy</span><span class=cF0>(&target,&p_target);
|
|
<a name="l154"></a> </span><span class=cF5>D3AddEqu</span><span class=cF0>(&target,&m2.state->x);
|
|
<a name="l155"></a>
|
|
<a name="l156"></a> target_heading=</span><span class=cF5>Arg</span><span class=cF0>(p_target.x,p_target.y);
|
|
<a name="l157"></a> target_angle_error=</span><span class=cF5>Wrap</span><span class=cF0>(theta-target_heading); </span><span class=cF2>//Force to range [-pi,pi)</span><span class=cF0>
|
|
<a name="l158"></a> desired_nozzle_angle=</span><span class=cF5>Clamp</span><span class=cF0>(50.0*DthetaDt+750*target_angle_error,-</span><span class=cF3>pi</span><span class=cF0>/8,</span><span class=cF3>pi</span><span class=cF0>/8);
|
|
<a name="l159"></a>
|
|
<a name="l160"></a> </span><span class=cF2>//For realism we limit the speed the nozzle angle can change.</span><span class=cF0>
|
|
<a name="l161"></a> DstateDt[STATE_NOZZLE_ANGLE]=state[STATE_NOZZLE_ANGLE_VELOCITY];
|
|
<a name="l162"></a> DstateDt[STATE_NOZZLE_ANGLE_VELOCITY]=
|
|
<a name="l163"></a> </span><span class=cF5>Clamp</span><span class=cF0>(10000*</span><span class=cF7>(</span><span class=cF0>desired_nozzle_angle-state[STATE_NOZZLE_ANGLE]</span><span class=cF7>)</span><span class=cF0>,
|
|
<a name="l164"></a> -1000,1000)-10.0*state[STATE_NOZZLE_ANGLE_VELOCITY]; </span><span class=cF2>//Damping</span><span class=cF0>
|
|
<a name="l165"></a>
|
|
<a name="l166"></a> </span><span class=cF1>if</span><span class=cF0> (blast_off) </span><span class=cF7>{</span><span class=cF0>
|
|
<a name="l167"></a> m1.DstateDt->DxDt+=THRUST*</span><span class=cF5>Cos</span><span class=cF0>(theta+state[STATE_NOZZLE_ANGLE]);
|
|
<a name="l168"></a> m1.DstateDt->DyDt+=THRUST*</span><span class=cF5>Sin</span><span class=cF0>(theta+state[STATE_NOZZLE_ANGLE]);
|
|
<a name="l169"></a>
|
|
<a name="l170"></a> m1.DstateDt->DyDt-=25; </span><span class=cF2>//Gravity</span><span class=cF0>
|
|
<a name="l171"></a> m2.DstateDt->DyDt-=25;
|
|
<a name="l172"></a> </span><span class=cF7>}</span><span class=cF0>
|
|
<a name="l173"></a>
|
|
<a name="l174"></a> </span><span class=cF2>//For more realism reduce the mass of the rocket because of fuel.</span><span class=cF0>
|
|
<a name="l175"></a> </span><span class=cF2>//You might also factor-in fuel slosh in the tank.</span><span class=cF0>
|
|
<a name="l176"></a>
|
|
<a name="l177"></a> </span><span class=cF2>//To do this, you would have to set-up state vars for mass and</span><span class=cF0>
|
|
<a name="l178"></a> </span><span class=cF2>//do A=F/m manually instead of relyin on </span><a href="/Wb/Adam/AMathODE.HC.HTML#l380"><span class=cF4>ODECallDerivative</span></a><span class=cF2>() to divide</span><span class=cF0>
|
|
<a name="l179"></a> </span><span class=cF2>//by mass.</span><span class=cF0>
|
|
<a name="l180"></a>}
|
|
<a name="l181"></a>
|
|
<a name="l182"></a></span><span class=cF1>U0</span><span class=cF0> Init()
|
|
<a name="l183"></a>{
|
|
<a name="l184"></a> </span><span class=cF5>DocClear</span><span class=cF0>;
|
|
<a name="l185"></a> </span><span class=cF6>"$BG,LTCYAN$%h*c"</span><span class=cF0>,</span><span class=cF5>ToI64</span><span class=cF0>(GROUND_Y/</span><span class=cF3>FONT_HEIGHT</span><span class=cF0>),</span><span class=cF6>'\n'</span><span class=cF0>;
|
|
<a name="l186"></a>
|
|
<a name="l187"></a> blast_off=</span><span class=cF3>FALSE</span><span class=cF0>;
|
|
<a name="l188"></a> plane_hit=</span><span class=cF3>FALSE</span><span class=cF0>;
|
|
<a name="l189"></a>
|
|
<a name="l190"></a> </span><span class=cF1>do</span><span class=cF0> antispin_coefficient=</span><span class=cF5>PopUpRangeF64Exp</span><span class=cF0>(0.1,10.001,</span><span class=cF5>Sqrt</span><span class=cF7>(</span><span class=cF0>10</span><span class=cF7>)</span><span class=cF0>,
|
|
<a name="l191"></a> </span><span class=cF6>"%9.4f"</span><span class=cF0>,</span><span class=cF6>"Anti-spin Coefficient\n\n"</span><span class=cF0>);
|
|
<a name="l192"></a> </span><span class=cF1>while</span><span class=cF0> (!</span><span class=cF7>(</span><span class=cF0>0.1<=antispin_coefficient<10.001</span><span class=cF7>)</span><span class=cF0>);
|
|
<a name="l193"></a>
|
|
<a name="l194"></a> </span><span class=cF2>//We don't clear que links.</span><span class=cF0>
|
|
<a name="l195"></a> </span><span class=cF5>MemSet</span><span class=cF0>(&m1.</span><span class=cF1>start</span><span class=cF0>,0,</span><span class=cF1>offset</span><span class=cF7>(</span><span class=cF9>CMass</span><span class=cF0>.</span><span class=cF1>end</span><span class=cF7>)</span><span class=cF0>-</span><span class=cF1>offset</span><span class=cF7>(</span><span class=cF9>CMass</span><span class=cF0>.</span><span class=cF1>start</span><span class=cF7>)</span><span class=cF0>);
|
|
<a name="l196"></a> m1.y=0;
|
|
<a name="l197"></a> m1.mass=1.0;
|
|
<a name="l198"></a>
|
|
<a name="l199"></a> </span><span class=cF5>MemSet</span><span class=cF0>(&m2.</span><span class=cF1>start</span><span class=cF0>,0,</span><span class=cF1>offset</span><span class=cF7>(</span><span class=cF9>CMass</span><span class=cF0>.</span><span class=cF1>end</span><span class=cF7>)</span><span class=cF0>-</span><span class=cF1>offset</span><span class=cF7>(</span><span class=cF9>CMass</span><span class=cF0>.</span><span class=cF1>start</span><span class=cF7>)</span><span class=cF0>);
|
|
<a name="l200"></a> m2.y=ROCKET_HEIGHT;
|
|
<a name="l201"></a> m2.mass=1.0;
|
|
<a name="l202"></a>
|
|
<a name="l203"></a> </span><span class=cF5>MemSet</span><span class=cF0>(&m3.</span><span class=cF1>start</span><span class=cF0>,0,</span><span class=cF1>offset</span><span class=cF7>(</span><span class=cF9>CMass</span><span class=cF0>.</span><span class=cF1>end</span><span class=cF7>)</span><span class=cF0>-</span><span class=cF1>offset</span><span class=cF7>(</span><span class=cF9>CMass</span><span class=cF0>.</span><span class=cF1>start</span><span class=cF7>)</span><span class=cF0>);
|
|
<a name="l204"></a> m3.y=400;
|
|
<a name="l205"></a> m3.x=-300;
|
|
<a name="l206"></a> m3.DxDt=50;
|
|
<a name="l207"></a> m3.mass=1.0;
|
|
<a name="l208"></a>
|
|
<a name="l209"></a> </span><span class=cF5>MemSet</span><span class=cF0>(&s.</span><span class=cF1>start</span><span class=cF0>,0,</span><span class=cF1>offset</span><span class=cF7>(</span><span class=cF9>CSpring</span><span class=cF0>.</span><span class=cF1>end</span><span class=cF7>)</span><span class=cF0>-</span><span class=cF1>offset</span><span class=cF7>(</span><span class=cF9>CSpring</span><span class=cF0>.</span><span class=cF1>start</span><span class=cF7>)</span><span class=cF0>);
|
|
<a name="l210"></a> s.end1=&m1;
|
|
<a name="l211"></a> s.end2=&m2;
|
|
<a name="l212"></a> s.rest_len=ROCKET_HEIGHT;
|
|
<a name="l213"></a> s.const=10000;
|
|
<a name="l214"></a>
|
|
<a name="l215"></a> ode->state[STATE_NOZZLE_ANGLE]=0;
|
|
<a name="l216"></a> ode->state[STATE_NOZZLE_ANGLE_VELOCITY]=0;
|
|
<a name="l217"></a>
|
|
<a name="l218"></a> </span><span class=cF5>DCFill</span><span class=cF0>;
|
|
<a name="l219"></a>}
|
|
<a name="l220"></a>
|
|
<a name="l221"></a></span><span class=cF1>U0</span><span class=cF0> TaskEndCB()
|
|
<a name="l222"></a>{
|
|
<a name="l223"></a> </span><span class=cF5>DCFill</span><span class=cF0>;
|
|
<a name="l224"></a> </span><span class=cF5>SndTaskEndCB</span><span class=cF0>;
|
|
<a name="l225"></a>}
|
|
<a name="l226"></a>
|
|
<a name="l227"></a></span><span class=cF1>U0</span><span class=cF0> RocketScience()
|
|
<a name="l228"></a>{
|
|
<a name="l229"></a> </span><span class=cF5>SettingsPush</span><span class=cF0>; </span><span class=cF2>//See </span><a href="/Wb/Adam/TaskSettings.HC.HTML#l3"><span class=cF4>SettingsPush</span></a><span class=cF0>
|
|
<a name="l230"></a> </span><span class=cF5>Fs</span><span class=cF0>->text_attr=</span><span class=cF3>YELLOW</span><span class=cF0><<4+</span><span class=cF3>BLUE</span><span class=cF0>;
|
|
<a name="l231"></a> </span><span class=cF5>MenuPush</span><span class=cF0>(
|
|
<a name="l232"></a> </span><span class=cF6>"File {"</span><span class=cF0>
|
|
<a name="l233"></a> </span><span class=cF6>" Abort(,CH_SHIFT_ESC);"</span><span class=cF0>
|
|
<a name="l234"></a> </span><span class=cF6>" Exit(,CH_ESC);"</span><span class=cF0>
|
|
<a name="l235"></a> </span><span class=cF6>"}"</span><span class=cF0>
|
|
<a name="l236"></a> </span><span class=cF6>"Play {"</span><span class=cF0>
|
|
<a name="l237"></a> </span><span class=cF6>" Restart(,'\n');"</span><span class=cF0>
|
|
<a name="l238"></a> </span><span class=cF6>" Launch(,CH_SPACE);"</span><span class=cF0>
|
|
<a name="l239"></a> </span><span class=cF6>"}"</span><span class=cF0>
|
|
<a name="l240"></a> );
|
|
<a name="l241"></a>
|
|
<a name="l242"></a> </span><span class=cF5>AutoComplete</span><span class=cF0>;
|
|
<a name="l243"></a> </span><span class=cF5>WinBorder</span><span class=cF0>;
|
|
<a name="l244"></a> </span><span class=cF5>WinMax</span><span class=cF0>;
|
|
<a name="l245"></a> </span><span class=cF5>DocCursor</span><span class=cF0>;
|
|
<a name="l246"></a> </span><span class=cF5>DocClear</span><span class=cF0>;
|
|
<a name="l247"></a> dc2=</span><span class=cF5>DCAlias</span><span class=cF0>;
|
|
<a name="l248"></a> </span><span class=cF5>Fs</span><span class=cF0>->task_end_cb=&TaskEndCB;
|
|
<a name="l249"></a>
|
|
<a name="l250"></a> ode=</span><span class=cF5>ODENew</span><span class=cF0>(STATE_NUM,1e-6,</span><span class=cF3>ODEF_HAS_MASSES</span><span class=cF0>);
|
|
<a name="l251"></a> ode->derive=&MyDerivative;
|
|
<a name="l252"></a> ode->drag_v2=0.002;
|
|
<a name="l253"></a> ode->drag_v3=0.00001;
|
|
<a name="l254"></a> ode->acceleration_limit=5e3;
|
|
<a name="l255"></a>
|
|
<a name="l256"></a> </span><span class=cF2>// ode->t_scale=0.1; //Uncomment this to go in slow motion.</span><span class=cF0>
|
|
<a name="l257"></a>
|
|
<a name="l258"></a> Init;
|
|
<a name="l259"></a> </span><span class=cF5>QueIns</span><span class=cF0>(&m1,ode->last_mass);
|
|
<a name="l260"></a> </span><span class=cF5>QueIns</span><span class=cF0>(&m2,ode->last_mass);
|
|
<a name="l261"></a> </span><span class=cF5>QueIns</span><span class=cF0>(&m3,ode->last_mass);
|
|
<a name="l262"></a> </span><span class=cF5>QueIns</span><span class=cF0>(&s,ode->last_spring);
|
|
<a name="l263"></a>
|
|
<a name="l264"></a> </span><span class=cF5>QueIns</span><span class=cF0>(ode,</span><span class=cF5>Fs</span><span class=cF0>->last_ode);
|
|
<a name="l265"></a>
|
|
<a name="l266"></a> </span><span class=cF5>Fs</span><span class=cF0>->draw_it=&</span><span class=cF5>DrawIt</span><span class=cF0>;
|
|
<a name="l267"></a>
|
|
<a name="l268"></a> </span><span class=cF1>try</span><span class=cF0> </span><span class=cF7>{</span><span class=cF0>
|
|
<a name="l269"></a> </span><span class=cF5>GetKey</span><span class=cF0>;
|
|
<a name="l270"></a> blast_off=</span><span class=cF3>TRUE</span><span class=cF0>;
|
|
<a name="l271"></a> </span><span class=cF1>while</span><span class=cF0> (</span><span class=cF3>TRUE</span><span class=cF0>) {
|
|
<a name="l272"></a> </span><span class=cF1>switch</span><span class=cF0> (</span><span class=cF5>GetChar</span><span class=cF7>(</span><span class=cF0>,</span><span class=cF3>FALSE</span><span class=cF7>)</span><span class=cF0>) </span><span class=cF7>{</span><span class=cF0>
|
|
<a name="l273"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF6>'\n'</span><span class=cF0>:
|
|
<a name="l274"></a> Init;
|
|
<a name="l275"></a> </span><span class=cF5>GetKey</span><span class=cF0>;
|
|
<a name="l276"></a> blast_off=</span><span class=cF3>TRUE</span><span class=cF0>;
|
|
<a name="l277"></a> </span><span class=cF1>break</span><span class=cF0>;
|
|
<a name="l278"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF3>CH_SHIFT_ESC</span><span class=cF0>:
|
|
<a name="l279"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF3>CH_ESC</span><span class=cF0>:
|
|
<a name="l280"></a> </span><span class=cF1>goto</span><span class=cF0> rs_done;
|
|
<a name="l281"></a> </span><span class=cF7>}</span><span class=cF0>
|
|
<a name="l282"></a> }
|
|
<a name="l283"></a>rs_done:
|
|
<a name="l284"></a> </span><span class=cF7>}</span><span class=cF0> </span><span class=cF1>catch</span><span class=cF0>
|
|
<a name="l285"></a> </span><span class=cF5>PutExcept</span><span class=cF0>;
|
|
<a name="l286"></a> </span><span class=cF5>QueRem</span><span class=cF0>(ode);
|
|
<a name="l287"></a> </span><span class=cF5>ODEDel</span><span class=cF0>(ode);
|
|
<a name="l288"></a> </span><span class=cF5>DocClear</span><span class=cF0>;
|
|
<a name="l289"></a> </span><span class=cF5>SettingsPop</span><span class=cF0>;
|
|
<a name="l290"></a> </span><span class=cF5>DCFill</span><span class=cF0>;
|
|
<a name="l291"></a> </span><span class=cF5>DCDel</span><span class=cF0>(dc2);
|
|
<a name="l292"></a> </span><span class=cF5>MenuPop</span><span class=cF0>;
|
|
<a name="l293"></a>}
|
|
<a name="l294"></a>
|
|
<a name="l295"></a>RocketScience;
|
|
</span></pre></body>
|
|
</html>
|