ZealOS/docs/Apps/GrModels/BallGen.ZC.html
2021-12-11 06:10:58 -05:00

168 lines
15 KiB
HTML
Executable file

<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=US-ASCII">
<meta name="generator" content="ZealOS V1.07">
<style type="text/css">
body {background-color:#1f1f1f;}
.cF0{color:#e3e3e3;background-color:#1f1f1f;}
.cF1{color:#4f84a6;background-color:#1f1f1f;}
.cF2{color:#73a255;background-color:#1f1f1f;}
.cF3{color:#297582;background-color:#1f1f1f;}
.cF4{color:#b34f4b;background-color:#1f1f1f;}
.cF5{color:#8a52c3;background-color:#1f1f1f;}
.cF6{color:#b7822f;background-color:#1f1f1f;}
.cF7{color:#444444;background-color:#1f1f1f;}
.cF8{color:#6d6d6d;background-color:#1f1f1f;}
.cF9{color:#94bfde;background-color:#1f1f1f;}
.cFA{color:#a1ce97;background-color:#1f1f1f;}
.cFB{color:#6db4be;background-color:#1f1f1f;}
.cFC{color:#e88e88;background-color:#1f1f1f;}
.cFD{color:#ca94e8;background-color:#1f1f1f;}
.cFE{color:#d4b475;background-color:#1f1f1f;}
.cFF{color:#1f1f1f;background-color:#1f1f1f;}
</style>
</head>
<body>
<pre style="font-family:monospace;font-size:12pt">
<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 </span><span class=cFE>1024</span><span class=cF0>
<a name="l4"></a>#</span><span class=cF1>define</span><span class=cF0> TRIS_NUM </span><span class=cFE>1024</span><span class=cF0>
<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_count;
<a name="l9"></a> </span><span class=cF9>I32</span><span class=cF0> tri_count;
<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>
<a name="l13"></a>} *b;
<a name="l14"></a>
<a name="l15"></a></span><span class=cF1>class</span><span class=cF0> BallDefineStruct
<a name="l16"></a>{
<a name="l17"></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="l18"></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="l19"></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="l20"></a>};
<a name="l21"></a>
<a name="l22"></a></span><span class=cF1>U0</span><span class=cF0> BDInit(BallDefineStruct *bd)
<a name="l23"></a>{
<a name="l24"></a> </span><span class=cF5>MemSet</span><span class=cF0>(bd, </span><span class=cFE>0</span><span class=cF0>, </span><span class=cF1>sizeof</span><span class=cF7>(</span><span class=cF0>BallDefineStruct</span><span class=cF7>)</span><span class=cF0>);
<a name="l25"></a> bd-&gt;n_longitude = </span><span class=cFE>16</span><span class=cF0>;
<a name="l26"></a> bd-&gt;n_lattitude = </span><span class=cFE>8</span><span class=cF0>;
<a name="l27"></a> bd-&gt;radius = </span><span class=cFE>20</span><span class=cF0>.</span><span class=cFE>0</span><span class=cF0>;
<a name="l28"></a>}
<a name="l29"></a>
<a name="l30"></a></span><span class=cF1>U0</span><span class=cF0> BDCorrect(BallDefineStruct *bd)
<a name="l31"></a>{
<a name="l32"></a> bd-&gt;n_longitude = (bd-&gt;n_longitude + </span><span class=cFE>1</span><span class=cF0>) / </span><span class=cFE>2</span><span class=cF0>;
<a name="l33"></a> bd-&gt;n_lattitude = (bd-&gt;n_lattitude + </span><span class=cFE>1</span><span class=cF0>) / </span><span class=cFE>2</span><span class=cF0>;
<a name="l34"></a>}
<a name="l35"></a>
<a name="l36"></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="l37"></a>{
<a name="l38"></a> </span><span class=cF9>I64</span><span class=cF0> i;
<a name="l39"></a>
<a name="l40"></a> </span><span class=cF1>for</span><span class=cF0> (i = </span><span class=cFE>0</span><span class=cF0>; i &lt; b-&gt;vertex_count; i++)
<a name="l41"></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="l42"></a> </span><span class=cF1>return</span><span class=cF0> i;
<a name="l43"></a> i = b-&gt;vertex_count++;
<a name="l44"></a> b-&gt;v[i].x = x;
<a name="l45"></a> b-&gt;v[i].y = y;
<a name="l46"></a> b-&gt;v[i].z = z;
<a name="l47"></a>
<a name="l48"></a> </span><span class=cF1>return</span><span class=cF0> i;
<a name="l49"></a>}
<a name="l50"></a>
<a name="l51"></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="l52"></a>{
<a name="l53"></a> </span><span class=cF9>I64</span><span class=cF0> res = b-&gt;tri_count++;
<a name="l54"></a>
<a name="l55"></a> b-&gt;t[res].color = c;
<a name="l56"></a> b-&gt;t[res].nums[</span><span class=cFE>0</span><span class=cF0>] = n0;
<a name="l57"></a> b-&gt;t[res].nums[</span><span class=cFE>1</span><span class=cF0>] = n1;
<a name="l58"></a> b-&gt;t[res].nums[</span><span class=cFE>2</span><span class=cF0>] = n2;
<a name="l59"></a>
<a name="l60"></a> </span><span class=cF1>return</span><span class=cF0> res;
<a name="l61"></a>}
<a name="l62"></a>
<a name="l63"></a></span><span class=cF1>U8</span><span class=cF0> *Ball2CSprite()
<a name="l64"></a>{
<a name="l65"></a></span><span class=cF2>//See </span><a href="https://zeal-operating-system.github.io/ZealOS/System/Gr/GrSpritePlot.ZC.html#l1"><span class=cF4>::/System/Gr/GrSpritePlot.ZC</span></a><span class=cF2> for how CSprite are stored.</span><span class=cF0>
<a name="l66"></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="l67"></a> b-&gt;vertex_count * </span><span class=cF1>sizeof</span><span class=cF7>(</span><span class=cF9>CD3I32</span><span class=cF7>)</span><span class=cF0> +
<a name="l68"></a> b-&gt;tri_count * </span><span class=cF1>sizeof</span><span class=cF7>(</span><span class=cF9>CMeshTri</span><span class=cF7>)</span><span class=cF0> + </span><span class=cFB>sprite_elem_base_sizes</span><span class=cF0>[</span><span class=cF3>SPT_END</span><span class=cF0>]),
<a name="l69"></a> *dst = res;
<a name="l70"></a> *dst++ = </span><span class=cF3>SPT_MESH</span><span class=cF0>;
<a name="l71"></a> *dst(</span><span class=cF9>I32</span><span class=cF0> *)++ = b-&gt;vertex_count;
<a name="l72"></a> *dst(</span><span class=cF9>I32</span><span class=cF0> *)++ = b-&gt;tri_count;
<a name="l73"></a> </span><span class=cF5>MemCopy</span><span class=cF0>(dst, &amp;b-&gt;v, b-&gt;vertex_count * </span><span class=cF1>sizeof</span><span class=cF7>(</span><span class=cF9>CD3I32</span><span class=cF7>)</span><span class=cF0>);
<a name="l74"></a> dst += b-&gt;vertex_count * </span><span class=cF1>sizeof</span><span class=cF0>(</span><span class=cF9>CD3I32</span><span class=cF0>);
<a name="l75"></a> </span><span class=cF5>MemCopy</span><span class=cF0>(dst, &amp;b-&gt;t, b-&gt;tri_count * </span><span class=cF1>sizeof</span><span class=cF7>(</span><span class=cF9>CMeshTri</span><span class=cF7>)</span><span class=cF0>);
<a name="l76"></a> dst += b-&gt;tri_count * </span><span class=cF1>sizeof</span><span class=cF0>(</span><span class=cF9>CMeshTri</span><span class=cF0>);
<a name="l77"></a> *dst++ = </span><span class=cF3>SPT_END</span><span class=cF0>;
<a name="l78"></a>
<a name="l79"></a> </span><span class=cF1>return</span><span class=cF0> res;
<a name="l80"></a>}
<a name="l81"></a>
<a name="l82"></a></span><span class=cF1>public</span><span class=cF0> </span><span class=cF1>U8</span><span class=cF0> *BallGen()
<a name="l83"></a>{
<a name="l84"></a> </span><span class=cF1>U8</span><span class=cF0> *res;
<a name="l85"></a> </span><span class=cF9>I64</span><span class=cF0> i, j, n, m, c, p1, p2, p3, p4;
<a name="l86"></a> BallDefineStruct bd1, bd2;
<a name="l87"></a> </span><span class=cF1>F64</span><span class=cF0> r, r1, r2, z1, z2, d_a1, d_a2;
<a name="l88"></a>
<a name="l89"></a> BDInit(&amp;bd1);
<a name="l90"></a>
<a name="l91"></a> </span><span class=cF1>while</span><span class=cF0> (</span><span class=cF3>TRUE</span><span class=cF0>)
<a name="l92"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l93"></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="l94"></a> </span><span class=cF1>return</span><span class=cF0> </span><span class=cF3>NULL</span><span class=cF0>;
<a name="l95"></a> </span><span class=cF5>MemCopy</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="l96"></a> BDCorrect(&amp;bd2);
<a name="l97"></a>
<a name="l98"></a> c = </span><span class=cF5>PopUpColorLighting</span><span class=cF0>;
<a name="l99"></a> </span><span class=cF1>if</span><span class=cF0> (c &lt; </span><span class=cFE>0</span><span class=cF0>)
<a name="l100"></a> </span><span class=cF1>return</span><span class=cF0> </span><span class=cF3>NULL</span><span class=cF0>;
<a name="l101"></a>
<a name="l102"></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="l103"></a> r = bd2.radius;
<a name="l104"></a> n = bd2.n_lattitude;
<a name="l105"></a> m = bd2.n_longitude;
<a name="l106"></a> d_a1 = </span><span class=cFE>2</span><span class=cF0> * </span><span class=cF3>pi</span><span class=cF0> / n / </span><span class=cFE>4</span><span class=cF0>;
<a name="l107"></a> d_a2 = </span><span class=cFE>2</span><span class=cF0> * </span><span class=cF3>pi</span><span class=cF0> / m / </span><span class=cFE>2</span><span class=cF0>;
<a name="l108"></a> </span><span class=cF1>for</span><span class=cF0> (j = -n; j &lt; n; j++)
<a name="l109"></a> {
<a name="l110"></a> r1 = r * </span><span class=cF5>Cos</span><span class=cF0>( j *d_a1);
<a name="l111"></a> r2 = r * </span><span class=cF5>Cos</span><span class=cF0>(</span><span class=cF7>(</span><span class=cF0>j+</span><span class=cFE>1</span><span class=cF7>)</span><span class=cF0>*d_a1);
<a name="l112"></a> z1 = r * </span><span class=cF5>Sin</span><span class=cF0>( j *d_a1);
<a name="l113"></a> z2 = r * </span><span class=cF5>Sin</span><span class=cF0>(</span><span class=cF7>(</span><span class=cF0>j+</span><span class=cFE>1</span><span class=cF7>)</span><span class=cF0>*d_a1);
<a name="l114"></a> </span><span class=cF1>for</span><span class=cF0> (i = </span><span class=cFE>0</span><span class=cF0>; i &lt; m; i++)
<a name="l115"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l116"></a> p1 = AddVertex(&amp;bd2, r1 * </span><span class=cF5>Cos</span><span class=cF7>(</span><span class=cF0>(</span><span class=cFE>2</span><span class=cF0> * 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>(</span><span class=cFE>2</span><span class=cF0> * i + j) * d_a2</span><span class=cF7>)</span><span class=cF0>, z1);
<a name="l117"></a> p2 = AddVertex(&amp;bd2, r1 * </span><span class=cF5>Cos</span><span class=cF7>(</span><span class=cF0>(</span><span class=cFE>2</span><span class=cF0> * i + </span><span class=cFE>2</span><span class=cF0> +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>(</span><span class=cFE>2</span><span class=cF0> * i + </span><span class=cFE>2</span><span class=cF0> + j) * d_a2</span><span class=cF7>)</span><span class=cF0>, z1);
<a name="l118"></a> p3 = AddVertex(&amp;bd2, r2 * </span><span class=cF5>Cos</span><span class=cF7>(</span><span class=cF0>(</span><span class=cFE>2</span><span class=cF0> * i + </span><span class=cFE>1</span><span class=cF0> +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>(</span><span class=cFE>2</span><span class=cF0> * i + </span><span class=cFE>1</span><span class=cF0> + j) * d_a2</span><span class=cF7>)</span><span class=cF0>, z2);
<a name="l119"></a> p4 = AddVertex(&amp;bd2, r2 * </span><span class=cF5>Cos</span><span class=cF7>(</span><span class=cF0>(</span><span class=cFE>2</span><span class=cF0> * i + </span><span class=cFE>3</span><span class=cF0> +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>(</span><span class=cFE>2</span><span class=cF0> * i + </span><span class=cFE>3</span><span class=cF0> + j) * d_a2</span><span class=cF7>)</span><span class=cF0>, z2);
<a name="l120"></a> AddTri(&amp;bd2, c, p1, p2, p3);
<a name="l121"></a> AddTri(&amp;bd2, c, p3, p2, p4);
<a name="l122"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l123"></a> }
<a name="l124"></a>
<a name="l125"></a> res = Ball2CSprite;
<a name="l126"></a> </span><span class=cF6>&quot;%h7c&quot;</span><span class=cF0>, </span><span class=cF6>'\n'</span><span class=cF0>;
<a name="l127"></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="l128"></a> </span><span class=cF6>&quot;%h7c&quot;</span><span class=cF0>, </span><span class=cF6>'\n'</span><span class=cF0>;
<a name="l129"></a> </span><span class=cF6>&quot;Vertices:%d\n&quot;</span><span class=cF0>, b-&gt;vertex_count;
<a name="l130"></a> </span><span class=cF5>Free</span><span class=cF0>(b);
<a name="l131"></a> </span><span class=cF6>&quot;Do another&quot;</span><span class=cF0>;
<a name="l132"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cF5>YorN</span><span class=cF0>)
<a name="l133"></a> </span><span class=cF5>Free</span><span class=cF0>(res);
<a name="l134"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l135"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l136"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l137"></a>
<a name="l138"></a> </span><span class=cF1>return</span><span class=cF0> res;
<a name="l139"></a>}
</span></pre></body>
</html>