templeos-info/public/Wb/Apps/GrModels/BallGen.HC.HTML

160 lines
13 KiB
Plaintext
Raw Normal View History

2024-03-24 21:24:44 +00:00
<!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">
.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=cF2>//Makes a mesh ball.</span><span class=cF0>
<a name="l2"></a>
<a name="l3"></a>#</span><span class=cF1>define</span><span class=cF0> VERTICES_NUM 1024
<a name="l4"></a>#</span><span class=cF1>define</span><span class=cF0> TRIS_NUM 1024
<a name="l5"></a>
<a name="l6"></a></span><span class=cF1>class</span><span class=cF0> Ball
<a name="l7"></a>{
<a name="l8"></a> </span><span class=cF9>I32</span><span class=cF0> vertex_cnt;
<a name="l9"></a> </span><span class=cF9>I32</span><span class=cF0> tri_cnt;
<a name="l10"></a> </span><span class=cF9>CD3I32</span><span class=cF0> v[VERTICES_NUM];
<a name="l11"></a> </span><span class=cF9>CMeshTri</span><span class=cF0> t[TRIS_NUM];
<a name="l12"></a>} *b;
<a name="l13"></a>
<a name="l14"></a></span><span class=cF1>class</span><span class=cF0> BallDefineStruct
<a name="l15"></a>{
<a name="l16"></a> </span><span class=cF1>F64</span><span class=cF0> radius format </span><span class=cF6>&quot;$DA-TRM,A=\&quot;Radius :%8.3f\&quot;$\n&quot;</span><span class=cF0>;
<a name="l17"></a> </span><span class=cF9>I64</span><span class=cF0> n_longitude format </span><span class=cF6>&quot;$DA-TRM,A=\&quot;Longitude Faces:%5d\&quot;$\n&quot;</span><span class=cF0>;
<a name="l18"></a> </span><span class=cF9>I64</span><span class=cF0> n_lattitude format </span><span class=cF6>&quot;$DA-TRM,A=\&quot;Lattitude Rings:%5d\&quot;$\n&quot;</span><span class=cF0>;
<a name="l19"></a>};
<a name="l20"></a>
<a name="l21"></a></span><span class=cF1>U0</span><span class=cF0> BDInit(BallDefineStruct *bd)
<a name="l22"></a>{
<a name="l23"></a> </span><span class=cF5>MemSet</span><span class=cF0>(bd,0,</span><span class=cF1>sizeof</span><span class=cF7>(</span><span class=cF0>BallDefineStruct</span><span class=cF7>)</span><span class=cF0>);
<a name="l24"></a> bd-&gt;n_longitude=16;
<a name="l25"></a> bd-&gt;n_lattitude=8;
<a name="l26"></a> bd-&gt;radius =20.0;
<a name="l27"></a>}
<a name="l28"></a>
<a name="l29"></a></span><span class=cF1>U0</span><span class=cF0> BDCorrect(BallDefineStruct *bd)
<a name="l30"></a>{
<a name="l31"></a> bd-&gt;n_longitude=(bd-&gt;n_longitude+1)/2;
<a name="l32"></a> bd-&gt;n_lattitude=(bd-&gt;n_lattitude+1)/2;
<a name="l33"></a>}
<a name="l34"></a>
<a name="l35"></a></span><span class=cF9>I64</span><span class=cF0> AddVertex(BallDefineStruct *,</span><span class=cF9>I64</span><span class=cF0> x,</span><span class=cF9>I64</span><span class=cF0> y,</span><span class=cF9>I64</span><span class=cF0> z)
<a name="l36"></a>{
<a name="l37"></a> </span><span class=cF9>I64</span><span class=cF0> i;
<a name="l38"></a> </span><span class=cF1>for</span><span class=cF0> (i=0;i&lt;b-&gt;vertex_cnt;i++)
<a name="l39"></a> </span><span class=cF1>if</span><span class=cF0> (b-&gt;v[i].x==x &amp;&amp; b-&gt;v[i].y==y &amp;&amp; b-&gt;v[i].z==z)
<a name="l40"></a> </span><span class=cF1>return</span><span class=cF0> i;
<a name="l41"></a> i=b-&gt;vertex_cnt++;
<a name="l42"></a> b-&gt;v[i].x=x;
<a name="l43"></a> b-&gt;v[i].y=y;
<a name="l44"></a> b-&gt;v[i].z=z;
<a name="l45"></a> </span><span class=cF1>return</span><span class=cF0> i;
<a name="l46"></a>}
<a name="l47"></a>
<a name="l48"></a></span><span class=cF9>I64</span><span class=cF0> AddTri(BallDefineStruct *,</span><span class=cF9>I64</span><span class=cF0> c,</span><span class=cF9>I64</span><span class=cF0> n0,</span><span class=cF9>I64</span><span class=cF0> n1,</span><span class=cF9>I64</span><span class=cF0> n2)
<a name="l49"></a>{
<a name="l50"></a> </span><span class=cF9>I64</span><span class=cF0> res=b-&gt;tri_cnt++;
<a name="l51"></a> b-&gt;t[res].color=c;
<a name="l52"></a> b-&gt;t[res].nums[0]=n0;
<a name="l53"></a> b-&gt;t[res].nums[1]=n1;
<a name="l54"></a> b-&gt;t[res].nums[2]=n2;
<a name="l55"></a> </span><span class=cF1>return</span><span class=cF0> res;
<a name="l56"></a>}
<a name="l57"></a>
<a name="l58"></a></span><span class=cF1>U8</span><span class=cF0> *Ball2CSprite()
<a name="l59"></a>{
<a name="l60"></a></span><span class=cF2>//See </span><a href="/Wb/Adam/Gr/GrSpritePlot.HC.HTML#l1"><span class=cF4>::/Adam/Gr/GrSpritePlot.HC</span></a><span class=cF2> for how CSprite are stored.</span><span class=cF0>
<a name="l61"></a> </span><span class=cF1>U8</span><span class=cF0> *res=</span><span class=cF5>MAlloc</span><span class=cF0>(</span><span class=cF1>sizeof</span><span class=cF7>(</span><span class=cF9>CSpriteMeshU8s</span><span class=cF7>)</span><span class=cF0>+
<a name="l62"></a> b-&gt;vertex_cnt*</span><span class=cF1>sizeof</span><span class=cF7>(</span><span class=cF9>CD3I32</span><span class=cF7>)</span><span class=cF0>+b-&gt;tri_cnt*</span><span class=cF1>sizeof</span><span class=cF7>(</span><span class=cF9>CMeshTri</span><span class=cF7>)</span><span class=cF0>
<a name="l63"></a> +</span><span class=cFB>sprite_elem_base_sizes</span><span class=cF0>[</span><span class=cF3>SPT_END</span><span class=cF0>]),
<a name="l64"></a> *dst=res;
<a name="l65"></a> *dst++ =</span><span class=cF3>SPT_MESH</span><span class=cF0>;
<a name="l66"></a> *dst(</span><span class=cF9>I32</span><span class=cF0> *)++ =b-&gt;vertex_cnt;
<a name="l67"></a> *dst(</span><span class=cF9>I32</span><span class=cF0> *)++ =b-&gt;tri_cnt;
<a name="l68"></a> </span><span class=cF5>MemCpy</span><span class=cF0>(dst,&amp;b-&gt;v,b-&gt;vertex_cnt*</span><span class=cF1>sizeof</span><span class=cF7>(</span><span class=cF9>CD3I32</span><span class=cF7>)</span><span class=cF0>);
<a name="l69"></a> dst+=b-&gt;vertex_cnt*</span><span class=cF1>sizeof</span><span class=cF0>(</span><span class=cF9>CD3I32</span><span class=cF0>);
<a name="l70"></a> </span><span class=cF5>MemCpy</span><span class=cF0>(dst,&amp;b-&gt;t,b-&gt;tri_cnt*</span><span class=cF1>sizeof</span><span class=cF7>(</span><span class=cF9>CMeshTri</span><span class=cF7>)</span><span class=cF0>);
<a name="l71"></a> dst+=b-&gt;tri_cnt*</span><span class=cF1>sizeof</span><span class=cF0>(</span><span class=cF9>CMeshTri</span><span class=cF0>);
<a name="l72"></a> *dst++ =</span><span class=cF3>SPT_END</span><span class=cF0>;
<a name="l73"></a> </span><span class=cF1>return</span><span class=cF0> res;
<a name="l74"></a>}
<a name="l75"></a>
<a name="l76"></a></span><span class=cF1>public</span><span class=cF0> </span><span class=cF1>U8</span><span class=cF0> *BallGen()
<a name="l77"></a>{
<a name="l78"></a> </span><span class=cF1>U8</span><span class=cF0> *res;
<a name="l79"></a> </span><span class=cF9>I64</span><span class=cF0> i,j,n,m,c,p1,p2,p3,p4;
<a name="l80"></a> BallDefineStruct bd1,bd2;
<a name="l81"></a> </span><span class=cF1>F64</span><span class=cF0> r,r1,r2,z1,z2,d_a1,d_a2;
<a name="l82"></a>
<a name="l83"></a> BDInit(&amp;bd1);
<a name="l84"></a>
<a name="l85"></a> </span><span class=cF1>while</span><span class=cF0> (</span><span class=cF3>TRUE</span><span class=cF0>) </span><span class=cF7>{</span><span class=cF0>
<a name="l86"></a> </span><span class=cF1>if</span><span class=cF0> (!</span><span class=cF5>DocForm</span><span class=cF7>(</span><span class=cF0>&amp;bd1</span><span class=cF7>)</span><span class=cF0>)
<a name="l87"></a> </span><span class=cF1>return</span><span class=cF0> </span><span class=cF3>NULL</span><span class=cF0>;
<a name="l88"></a> </span><span class=cF5>MemCpy</span><span class=cF0>(&amp;bd2,&amp;bd1,</span><span class=cF1>sizeof</span><span class=cF7>(</span><span class=cF0>BallDefineStruct</span><span class=cF7>)</span><span class=cF0>);
<a name="l89"></a> BDCorrect(&amp;bd2);
<a name="l90"></a>
<a name="l91"></a> c=</span><span class=cF5>PopUpColorLighting</span><span class=cF0>;
<a name="l92"></a> </span><span class=cF1>if</span><span class=cF0> (c&lt;0) </span><span class=cF1>return</span><span class=cF0> </span><span class=cF3>NULL</span><span class=cF0>;
<a name="l93"></a>
<a name="l94"></a> b=</span><span class=cF5>CAlloc</span><span class=cF0>(</span><span class=cF1>sizeof</span><span class=cF7>(</span><span class=cF0>Ball</span><span class=cF7>)</span><span class=cF0>);
<a name="l95"></a> r=bd2.radius;
<a name="l96"></a> n=bd2.n_lattitude;
<a name="l97"></a> m=bd2.n_longitude;
<a name="l98"></a> d_a1=2*</span><span class=cF3>pi</span><span class=cF0>/n/4;
<a name="l99"></a> d_a2=2*</span><span class=cF3>pi</span><span class=cF0>/m/2;
<a name="l100"></a> </span><span class=cF1>for</span><span class=cF0> (j=-n;j&lt;n;j++) {
<a name="l101"></a> r1=r*</span><span class=cF5>Cos</span><span class=cF0>( j *d_a1);
<a name="l102"></a> r2=r*</span><span class=cF5>Cos</span><span class=cF0>(</span><span class=cF7>(</span><span class=cF0>j+1</span><span class=cF7>)</span><span class=cF0>*d_a1);
<a name="l103"></a> z1=r*</span><span class=cF5>Sin</span><span class=cF0>( j *d_a1);
<a name="l104"></a> z2=r*</span><span class=cF5>Sin</span><span class=cF0>(</span><span class=cF7>(</span><span class=cF0>j+1</span><span class=cF7>)</span><span class=cF0>*d_a1);
<a name="l105"></a> </span><span class=cF1>for</span><span class=cF0> (i=0;i&lt;m;i++) </span><span class=cF7>{</span><span class=cF0>
<a name="l106"></a> p1=AddVertex(&amp;bd2,r1*</span><span class=cF5>Cos</span><span class=cF7>(</span><span class=cF0>(2*i +j)*d_a2</span><span class=cF7>)</span><span class=cF0>,r1*</span><span class=cF5>Sin</span><span class=cF7>(</span><span class=cF0>(2*i +j)*d_a2</span><span class=cF7>)</span><span class=cF0>,z1);
<a name="l107"></a> p2=AddVertex(&amp;bd2,r1*</span><span class=cF5>Cos</span><span class=cF7>(</span><span class=cF0>(2*i+2+j)*d_a2</span><span class=cF7>)</span><span class=cF0>,r1*</span><span class=cF5>Sin</span><span class=cF7>(</span><span class=cF0>(2*i+2+j)*d_a2</span><span class=cF7>)</span><span class=cF0>,z1);
<a name="l108"></a> p3=AddVertex(&amp;bd2,r2*</span><span class=cF5>Cos</span><span class=cF7>(</span><span class=cF0>(2*i+1+j)*d_a2</span><span class=cF7>)</span><span class=cF0>,r2*</span><span class=cF5>Sin</span><span class=cF7>(</span><span class=cF0>(2*i+1+j)*d_a2</span><span class=cF7>)</span><span class=cF0>,z2);
<a name="l109"></a> p4=AddVertex(&amp;bd2,r2*</span><span class=cF5>Cos</span><span class=cF7>(</span><span class=cF0>(2*i+3+j)*d_a2</span><span class=cF7>)</span><span class=cF0>,r2*</span><span class=cF5>Sin</span><span class=cF7>(</span><span class=cF0>(2*i+3+j)*d_a2</span><span class=cF7>)</span><span class=cF0>,z2);
<a name="l110"></a> AddTri(&amp;bd2,c,p1,p2,p3);
<a name="l111"></a> AddTri(&amp;bd2,c,p3,p2,p4);
<a name="l112"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l113"></a> }
<a name="l114"></a>
<a name="l115"></a> res=Ball2CSprite;
<a name="l116"></a> </span><span class=cF6>&quot;%h7c&quot;</span><span class=cF0>,</span><span class=cF6>'\n'</span><span class=cF0>;
<a name="l117"></a> </span><span class=cF5>Sprite</span><span class=cF0>(res,</span><span class=cF6>&quot;\t\t$SP,\&quot;&lt;1&gt;\&quot;,BI=%d$&quot;</span><span class=cF0>);
<a name="l118"></a> </span><span class=cF6>&quot;%h7c&quot;</span><span class=cF0>,</span><span class=cF6>'\n'</span><span class=cF0>;
<a name="l119"></a> </span><span class=cF6>&quot;Vertices:%d\n&quot;</span><span class=cF0>,b-&gt;vertex_cnt;
<a name="l120"></a> </span><span class=cF5>Free</span><span class=cF0>(b);
<a name="l121"></a> </span><span class=cF6>&quot;Do another&quot;</span><span class=cF0>;
<a name="l122"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cF5>YorN</span><span class=cF0>)
<a name="l123"></a> </span><span class=cF5>Free</span><span class=cF0>(res);
<a name="l124"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l125"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l126"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l127"></a> </span><span class=cF1>return</span><span class=cF0> res;
<a name="l128"></a>}
</span></pre></body>
</html>