commit cb62bce36edf686862751b71f5e408fc0efe5815
parent b50b663aec52b41989f43b3a30a9ff34cedd4a50
Author: Matsuda Kenji <info@mtkn.jp>
Date: Mon, 2 Jan 2023 18:52:54 +0900
add xlib_playground4
Diffstat:
12 files changed, 472 insertions(+), 15 deletions(-)
diff --git a/data/weblog b/data/weblog
@@ -107,3 +107,13 @@
1672585200 /computer/xlib_playground2.html
1672585200 /computer/xlib_playground3.html
1672585200 /computer/xlib_playground4.html
+1672585200 /computer/xlib_playground4.html
+1672585200 /computer/xlib_playground4.html
+1672585200 /computer/xlib_playground4.html
+1672585200 /computer/xlib_playground4.html
+1672585200 /computer/xlib_playground4.html
+1672585200 /computer/index.html
+1672585200 /computer/xlib_playground3.html
+1672585200 /computer/xlib_playground4.html
+1672585200 /index.html
+1672585200 /computer/xlib_playground3.html
diff --git a/man/computer/index.html b/man/computer/index.html
@@ -7,6 +7,7 @@ Small is beautiful.
<li><a href="xlib_playground1.html">Xlibで遊んでみる1</a></li>
<li><a href="xlib_playground2.html">Xlibで遊んでみる2</a></li>
<li><a href="xlib_playground3.html">Xlibで遊んでみる3</a></li>
+ <li><a href="xlib_playground4.html">Xlibで遊んでみる4</a></li>
</ul>
<h2>MISC</h1>
diff --git a/man/computer/videos/ex4.webm b/man/computer/videos/ex4.webm
Binary files differ.
diff --git a/man/computer/xlib_playground3.html b/man/computer/xlib_playground3.html
@@ -171,3 +171,7 @@ main(void)
<ul>
<li><a href="https://tronche.com/gui/x/xlib/">The Xlib Manual(html conversion)</a></li>
</ul>
+<p>
+次の記事: \
+<a href="xlib_playground4.html">Xlibで遊んでみる4</a>
+</p>
diff --git a/man/computer/xlib_playground4.html b/man/computer/xlib_playground4.html
@@ -0,0 +1,159 @@
+<h1>Xlibで遊んでみる4</h1>
+<time>2023-01-02</time>
+
+<p>
+前回: <a href="xlib_playground3.html">Xlibで遊んでみる3</a>
+</p>
+<p>
+言語: C言語<br />
+ソースコード: \
+<a href="https://git.mtkn.jp/xlib_playground/log.html">git</a>
+</p>
+
+<h2>衝突判定とその処理</h2>
+<p>
+これまでは一つの四角形だけを描画していたが、今回は複数の四角形を作成\
+して動かしてみた。ランダムな場所にランダムな運動量で動かして、\
+他のものやウィンドウの縁とぶつかったら跳ね返るようにした。\
+</p>
+<p>
+回転しない四角形どうしの衝突判定は簡単である。x軸方向とy軸方向の\
+両方に重なりがあれば衝突している:
+</p>
+<pre><code>\
+struct square {
+ float ppx, ppy; // previous position
+ float px, py; // current position
+ float vx, vy; // velocity
+ int w, h; // width and height
+};
+
+int
+test_collision(struct square *s1, struct square* s2)
+{
+ return s1->px < s2->px + s2->w && s2->px < s1->px + s1->w &&
+ s2->py < s1->py + s1->h && s1->py < s2->py + s2->h;
+}
+</code></pre>
+
+<p>
+衝突後の処理は多少めんどくさかった。\
+衝突した時は既にめりこんでいるので、まずはそれぞれをめりこんだ距離の半分\
+ずつずらして衝突を解消するようにした。この際、x軸方向にぶつかったのか、\
+y軸方向にぶつかったのかで、それぞれの軸方向にひっぺがすようにしている。\
+二つの四角形の各軸に関するめりこんだ距離<code>lapx</code>、<code>lapy</code>\
+と各軸に関する相対速度<code>rel_vx</code>、<code>rel_vy</code>の比を比べれば\
+どちらの軸方向にぶつかったかが分かるはずである、多分 :
+</p>
+<pre><code>\
+void
+handle_collision_mm(struct square *s1, struct square *s2)
+{
+ if (!test_collision(s1, s2))
+ return;
+
+ float lapx = min(s1->px + s1->w, s2->px + s2->w) - max(s1->px, s2->px);
+ float lapy = min(s1->py + s1->h, s2->py + s2->h) - max(s1->py, s2->py);
+ float rel_vx = max(s1->vx - s2->vx, s2->vx - s1->vx);
+ float rel_vy = max(s1->vy - s2->vy, s2->vy - s1->vy);
+
+ if (lapx / rel_vx < lapy / rel_vy) {
+ if (s1->px + s1->w < s2->px + s2->w / 2) {
+ s1->px -= lapx / 2;
+ s2->px += lapx / 2;
+ } else {
+ s1->px += lapx / 2;
+ s2->px -= lapx / 2;
+ }
+ } else {
+ if (s1->py + s1->h < s2->py + s2->h / 2) {
+ s1->py -= lapy / 2;
+ s2->py += lapy / 2;
+ } else {
+ s1->py += lapy / 2;
+ s2->py -= lapy / 2;
+ }
+ }
+}
+</pre></code>
+<p>
+衝突は弾性衝突として、衝突したそれぞれの四角形の速度を\
+更新した。質量は四角形の面積として計算している。\
+衝突後の速度はエネルギー保存則と運動量保存則から導いたのでしんどかった。
+</p>
+<pre><code>\
+void
+handle_collision_elastic(struct square *s1, struct square *s2)
+{
+ if(!test_collision(s1, s2))
+ return;
+
+ float v1, v2;
+ float m1 = s1->w * s1->h;
+ float m2 = s2->w * s2->h;
+
+ float lapx = min(s1->px + s1->w, s2->px + s2->w) - max(s1->px, s2->px);
+ float lapy = min(s1->py + s1->h, s2->py + s2->h) - max(s1->py, s2->py);
+
+ if (lapx < lapy) {
+ v1 = s1->vx;
+ v2 = s2->vx;
+ s1->vx = 2*m2/(m1+m2)*v2 + (m1-m2)/(m1+m2)*v1;
+ s2->vx = 2*m1/(m1+m2)*v1 + (m2-m1)/(m1+m2)*v2;
+ } else {
+ v1 = s1->vy;
+ v2 = s2->vy;
+ s1->vy = 2*m2/(m1+m2)*v2 + (m1-m2)/(m1+m2)*v1;
+ s2->vy = 2*m1/(m1+m2)*v1 + (m2-m1)/(m1+m2)*v2;
+ }
+
+ handle_collision_mm(s1, s2);
+}
+</code></pre>
+
+<h2>サブティック</h2>
+<p>
+この名前が適切かどうか分からないが、前のフレームから次のフレームまで\
+の時間をさらに何等分かして衝突判定の制度を上げた(マクロは括弧でかこって\
+分かりにくいバグを防げとどこかに書いていたのでそうすることにした):
+</p>
+<pre><code>\
+#define SUB_TIC (4)
+
+void
+game_play(void)
+{
+ /* ... */
+ while (next_menu == GAME_PLAY) {
+ /* ... */
+ for (int j = 0; j < SUB_TICK; j++) {
+ for (int i = 0; i < NUM_SQUARE; i++)
+ next_tick(&square[i], 1000 * 1000 * 1000 / FPS / SUB_TICK);
+
+ for (int i = 0; i < NUM_SQUARE; i++)
+ for (int j = i + 1; j < NUM_SQUARE; j++) {
+ handle_collision_elastic(&square[i], &square[j]);
+ /* ... */
+ }
+ /* ... */
+ }
+ /* ... */
+ }
+ /* ... */
+}
+</code></pre>
+
+<h2>完成品</h2>
+<p>
+<a href="https://git.mtkn.jp/xlib_playground/file/ex4/ex4.c.html">git</a>
+</p>
+<p>
+<video controls>
+<source src="videos/ex4.webm" type="video/webm">
+</video>
+</p>
+
+<h2>参考</h2>
+<ul>
+<li><a href="https://tronche.com/gui/x/xlib/">The Xlib Manual(html conversion)</a></li>
+</ul>
diff --git a/man/index.html b/man/index.html
@@ -9,6 +9,7 @@
<h2>更新履歴</h2>
<a href="/rss.xml">RSS</a>
<ul>
+<li>2023-01-02 <a href="/computer/xlib_playground4.html">Xlibで遊んでみる4</a></li>
<li>2023-01-02 <a href="/computer/xlib_playground3.html">Xlibで遊んでみる3</a></li>
<li>2022-12-28 <a href="/journal/posts/20221228.html">Holy Shit!</a></li>
<li>2022-12-22 <a href="/computer/xlib_playground2.html">Xlibで遊んでみる2</a></li>
@@ -22,10 +23,4 @@
<li>2022-08-03 <a href="/journal/posts/20220730.html">新型コロナウイルスとその対策に関する個人的見解</a></li>
<li>2022-07-29 <a href="/journal/posts/20220729.html">RSS作った</a></li>
<li>2022-07-20 <a href="/journal/posts/20200808.html">冷蔵庫と豊かな生活</a></li>
-<li>2022-06-27 <a href="/computer/setting_up_web_server.html">Webサーバーの設定</a></li>
-<li>2022-05-13 <a href="/journal/posts/20220513.html">坊主になるために薬の服用を強要されそうにな
-ってる。</a></li>
-<li>2022-05-09 <a href="/farm/journal/2022.html">令和4年 農業日誌</a></li>
-<li>2022-02-08 <a href="/kitchen/recipe/tonkotsu_ramen.html">豚骨ラーメン</a></li>
-<li>2022-01-15 <a href="/computer/rtx1200-qos.html">ルーター(RTX1200)のQoS機能を利用して帯域を制限した</a></li>
</ul>
diff --git a/pub/computer/index.html b/pub/computer/index.html
@@ -30,6 +30,7 @@ Small is beautiful.
<li><a href="xlib_playground1.html">Xlibで遊んでみる1</a></li>
<li><a href="xlib_playground2.html">Xlibで遊んでみる2</a></li>
<li><a href="xlib_playground3.html">Xlibで遊んでみる3</a></li>
+ <li><a href="xlib_playground4.html">Xlibで遊んでみる4</a></li>
</ul>
<h2>MISC</h1>
diff --git a/pub/computer/videos/ex4.webm b/pub/computer/videos/ex4.webm
Binary files differ.
diff --git a/pub/computer/xlib_playground3.html b/pub/computer/xlib_playground3.html
@@ -182,6 +182,9 @@ main(void)
<ul>
<li><a href="https://tronche.com/gui/x/xlib/">The Xlib Manual(html conversion)</a></li>
</ul>
+<p>
+次の記事: <a href="xlib_playground4.html">Xlibで遊んでみる4</a>
+</p>
</article>
</main>
diff --git a/pub/computer/xlib_playground4.html b/pub/computer/xlib_playground4.html
@@ -0,0 +1,171 @@
+<!DOCTYPE html>
+<html lang="ja">
+<head>
+ <meta charset="utf-8" />
+ <meta name="viewport" content="width=device-width,initial-scale=1" />
+ <link rel="stylesheet" type="text/css" href="/style.css" />
+ <link rel="icon" type="image/x-icon" href="/pics/favicon.ico" />
+ <title>Xlibで遊んでみる4</title>
+</head>
+<body>
+ <header>
+ <a href="/">主頁</a> |
+ <a href="/about.html">自己紹介</a> |
+ <a href="/journal">日記</a> |
+ <a href="/farm">農業</a> |
+ <a href="/kitchen">台所</a> |
+ <a href="/computer">コンピュータ</a> |
+ <a href="/poetry">詩</a> |
+ <a href="/books">本棚</a> |
+ <a href="https://git.mtkn.jp">Git</a>
+ </header>
+ <main>
+ <article>
+<h1>Xlibで遊んでみる4</h1>
+<time>2023-01-02</time>
+
+<p>
+前回: <a href="xlib_playground3.html">Xlibで遊んでみる3</a>
+</p>
+<p>
+言語: C言語<br />
+ソースコード: <a href="https://git.mtkn.jp/xlib_playground/log.html">git</a>
+</p>
+
+<h2>衝突判定とその処理</h2>
+<p>
+これまでは一つの四角形だけを描画していたが、今回は複数の四角形を作成して動かしてみた。ランダムな場所にランダムな運動量で動かして、他のものやウィンドウの縁とぶつかったら跳ね返るようにした。</p>
+<p>
+回転しない四角形どうしの衝突判定は簡単である。x軸方向とy軸方向の両方に重なりがあれば衝突している:
+</p>
+<pre><code>struct square {
+ float ppx, ppy; // previous position
+ float px, py; // current position
+ float vx, vy; // velocity
+ int w, h; // width and height
+};
+
+int
+test_collision(struct square *s1, struct square* s2)
+{
+ return s1->px < s2->px + s2->w && s2->px < s1->px + s1->w &&
+ s2->py < s1->py + s1->h && s1->py < s2->py + s2->h;
+}
+</code></pre>
+
+<p>
+衝突後の処理は多少めんどくさかった。衝突した時は既にめりこんでいるので、まずはそれぞれをめりこんだ距離の半分ずつずらして衝突を解消するようにした。この際、x軸方向にぶつかったのか、y軸方向にぶつかったのかで、それぞれの軸方向にひっぺがすようにしている。二つの四角形の各軸に関するめりこんだ距離<code>lapx</code>、<code>lapy</code>と各軸に関する相対速度<code>rel_vx</code>、<code>rel_vy</code>の比を比べればどちらの軸方向にぶつかったかが分かるはずである、多分 :
+</p>
+<pre><code>void
+handle_collision_mm(struct square *s1, struct square *s2)
+{
+ if (!test_collision(s1, s2))
+ return;
+
+ float lapx = min(s1->px + s1->w, s2->px + s2->w) - max(s1->px, s2->px);
+ float lapy = min(s1->py + s1->h, s2->py + s2->h) - max(s1->py, s2->py);
+ float rel_vx = max(s1->vx - s2->vx, s2->vx - s1->vx);
+ float rel_vy = max(s1->vy - s2->vy, s2->vy - s1->vy);
+
+ if (lapx / rel_vx < lapy / rel_vy) {
+ if (s1->px + s1->w < s2->px + s2->w / 2) {
+ s1->px -= lapx / 2;
+ s2->px += lapx / 2;
+ } else {
+ s1->px += lapx / 2;
+ s2->px -= lapx / 2;
+ }
+ } else {
+ if (s1->py + s1->h < s2->py + s2->h / 2) {
+ s1->py -= lapy / 2;
+ s2->py += lapy / 2;
+ } else {
+ s1->py += lapy / 2;
+ s2->py -= lapy / 2;
+ }
+ }
+}
+</pre></code>
+<p>
+衝突は弾性衝突として、衝突したそれぞれの四角形の速度を更新した。質量は四角形の面積として計算している。衝突後の速度はエネルギー保存則と運動量保存則から導いたのでしんどかった。
+</p>
+<pre><code>void
+handle_collision_elastic(struct square *s1, struct square *s2)
+{
+ if(!test_collision(s1, s2))
+ return;
+
+ float v1, v2;
+ float m1 = s1->w * s1->h;
+ float m2 = s2->w * s2->h;
+
+ float lapx = min(s1->px + s1->w, s2->px + s2->w) - max(s1->px, s2->px);
+ float lapy = min(s1->py + s1->h, s2->py + s2->h) - max(s1->py, s2->py);
+
+ if (lapx < lapy) {
+ v1 = s1->vx;
+ v2 = s2->vx;
+ s1->vx = 2*m2/(m1+m2)*v2 + (m1-m2)/(m1+m2)*v1;
+ s2->vx = 2*m1/(m1+m2)*v1 + (m2-m1)/(m1+m2)*v2;
+ } else {
+ v1 = s1->vy;
+ v2 = s2->vy;
+ s1->vy = 2*m2/(m1+m2)*v2 + (m1-m2)/(m1+m2)*v1;
+ s2->vy = 2*m1/(m1+m2)*v1 + (m2-m1)/(m1+m2)*v2;
+ }
+
+ handle_collision_mm(s1, s2);
+}
+</code></pre>
+
+<h2>サブティック</h2>
+<p>
+この名前が適切かどうか分からないが、前のフレームから次のフレームまでの時間をさらに何等分かして衝突判定の制度を上げた(マクロは括弧でかこって分かりにくいバグを防げとどこかに書いていたのでそうすることにした):
+</p>
+<pre><code>#define SUB_TIC (4)
+
+void
+game_play(void)
+{
+ /* ... */
+ while (next_menu == GAME_PLAY) {
+ /* ... */
+ for (int j = 0; j < SUB_TICK; j++) {
+ for (int i = 0; i < NUM_SQUARE; i++)
+ next_tick(&square[i], 1000 * 1000 * 1000 / FPS / SUB_TICK);
+
+ for (int i = 0; i < NUM_SQUARE; i++)
+ for (int j = i + 1; j < NUM_SQUARE; j++) {
+ handle_collision_elastic(&square[i], &square[j]);
+ /* ... */
+ }
+ /* ... */
+ }
+ /* ... */
+ }
+ /* ... */
+}
+</code></pre>
+
+<h2>完成品</h2>
+<p>
+<a href="https://git.mtkn.jp/xlib_playground/file/ex4/ex4.c.html">git</a>
+</p>
+<p>
+<video controls>
+<source src="videos/ex4.webm" type="video/webm">
+</video>
+</p>
+
+<h2>参考</h2>
+<ul>
+<li><a href="https://tronche.com/gui/x/xlib/">The Xlib Manual(html conversion)</a></li>
+</ul>
+ </article>
+
+ </main>
+ <footer>
+ <address>info(at)mtkn(dot)jp</address>
+ </footer>
+</body>
+</html>
diff --git a/pub/index.html b/pub/index.html
@@ -32,6 +32,7 @@
<h2>更新履歴</h2>
<a href="/rss.xml">RSS</a>
<ul>
+<li>2023-01-02 <a href="/computer/xlib_playground4.html">Xlibで遊んでみる4</a></li>
<li>2023-01-02 <a href="/computer/xlib_playground3.html">Xlibで遊んでみる3</a></li>
<li>2022-12-28 <a href="/journal/posts/20221228.html">Holy Shit!</a></li>
<li>2022-12-22 <a href="/computer/xlib_playground2.html">Xlibで遊んでみる2</a></li>
@@ -45,12 +46,6 @@
<li>2022-08-03 <a href="/journal/posts/20220730.html">新型コロナウイルスとその対策に関する個人的見解</a></li>
<li>2022-07-29 <a href="/journal/posts/20220729.html">RSS作った</a></li>
<li>2022-07-20 <a href="/journal/posts/20200808.html">冷蔵庫と豊かな生活</a></li>
-<li>2022-06-27 <a href="/computer/setting_up_web_server.html">Webサーバーの設定</a></li>
-<li>2022-05-13 <a href="/journal/posts/20220513.html">坊主になるために薬の服用を強要されそうにな
-ってる。</a></li>
-<li>2022-05-09 <a href="/farm/journal/2022.html">令和4年 農業日誌</a></li>
-<li>2022-02-08 <a href="/kitchen/recipe/tonkotsu_ramen.html">豚骨ラーメン</a></li>
-<li>2022-01-15 <a href="/computer/rtx1200-qos.html">ルーター(RTX1200)のQoS機能を利用して帯域を制限した</a></li>
</ul>
</article>
diff --git a/pub/rss.xml b/pub/rss.xml
@@ -5,8 +5,8 @@
<description>ウェブページの更新履歴</description>
<language>ja-jp</language>
<link>https://www.mtkn.jp</link>
-<lastBuildDate>Mon, 2 Jan 2023 14:16:35 +0900</lastBuildDate>
-<pubDate>Mon, 2 Jan 2023 14:16:35 +0900</pubDate>
+<lastBuildDate>Mon, 2 Jan 2023 18:51:14 +0900</lastBuildDate>
+<pubDate>Mon, 2 Jan 2023 18:51:14 +0900</pubDate>
<docs>https://www.rssboard.org/rss-specification</docs>
<item>
<title>Xlibで遊んでみる4</title>
@@ -17,13 +17,128 @@
<time>2023-01-02</time>
<p>
-前回: <a href="xlib_playground4.html">Xlibで遊んでみる4</a>
+前回: <a href="xlib_playground3.html">Xlibで遊んでみる3</a>
</p>
<p>
言語: C言語<br />
ソースコード: <a href="https://git.mtkn.jp/xlib_playground/log.html">git</a>
</p>
+<h2>衝突判定とその処理</h2>
+<p>
+これまでは一つの四角形だけを描画していたが、今回は複数の四角形を作成して動かしてみた。ランダムな場所にランダムな運動量で動かして、他のものやウィンドウの縁とぶつかったら跳ね返るようにした。</p>
+<p>
+回転しない四角形どうしの衝突判定は簡単である。x軸方向とy軸方向の両方に重なりがあれば衝突している:
+</p>
+<pre><code>struct square {
+ float ppx, ppy; // previous position
+ float px, py; // current position
+ float vx, vy; // velocity
+ int w, h; // width and height
+};
+
+int
+test_collision(struct square *s1, struct square* s2)
+{
+ return s1->px < s2->px + s2->w && s2->px < s1->px + s1->w &&
+ s2->py < s1->py + s1->h && s1->py < s2->py + s2->h;
+}
+</code></pre>
+
+<p>
+衝突後の処理は多少めんどくさかった。衝突した時は既にめりこんでいるので、まずはそれぞれをめりこんだ距離の半分ずつずらして衝突を解消するようにした。この際、x軸方向にぶつかったのか、y軸方向にぶつかったのかで、それぞれの軸方向にひっぺがすようにしている。二つの四角形の各軸に関するめりこんだ距離<code>lapx</code>、<code>lapy</code>と各軸に関する相対速度<code>rel_vx</code>、<code>rel_vy</code>の比を比べればどちらの軸方向にぶつかったかが分かるはずである、多分 :
+</p>
+<pre><code>void
+handle_collision_mm(struct square *s1, struct square *s2)
+{
+ if (!test_collision(s1, s2))
+ return;
+
+ float lapx = min(s1->px + s1->w, s2->px + s2->w) - max(s1->px, s2->px);
+ float lapy = min(s1->py + s1->h, s2->py + s2->h) - max(s1->py, s2->py);
+ float rel_vx = max(s1->vx - s2->vx, s2->vx - s1->vx);
+ float rel_vy = max(s1->vy - s2->vy, s2->vy - s1->vy);
+
+ if (lapx / rel_vx < lapy / rel_vy) {
+ if (s1->px + s1->w < s2->px + s2->w / 2) {
+ s1->px -= lapx / 2;
+ s2->px += lapx / 2;
+ } else {
+ s1->px += lapx / 2;
+ s2->px -= lapx / 2;
+ }
+ } else {
+ if (s1->py + s1->h < s2->py + s2->h / 2) {
+ s1->py -= lapy / 2;
+ s2->py += lapy / 2;
+ } else {
+ s1->py += lapy / 2;
+ s2->py -= lapy / 2;
+ }
+ }
+}
+</pre></code>
+<p>
+衝突は弾性衝突として、衝突したそれぞれの四角形の速度を更新した。質量は四角形の面積として計算している。衝突後の速度はエネルギー保存則と運動量保存則から導いたのでしんどかった。
+</p>
+<pre><code>void
+handle_collision_elastic(struct square *s1, struct square *s2)
+{
+ if(!test_collision(s1, s2))
+ return;
+
+ float v1, v2;
+ float m1 = s1->w * s1->h;
+ float m2 = s2->w * s2->h;
+
+ float lapx = min(s1->px + s1->w, s2->px + s2->w) - max(s1->px, s2->px);
+ float lapy = min(s1->py + s1->h, s2->py + s2->h) - max(s1->py, s2->py);
+
+ if (lapx < lapy) {
+ v1 = s1->vx;
+ v2 = s2->vx;
+ s1->vx = 2*m2/(m1+m2)*v2 + (m1-m2)/(m1+m2)*v1;
+ s2->vx = 2*m1/(m1+m2)*v1 + (m2-m1)/(m1+m2)*v2;
+ } else {
+ v1 = s1->vy;
+ v2 = s2->vy;
+ s1->vy = 2*m2/(m1+m2)*v2 + (m1-m2)/(m1+m2)*v1;
+ s2->vy = 2*m1/(m1+m2)*v1 + (m2-m1)/(m1+m2)*v2;
+ }
+
+ handle_collision_mm(s1, s2);
+}
+</code></pre>
+
+<h2>サブティック</h2>
+<p>
+この名前が適切かどうか分からないが、前のフレームから次のフレームまでの時間をさらに何等分かして衝突判定の制度を上げた(マクロは括弧でかこって分かりにくいバグを防げとどこかに書いていたのでそうすることにした):
+</p>
+<pre><code>#define SUB_TIC (4)
+
+void
+game_play(void)
+{
+ /* ... */
+ while (next_menu == GAME_PLAY) {
+ /* ... */
+ for (int j = 0; j < SUB_TICK; j++) {
+ for (int i = 0; i < NUM_SQUARE; i++)
+ next_tick(&square[i], 1000 * 1000 * 1000 / FPS / SUB_TICK);
+
+ for (int i = 0; i < NUM_SQUARE; i++)
+ for (int j = i + 1; j < NUM_SQUARE; j++) {
+ handle_collision_elastic(&square[i], &square[j]);
+ /* ... */
+ }
+ /* ... */
+ }
+ /* ... */
+ }
+ /* ... */
+}
+</code></pre>
+
<h2>完成品</h2>
<p>
<a href="https://git.mtkn.jp/xlib_playground/file/ex4/ex4.c.html">git</a>
@@ -206,6 +321,9 @@ main(void)
<ul>
<li><a href="https://tronche.com/gui/x/xlib/">The Xlib Manual(html conversion)</a></li>
</ul>
+<p>
+次の記事: <a href="xlib_playground4.html">Xlibで遊んでみる4</a>
+</p>
]]></description>
</item>
<item>