diff --git a/games/tps/CMakeLists.txt b/games/tps/CMakeLists.txt new file mode 100644 index 0000000..59b2053 --- /dev/null +++ b/games/tps/CMakeLists.txt @@ -0,0 +1,14 @@ +# 第36〜39章:三人称シューティング(TPS) / Chapters 36-39: the third-person shooter (TPS) +add_executable(tps + src/main.cc + src/collision3d.cc + src/frustum.cc + src/level.cc + src/renderer.cc + src/character.cc + src/third_person_camera.cc + src/play_scene.cc) +target_include_directories(tps PRIVATE src) +target_link_libraries(tps PRIVATE engine) +enable_warnings(tps) +set_working_directory(tps) diff --git a/games/tps/README.md b/games/tps/README.md new file mode 100644 index 0000000..c4e4af1 --- /dev/null +++ b/games/tps/README.md @@ -0,0 +1,41 @@ +# TPS(三人称シューティング) / TPS (third-person shooter) — 第36〜39章 / chapters 36-39 + +プロジェクトのルートから実行する / run from the project root: + +```sh +./build/games/tps/tps # Windows: build\games\tps\Debug\tps.exe +./build/games/tps/tps games/tps/assets/levels/pieces.level # 部品を並べたレベル / every piece in a row +``` + +## 操作 / Controls(第36章 / chapter 36) + +| キー / key | | +|---|---| +| WASD / ↑↓←→ | カメラの向きに対して移動 / move relative to the camera | +| マウス / mouse | 見回す / look around | +| Shift | 走る(前へ) / run (forwards) | +| Q | 右肩 ⇔ 左肩 / right ⇔ left shoulder | +| B | 当たり判定の箱とソケット / collision boxes and sockets | +| C | カメラだけ回す(キャラクターを前から見る) / turn only the camera (look at the character) | +| K | カメラの当たり判定のオン・オフ / camera collision on / off | +| P | 手続き的な姿勢のオン・オフ / procedural pose on / off | +| F3 | 時間と描いた数 / timings and draw counts | +| F4 | 視錐台カリングのオン・オフ / frustum culling on / off | +| Tab | カーソルのキャプチャ / cursor capture | +| Esc | 終了 / quit | + +## ファイル / Files + +``` +src/main.cc ウィンドウ、読み込み、ゲームループ / window, loading, game loop +src/game.hh シーンが共有するデータ / data the scenes share +src/play_scene.* 遊ぶシーン / the play scene +src/level.* レベルのファイル、インスタンシング、カリング / level file, instancing, culling +src/collision3d.* AABB、レイ、スフィアキャスト / AABBs, rays, sphere casts +src/frustum.* 視錐台の平面 / frustum planes +src/renderer.* 影 → 場面(PBR + IBL) → 後処理 / shadows → scene (PBR + IBL) → post +src/character.* 関節の姿勢と腕のIK / joint poses and arm IK +src/third_person_camera.* 肩越しのカメラ / the over-the-shoulder camera +shaders/instanced.vert 部品のインスタンシング(フラグメントはengine/shaders/pbr.frag) / instanced pieces +assets/ モデル・レベル・フォント(assets/LICENSE.txt) / models, levels, font +``` diff --git a/games/tps/assets/LICENSE.txt b/games/tps/assets/LICENSE.txt new file mode 100644 index 0000000..54d4c13 --- /dev/null +++ b/games/tps/assets/LICENSE.txt @@ -0,0 +1,27 @@ +games/tps/assets/ のファイルはこのチュートリアルのために作者が自作したもの(作者のPythonのスクリプトで生成。スクリプトはこのプロジェクトには含まれない)。自由に使ってよい。 +The files in games/tps/assets/ were made for this tutorial by the author (generated with the author's own Python scripts, which are not part of this project). Free to use for any purpose. + +models/floor_tile.glb コンクリートの床タイル 4 × 4 m / a 4 × 4 m concrete floor tile (chapter 36) +models/wall.glb コンクリートの壁 4 × 3 m / a 4 × 3 m concrete wall +models/cover.glb 低い遮蔽(バリア) / low cover, a concrete barrier +models/pillar.glb 柱と照明 / a pillar with a lamp +models/platform.glb 台(縞鋼板の上面) / a platform with a diamond-plate top +models/stairs.glb 階段 / stairs +models/player.glb プレイヤー:部品の階層とソケット / the player: parts in a node hierarchy + sockets +models/rifle.glb ライフル(Muzzle・Foregripソケット) / the rifle (Muzzle and Foregrip sockets) +levels/arena.level レベル(手で書いたテキスト) / the level (hand-written text) +levels/pieces.level 部品を並べた確認用のレベル / every piece in a row, for checking (hand-written text) +fonts/mono16.png/.fnt 共有のmono16にこのゲームの漢字を足したもの / the shared mono16 plus this game's kanji + (足した漢字 / added kanji: 移動走肩跳撃弾装填三称任務失敗破命中率照狙射銃戦闘) + +フォントの画像(fonts/mono16.png)について / About the font image (fonts/mono16.png): +これらは次のフォントから文字を画像にしたもの(フォントのファイル自体は含まない) / it contains glyph images rasterized +from these fonts (the font files themselves are not included): + * ASCIIの文字 / ASCII characters: DejaVu Sans Mono (https://dejavu-fonts.github.io/). + Copyright (c) 2003 by Bitstream, Inc. All Rights Reserved. Bitstream Vera is a trademark of Bitstream, Inc. + DejaVu changes are in public domain. Bitstream Vera Fonts license: the fonts may be used, copied, modified and + distributed freely as long as the copyright notice is kept and modified fonts are not called "Bitstream" or + "Vera" (full text: https://dejavu-fonts.github.io/License.html). + * 日本語の文字(かな・カナ・漢字の一部) / Japanese characters (kana and a kanji subset): Noto Sans CJK JP + (https://github.com/notofonts/noto-cjk). Copyright 2014-2021 Adobe (http://www.adobe.com/). Noto is a trademark + of Google Inc. Licensed under the SIL Open Font License, Version 1.1 (https://openfontlicense.org). diff --git a/games/tps/assets/fonts/mono16.fnt b/games/tps/assets/fonts/mono16.fnt new file mode 100644 index 0000000..d18e3e8 --- /dev/null +++ b/games/tps/assets/fonts/mono16.fnt @@ -0,0 +1,575 @@ +info face="DejaVu Sans Mono + Noto Sans CJK JP" size=16 bold=0 italic=0 charset="" unicode=1 stretchH=100 smooth=1 aa=1 padding=1,1,1,1 spacing=2,2 +common lineHeight=20 base=15 scaleW=512 scaleH=512 pages=1 packed=0 +page id=0 file="mono16.png" +chars count=571 +char id=32 x=1 y=1 width=0 height=0 xoffset=0 yoffset=15 xadvance=10 page=0 chnl=15 +char id=33 x=3 y=1 width=10 height=12 xoffset=0 yoffset=3 xadvance=10 page=0 chnl=15 +char id=34 x=15 y=1 width=10 height=12 xoffset=0 yoffset=3 xadvance=10 page=0 chnl=15 +char id=35 x=27 y=1 width=10 height=11 xoffset=0 yoffset=4 xadvance=10 page=0 chnl=15 +char id=36 x=39 y=1 width=10 height=14 xoffset=0 yoffset=3 xadvance=10 page=0 chnl=15 +char id=37 x=51 y=1 width=10 height=12 xoffset=0 yoffset=3 xadvance=10 page=0 chnl=15 +char id=38 x=63 y=1 width=10 height=12 xoffset=0 yoffset=3 xadvance=10 page=0 chnl=15 +char id=39 x=75 y=1 width=10 height=12 xoffset=0 yoffset=3 xadvance=10 page=0 chnl=15 +char id=40 x=87 y=1 width=10 height=14 xoffset=0 yoffset=3 xadvance=10 page=0 chnl=15 +char id=41 x=99 y=1 width=10 height=14 xoffset=0 yoffset=3 xadvance=10 page=0 chnl=15 +char id=42 x=111 y=1 width=10 height=12 xoffset=0 yoffset=3 xadvance=10 page=0 chnl=15 +char id=43 x=123 y=1 width=10 height=8 xoffset=0 yoffset=7 xadvance=10 page=0 chnl=15 +char id=44 x=135 y=1 width=10 height=5 xoffset=0 yoffset=13 xadvance=10 page=0 chnl=15 +char id=45 x=147 y=1 width=10 height=5 xoffset=0 yoffset=10 xadvance=10 page=0 chnl=15 +char id=46 x=159 y=1 width=10 height=2 xoffset=0 yoffset=13 xadvance=10 page=0 chnl=15 +char id=47 x=171 y=1 width=10 height=13 xoffset=0 yoffset=3 xadvance=10 page=0 chnl=15 +char id=48 x=183 y=1 width=10 height=12 xoffset=0 yoffset=3 xadvance=10 page=0 chnl=15 +char id=49 x=195 y=1 width=10 height=12 xoffset=0 yoffset=3 xadvance=10 page=0 chnl=15 +char id=50 x=207 y=1 width=10 height=12 xoffset=0 yoffset=3 xadvance=10 page=0 chnl=15 +char id=51 x=219 y=1 width=10 height=12 xoffset=0 yoffset=3 xadvance=10 page=0 chnl=15 +char id=52 x=231 y=1 width=10 height=12 xoffset=0 yoffset=3 xadvance=10 page=0 chnl=15 +char id=53 x=243 y=1 width=10 height=12 xoffset=0 yoffset=3 xadvance=10 page=0 chnl=15 +char id=54 x=255 y=1 width=10 height=12 xoffset=0 yoffset=3 xadvance=10 page=0 chnl=15 +char id=55 x=267 y=1 width=10 height=12 xoffset=0 yoffset=3 xadvance=10 page=0 chnl=15 +char id=56 x=279 y=1 width=10 height=12 xoffset=0 yoffset=3 xadvance=10 page=0 chnl=15 +char id=57 x=291 y=1 width=10 height=12 xoffset=0 yoffset=3 xadvance=10 page=0 chnl=15 +char id=58 x=303 y=1 width=10 height=8 xoffset=0 yoffset=7 xadvance=10 page=0 chnl=15 +char id=59 x=315 y=1 width=10 height=11 xoffset=0 yoffset=7 xadvance=10 page=0 chnl=15 +char id=60 x=327 y=1 width=10 height=9 xoffset=0 yoffset=6 xadvance=10 page=0 chnl=15 +char id=61 x=339 y=1 width=10 height=7 xoffset=0 yoffset=8 xadvance=10 page=0 chnl=15 +char id=62 x=351 y=1 width=10 height=9 xoffset=0 yoffset=6 xadvance=10 page=0 chnl=15 +char id=63 x=363 y=1 width=10 height=12 xoffset=0 yoffset=3 xadvance=10 page=0 chnl=15 +char id=64 x=375 y=1 width=10 height=14 xoffset=0 yoffset=4 xadvance=10 page=0 chnl=15 +char id=65 x=387 y=1 width=10 height=12 xoffset=0 yoffset=3 xadvance=10 page=0 chnl=15 +char id=66 x=399 y=1 width=10 height=12 xoffset=0 yoffset=3 xadvance=10 page=0 chnl=15 +char id=67 x=411 y=1 width=10 height=12 xoffset=0 yoffset=3 xadvance=10 page=0 chnl=15 +char id=68 x=423 y=1 width=10 height=12 xoffset=0 yoffset=3 xadvance=10 page=0 chnl=15 +char id=69 x=435 y=1 width=10 height=12 xoffset=0 yoffset=3 xadvance=10 page=0 chnl=15 +char id=70 x=447 y=1 width=10 height=12 xoffset=0 yoffset=3 xadvance=10 page=0 chnl=15 +char id=71 x=459 y=1 width=10 height=12 xoffset=0 yoffset=3 xadvance=10 page=0 chnl=15 +char id=72 x=471 y=1 width=10 height=12 xoffset=0 yoffset=3 xadvance=10 page=0 chnl=15 +char id=73 x=483 y=1 width=10 height=12 xoffset=0 yoffset=3 xadvance=10 page=0 chnl=15 +char id=74 x=495 y=1 width=10 height=12 xoffset=0 yoffset=3 xadvance=10 page=0 chnl=15 +char id=75 x=1 y=17 width=10 height=12 xoffset=0 yoffset=3 xadvance=10 page=0 chnl=15 +char id=76 x=13 y=17 width=10 height=12 xoffset=0 yoffset=3 xadvance=10 page=0 chnl=15 +char id=77 x=25 y=17 width=10 height=12 xoffset=0 yoffset=3 xadvance=10 page=0 chnl=15 +char id=78 x=37 y=17 width=10 height=12 xoffset=0 yoffset=3 xadvance=10 page=0 chnl=15 +char id=79 x=49 y=17 width=10 height=12 xoffset=0 yoffset=3 xadvance=10 page=0 chnl=15 +char id=80 x=61 y=17 width=10 height=12 xoffset=0 yoffset=3 xadvance=10 page=0 chnl=15 +char id=81 x=73 y=17 width=10 height=14 xoffset=0 yoffset=3 xadvance=10 page=0 chnl=15 +char id=82 x=85 y=17 width=10 height=12 xoffset=0 yoffset=3 xadvance=10 page=0 chnl=15 +char id=83 x=97 y=17 width=10 height=12 xoffset=0 yoffset=3 xadvance=10 page=0 chnl=15 +char id=84 x=109 y=17 width=10 height=12 xoffset=0 yoffset=3 xadvance=10 page=0 chnl=15 +char id=85 x=121 y=17 width=10 height=12 xoffset=0 yoffset=3 xadvance=10 page=0 chnl=15 +char id=86 x=133 y=17 width=10 height=12 xoffset=0 yoffset=3 xadvance=10 page=0 chnl=15 +char id=87 x=145 y=17 width=10 height=12 xoffset=0 yoffset=3 xadvance=10 page=0 chnl=15 +char id=88 x=157 y=17 width=10 height=12 xoffset=0 yoffset=3 xadvance=10 page=0 chnl=15 +char id=89 x=169 y=17 width=10 height=12 xoffset=0 yoffset=3 xadvance=10 page=0 chnl=15 +char id=90 x=181 y=17 width=10 height=12 xoffset=0 yoffset=3 xadvance=10 page=0 chnl=15 +char id=91 x=193 y=17 width=10 height=14 xoffset=0 yoffset=3 xadvance=10 page=0 chnl=15 +char id=92 x=205 y=17 width=10 height=13 xoffset=0 yoffset=3 xadvance=10 page=0 chnl=15 +char id=93 x=217 y=17 width=10 height=14 xoffset=0 yoffset=3 xadvance=10 page=0 chnl=15 +char id=94 x=229 y=17 width=10 height=12 xoffset=0 yoffset=3 xadvance=10 page=0 chnl=15 +char id=95 x=241 y=17 width=10 height=4 xoffset=0 yoffset=15 xadvance=10 page=0 chnl=15 +char id=96 x=253 y=17 width=10 height=13 xoffset=0 yoffset=2 xadvance=10 page=0 chnl=15 +char id=97 x=265 y=17 width=10 height=9 xoffset=0 yoffset=6 xadvance=10 page=0 chnl=15 +char id=98 x=277 y=17 width=10 height=12 xoffset=0 yoffset=3 xadvance=10 page=0 chnl=15 +char id=99 x=289 y=17 width=10 height=9 xoffset=0 yoffset=6 xadvance=10 page=0 chnl=15 +char id=100 x=301 y=17 width=10 height=12 xoffset=0 yoffset=3 xadvance=10 page=0 chnl=15 +char id=101 x=313 y=17 width=10 height=9 xoffset=0 yoffset=6 xadvance=10 page=0 chnl=15 +char id=102 x=325 y=17 width=10 height=12 xoffset=0 yoffset=3 xadvance=10 page=0 chnl=15 +char id=103 x=337 y=17 width=10 height=12 xoffset=0 yoffset=6 xadvance=10 page=0 chnl=15 +char id=104 x=349 y=17 width=10 height=12 xoffset=0 yoffset=3 xadvance=10 page=0 chnl=15 +char id=105 x=361 y=17 width=10 height=12 xoffset=0 yoffset=3 xadvance=10 page=0 chnl=15 +char id=106 x=373 y=17 width=10 height=15 xoffset=0 yoffset=3 xadvance=10 page=0 chnl=15 +char id=107 x=385 y=17 width=10 height=12 xoffset=0 yoffset=3 xadvance=10 page=0 chnl=15 +char id=108 x=397 y=17 width=10 height=12 xoffset=0 yoffset=3 xadvance=10 page=0 chnl=15 +char id=109 x=409 y=17 width=10 height=9 xoffset=0 yoffset=6 xadvance=10 page=0 chnl=15 +char id=110 x=421 y=17 width=10 height=9 xoffset=0 yoffset=6 xadvance=10 page=0 chnl=15 +char id=111 x=433 y=17 width=10 height=9 xoffset=0 yoffset=6 xadvance=10 page=0 chnl=15 +char id=112 x=445 y=17 width=10 height=12 xoffset=0 yoffset=6 xadvance=10 page=0 chnl=15 +char id=113 x=457 y=17 width=10 height=12 xoffset=0 yoffset=6 xadvance=10 page=0 chnl=15 +char id=114 x=469 y=17 width=10 height=9 xoffset=0 yoffset=6 xadvance=10 page=0 chnl=15 +char id=115 x=481 y=17 width=10 height=9 xoffset=0 yoffset=6 xadvance=10 page=0 chnl=15 +char id=116 x=493 y=17 width=10 height=11 xoffset=0 yoffset=4 xadvance=10 page=0 chnl=15 +char id=117 x=1 y=34 width=10 height=9 xoffset=0 yoffset=6 xadvance=10 page=0 chnl=15 +char id=118 x=13 y=34 width=10 height=9 xoffset=0 yoffset=6 xadvance=10 page=0 chnl=15 +char id=119 x=25 y=34 width=10 height=9 xoffset=0 yoffset=6 xadvance=10 page=0 chnl=15 +char id=120 x=37 y=34 width=10 height=9 xoffset=0 yoffset=6 xadvance=10 page=0 chnl=15 +char id=121 x=49 y=34 width=10 height=12 xoffset=0 yoffset=6 xadvance=10 page=0 chnl=15 +char id=122 x=61 y=34 width=10 height=9 xoffset=0 yoffset=6 xadvance=10 page=0 chnl=15 +char id=123 x=73 y=34 width=10 height=15 xoffset=0 yoffset=3 xadvance=10 page=0 chnl=15 +char id=124 x=85 y=34 width=10 height=16 xoffset=0 yoffset=3 xadvance=10 page=0 chnl=15 +char id=125 x=97 y=34 width=10 height=15 xoffset=0 yoffset=3 xadvance=10 page=0 chnl=15 +char id=126 x=109 y=34 width=10 height=6 xoffset=0 yoffset=9 xadvance=10 page=0 chnl=15 +char id=12353 x=121 y=34 width=16 height=12 xoffset=0 yoffset=4 xadvance=16 page=0 chnl=15 +char id=12354 x=139 y=34 width=16 height=16 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=12355 x=157 y=34 width=16 height=11 xoffset=0 yoffset=5 xadvance=16 page=0 chnl=15 +char id=12356 x=175 y=34 width=16 height=13 xoffset=0 yoffset=3 xadvance=16 page=0 chnl=15 +char id=12357 x=193 y=34 width=16 height=13 xoffset=0 yoffset=4 xadvance=16 page=0 chnl=15 +char id=12358 x=211 y=34 width=16 height=15 xoffset=0 yoffset=2 xadvance=16 page=0 chnl=15 +char id=12359 x=229 y=34 width=16 height=13 xoffset=0 yoffset=4 xadvance=16 page=0 chnl=15 +char id=12360 x=247 y=34 width=16 height=15 xoffset=0 yoffset=2 xadvance=16 page=0 chnl=15 +char id=12361 x=265 y=34 width=16 height=13 xoffset=0 yoffset=4 xadvance=16 page=0 chnl=15 +char id=12362 x=283 y=34 width=16 height=15 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=12363 x=301 y=34 width=16 height=15 xoffset=0 yoffset=2 xadvance=16 page=0 chnl=15 +char id=12364 x=319 y=34 width=16 height=16 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=12365 x=337 y=34 width=16 height=16 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=12366 x=355 y=34 width=16 height=16 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=12367 x=373 y=34 width=16 height=14 xoffset=0 yoffset=2 xadvance=16 page=0 chnl=15 +char id=12368 x=391 y=34 width=16 height=14 xoffset=0 yoffset=2 xadvance=16 page=0 chnl=15 +char id=12369 x=409 y=34 width=16 height=15 xoffset=0 yoffset=2 xadvance=16 page=0 chnl=15 +char id=12370 x=427 y=34 width=16 height=16 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=12371 x=445 y=34 width=16 height=13 xoffset=0 yoffset=3 xadvance=16 page=0 chnl=15 +char id=12372 x=463 y=34 width=16 height=15 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=12373 x=481 y=34 width=16 height=16 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=12374 x=1 y=52 width=16 height=17 xoffset=0 yoffset=0 xadvance=16 page=0 chnl=15 +char id=12375 x=19 y=52 width=16 height=15 xoffset=0 yoffset=2 xadvance=16 page=0 chnl=15 +char id=12376 x=37 y=52 width=16 height=15 xoffset=0 yoffset=2 xadvance=16 page=0 chnl=15 +char id=12377 x=55 y=52 width=16 height=16 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=12378 x=73 y=52 width=16 height=16 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=12379 x=91 y=52 width=16 height=14 xoffset=0 yoffset=2 xadvance=16 page=0 chnl=15 +char id=12380 x=109 y=52 width=16 height=15 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=12381 x=127 y=52 width=16 height=15 xoffset=0 yoffset=2 xadvance=16 page=0 chnl=15 +char id=12382 x=145 y=52 width=16 height=15 xoffset=0 yoffset=2 xadvance=16 page=0 chnl=15 +char id=12383 x=163 y=52 width=16 height=16 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=12384 x=181 y=52 width=16 height=15 xoffset=0 yoffset=2 xadvance=16 page=0 chnl=15 +char id=12385 x=199 y=52 width=16 height=15 xoffset=0 yoffset=2 xadvance=16 page=0 chnl=15 +char id=12386 x=217 y=52 width=16 height=16 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=12387 x=235 y=52 width=16 height=10 xoffset=0 yoffset=6 xadvance=16 page=0 chnl=15 +char id=12388 x=253 y=52 width=16 height=12 xoffset=0 yoffset=4 xadvance=16 page=0 chnl=15 +char id=12389 x=271 y=52 width=16 height=15 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=12390 x=289 y=52 width=16 height=13 xoffset=0 yoffset=3 xadvance=16 page=0 chnl=15 +char id=12391 x=307 y=52 width=16 height=13 xoffset=0 yoffset=3 xadvance=16 page=0 chnl=15 +char id=12392 x=325 y=52 width=16 height=14 xoffset=0 yoffset=2 xadvance=16 page=0 chnl=15 +char id=12393 x=343 y=52 width=16 height=15 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=12394 x=361 y=52 width=16 height=16 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=12395 x=379 y=52 width=16 height=14 xoffset=0 yoffset=2 xadvance=16 page=0 chnl=15 +char id=12396 x=397 y=52 width=16 height=14 xoffset=0 yoffset=2 xadvance=16 page=0 chnl=15 +char id=12397 x=415 y=52 width=16 height=16 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=12398 x=433 y=52 width=16 height=13 xoffset=0 yoffset=3 xadvance=16 page=0 chnl=15 +char id=12399 x=451 y=52 width=16 height=15 xoffset=0 yoffset=2 xadvance=16 page=0 chnl=15 +char id=12400 x=469 y=52 width=16 height=16 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=12401 x=487 y=52 width=16 height=16 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=12402 x=1 y=71 width=16 height=14 xoffset=0 yoffset=3 xadvance=16 page=0 chnl=15 +char id=12403 x=19 y=71 width=16 height=16 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=12404 x=37 y=71 width=16 height=16 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=12405 x=55 y=71 width=16 height=14 xoffset=0 yoffset=2 xadvance=16 page=0 chnl=15 +char id=12406 x=73 y=71 width=16 height=14 xoffset=0 yoffset=2 xadvance=16 page=0 chnl=15 +char id=12407 x=91 y=71 width=16 height=14 xoffset=0 yoffset=2 xadvance=16 page=0 chnl=15 +char id=12408 x=109 y=71 width=16 height=11 xoffset=0 yoffset=4 xadvance=16 page=0 chnl=15 +char id=12409 x=127 y=71 width=16 height=13 xoffset=0 yoffset=3 xadvance=16 page=0 chnl=15 +char id=12410 x=145 y=71 width=16 height=13 xoffset=0 yoffset=3 xadvance=16 page=0 chnl=15 +char id=12411 x=163 y=71 width=16 height=15 xoffset=0 yoffset=2 xadvance=16 page=0 chnl=15 +char id=12412 x=181 y=71 width=16 height=16 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=12413 x=199 y=71 width=16 height=16 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=12414 x=217 y=71 width=16 height=15 xoffset=0 yoffset=2 xadvance=16 page=0 chnl=15 +char id=12415 x=235 y=71 width=16 height=15 xoffset=0 yoffset=2 xadvance=16 page=0 chnl=15 +char id=12416 x=253 y=71 width=16 height=16 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=12417 x=271 y=71 width=16 height=15 xoffset=0 yoffset=2 xadvance=16 page=0 chnl=15 +char id=12418 x=289 y=71 width=16 height=16 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=12419 x=307 y=71 width=16 height=13 xoffset=0 yoffset=4 xadvance=16 page=0 chnl=15 +char id=12420 x=325 y=71 width=16 height=16 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=12421 x=343 y=71 width=16 height=13 xoffset=0 yoffset=4 xadvance=16 page=0 chnl=15 +char id=12422 x=361 y=71 width=16 height=16 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=12423 x=379 y=71 width=16 height=13 xoffset=0 yoffset=4 xadvance=16 page=0 chnl=15 +char id=12424 x=397 y=71 width=16 height=15 xoffset=0 yoffset=2 xadvance=16 page=0 chnl=15 +char id=12425 x=415 y=71 width=16 height=15 xoffset=0 yoffset=2 xadvance=16 page=0 chnl=15 +char id=12426 x=433 y=71 width=16 height=15 xoffset=0 yoffset=2 xadvance=16 page=0 chnl=15 +char id=12427 x=451 y=71 width=16 height=15 xoffset=0 yoffset=2 xadvance=16 page=0 chnl=15 +char id=12428 x=469 y=71 width=16 height=14 xoffset=0 yoffset=2 xadvance=16 page=0 chnl=15 +char id=12429 x=487 y=71 width=16 height=15 xoffset=0 yoffset=2 xadvance=16 page=0 chnl=15 +char id=12430 x=1 y=89 width=16 height=13 xoffset=0 yoffset=4 xadvance=16 page=0 chnl=15 +char id=12431 x=19 y=89 width=16 height=16 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=12432 x=37 y=89 width=16 height=15 xoffset=0 yoffset=2 xadvance=16 page=0 chnl=15 +char id=12433 x=55 y=89 width=16 height=15 xoffset=0 yoffset=2 xadvance=16 page=0 chnl=15 +char id=12434 x=73 y=89 width=16 height=16 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=12435 x=91 y=89 width=16 height=15 xoffset=0 yoffset=2 xadvance=16 page=0 chnl=15 +char id=12436 x=109 y=89 width=16 height=15 xoffset=0 yoffset=2 xadvance=16 page=0 chnl=15 +char id=12437 x=127 y=89 width=16 height=12 xoffset=0 yoffset=5 xadvance=16 page=0 chnl=15 +char id=12438 x=145 y=89 width=16 height=12 xoffset=0 yoffset=5 xadvance=16 page=0 chnl=15 +char id=12445 x=163 y=89 width=16 height=11 xoffset=0 yoffset=4 xadvance=16 page=0 chnl=15 +char id=12446 x=181 y=89 width=16 height=12 xoffset=0 yoffset=3 xadvance=16 page=0 chnl=15 +char id=12449 x=199 y=89 width=16 height=12 xoffset=0 yoffset=5 xadvance=16 page=0 chnl=15 +char id=12450 x=217 y=89 width=16 height=15 xoffset=0 yoffset=2 xadvance=16 page=0 chnl=15 +char id=12451 x=235 y=89 width=16 height=12 xoffset=0 yoffset=5 xadvance=16 page=0 chnl=15 +char id=12452 x=253 y=89 width=16 height=14 xoffset=0 yoffset=2 xadvance=16 page=0 chnl=15 +char id=12453 x=271 y=89 width=16 height=12 xoffset=0 yoffset=5 xadvance=16 page=0 chnl=15 +char id=12454 x=289 y=89 width=16 height=16 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=12455 x=307 y=89 width=16 height=10 xoffset=0 yoffset=6 xadvance=16 page=0 chnl=15 +char id=12456 x=325 y=89 width=16 height=13 xoffset=0 yoffset=3 xadvance=16 page=0 chnl=15 +char id=12457 x=343 y=89 width=16 height=12 xoffset=0 yoffset=5 xadvance=16 page=0 chnl=15 +char id=12458 x=361 y=89 width=16 height=14 xoffset=0 yoffset=2 xadvance=16 page=0 chnl=15 +char id=12459 x=379 y=89 width=16 height=15 xoffset=0 yoffset=2 xadvance=16 page=0 chnl=15 +char id=12460 x=397 y=89 width=16 height=16 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=12461 x=415 y=89 width=16 height=14 xoffset=0 yoffset=2 xadvance=16 page=0 chnl=15 +char id=12462 x=433 y=89 width=16 height=15 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=12463 x=451 y=89 width=16 height=16 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=12464 x=469 y=89 width=16 height=16 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=12465 x=487 y=89 width=16 height=16 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=12466 x=1 y=107 width=16 height=16 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=12467 x=19 y=107 width=16 height=13 xoffset=0 yoffset=3 xadvance=16 page=0 chnl=15 +char id=12468 x=37 y=107 width=16 height=17 xoffset=0 yoffset=0 xadvance=16 page=0 chnl=15 +char id=12469 x=55 y=107 width=16 height=15 xoffset=0 yoffset=2 xadvance=16 page=0 chnl=15 +char id=12470 x=73 y=107 width=16 height=16 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=12471 x=91 y=107 width=16 height=13 xoffset=0 yoffset=3 xadvance=16 page=0 chnl=15 +char id=12472 x=109 y=107 width=16 height=14 xoffset=0 yoffset=2 xadvance=16 page=0 chnl=15 +char id=12473 x=127 y=107 width=16 height=13 xoffset=0 yoffset=3 xadvance=16 page=0 chnl=15 +char id=12474 x=145 y=107 width=16 height=16 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=12475 x=163 y=107 width=16 height=14 xoffset=0 yoffset=2 xadvance=16 page=0 chnl=15 +char id=12476 x=181 y=107 width=16 height=15 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=12477 x=199 y=107 width=16 height=13 xoffset=0 yoffset=3 xadvance=16 page=0 chnl=15 +char id=12478 x=217 y=107 width=16 height=15 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=12479 x=235 y=107 width=16 height=16 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=12480 x=253 y=107 width=16 height=16 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=12481 x=271 y=107 width=16 height=15 xoffset=0 yoffset=2 xadvance=16 page=0 chnl=15 +char id=12482 x=289 y=107 width=16 height=15 xoffset=0 yoffset=2 xadvance=16 page=0 chnl=15 +char id=12483 x=307 y=107 width=16 height=11 xoffset=0 yoffset=6 xadvance=16 page=0 chnl=15 +char id=12484 x=325 y=107 width=16 height=13 xoffset=0 yoffset=3 xadvance=16 page=0 chnl=15 +char id=12485 x=343 y=107 width=16 height=15 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=12486 x=361 y=107 width=16 height=15 xoffset=0 yoffset=2 xadvance=16 page=0 chnl=15 +char id=12487 x=379 y=107 width=16 height=17 xoffset=0 yoffset=0 xadvance=16 page=0 chnl=15 +char id=12488 x=397 y=107 width=16 height=13 xoffset=0 yoffset=3 xadvance=16 page=0 chnl=15 +char id=12489 x=415 y=107 width=16 height=13 xoffset=0 yoffset=3 xadvance=16 page=0 chnl=15 +char id=12490 x=433 y=107 width=16 height=15 xoffset=0 yoffset=2 xadvance=16 page=0 chnl=15 +char id=12491 x=451 y=107 width=16 height=11 xoffset=0 yoffset=4 xadvance=16 page=0 chnl=15 +char id=12492 x=469 y=107 width=16 height=14 xoffset=0 yoffset=3 xadvance=16 page=0 chnl=15 +char id=12493 x=487 y=107 width=16 height=16 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=12494 x=1 y=126 width=16 height=13 xoffset=0 yoffset=3 xadvance=16 page=0 chnl=15 +char id=12495 x=19 y=126 width=16 height=12 xoffset=0 yoffset=3 xadvance=16 page=0 chnl=15 +char id=12496 x=37 y=126 width=16 height=14 xoffset=0 yoffset=2 xadvance=16 page=0 chnl=15 +char id=12497 x=55 y=126 width=16 height=14 xoffset=0 yoffset=2 xadvance=16 page=0 chnl=15 +char id=12498 x=73 y=126 width=16 height=14 xoffset=0 yoffset=2 xadvance=16 page=0 chnl=15 +char id=12499 x=91 y=126 width=16 height=15 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=12500 x=109 y=126 width=16 height=14 xoffset=0 yoffset=2 xadvance=16 page=0 chnl=15 +char id=12501 x=127 y=126 width=16 height=13 xoffset=0 yoffset=3 xadvance=16 page=0 chnl=15 +char id=12502 x=145 y=126 width=16 height=17 xoffset=0 yoffset=0 xadvance=16 page=0 chnl=15 +char id=12503 x=163 y=126 width=16 height=16 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=12504 x=181 y=126 width=16 height=11 xoffset=0 yoffset=4 xadvance=16 page=0 chnl=15 +char id=12505 x=199 y=126 width=16 height=12 xoffset=0 yoffset=3 xadvance=16 page=0 chnl=15 +char id=12506 x=217 y=126 width=16 height=12 xoffset=0 yoffset=3 xadvance=16 page=0 chnl=15 +char id=12507 x=235 y=126 width=16 height=14 xoffset=0 yoffset=2 xadvance=16 page=0 chnl=15 +char id=12508 x=253 y=126 width=16 height=16 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=12509 x=271 y=126 width=16 height=16 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=12510 x=289 y=126 width=16 height=14 xoffset=0 yoffset=3 xadvance=16 page=0 chnl=15 +char id=12511 x=307 y=126 width=16 height=13 xoffset=0 yoffset=3 xadvance=16 page=0 chnl=15 +char id=12512 x=325 y=126 width=16 height=14 xoffset=0 yoffset=2 xadvance=16 page=0 chnl=15 +char id=12513 x=343 y=126 width=16 height=13 xoffset=0 yoffset=3 xadvance=16 page=0 chnl=15 +char id=12514 x=361 y=126 width=16 height=13 xoffset=0 yoffset=3 xadvance=16 page=0 chnl=15 +char id=12515 x=379 y=126 width=16 height=12 xoffset=0 yoffset=5 xadvance=16 page=0 chnl=15 +char id=12516 x=397 y=126 width=16 height=14 xoffset=0 yoffset=2 xadvance=16 page=0 chnl=15 +char id=12517 x=415 y=126 width=16 height=10 xoffset=0 yoffset=6 xadvance=16 page=0 chnl=15 +char id=12518 x=433 y=126 width=16 height=12 xoffset=0 yoffset=3 xadvance=16 page=0 chnl=15 +char id=12519 x=451 y=126 width=16 height=12 xoffset=0 yoffset=5 xadvance=16 page=0 chnl=15 +char id=12520 x=469 y=126 width=16 height=13 xoffset=0 yoffset=3 xadvance=16 page=0 chnl=15 +char id=12521 x=487 y=126 width=16 height=15 xoffset=0 yoffset=2 xadvance=16 page=0 chnl=15 +char id=12522 x=1 y=145 width=16 height=13 xoffset=0 yoffset=3 xadvance=16 page=0 chnl=15 +char id=12523 x=19 y=145 width=16 height=13 xoffset=0 yoffset=3 xadvance=16 page=0 chnl=15 +char id=12524 x=37 y=145 width=16 height=13 xoffset=0 yoffset=3 xadvance=16 page=0 chnl=15 +char id=12525 x=55 y=145 width=16 height=13 xoffset=0 yoffset=3 xadvance=16 page=0 chnl=15 +char id=12526 x=73 y=145 width=16 height=12 xoffset=0 yoffset=5 xadvance=16 page=0 chnl=15 +char id=12527 x=91 y=145 width=16 height=14 xoffset=0 yoffset=3 xadvance=16 page=0 chnl=15 +char id=12528 x=109 y=145 width=16 height=14 xoffset=0 yoffset=2 xadvance=16 page=0 chnl=15 +char id=12529 x=127 y=145 width=16 height=13 xoffset=0 yoffset=3 xadvance=16 page=0 chnl=15 +char id=12530 x=145 y=145 width=16 height=14 xoffset=0 yoffset=3 xadvance=16 page=0 chnl=15 +char id=12531 x=163 y=145 width=16 height=13 xoffset=0 yoffset=3 xadvance=16 page=0 chnl=15 +char id=12532 x=181 y=145 width=16 height=16 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=12533 x=199 y=145 width=16 height=12 xoffset=0 yoffset=5 xadvance=16 page=0 chnl=15 +char id=12534 x=217 y=145 width=16 height=12 xoffset=0 yoffset=5 xadvance=16 page=0 chnl=15 +char id=12535 x=235 y=145 width=16 height=17 xoffset=0 yoffset=0 xadvance=16 page=0 chnl=15 +char id=12536 x=253 y=145 width=16 height=16 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=12537 x=271 y=145 width=16 height=15 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=12538 x=289 y=145 width=16 height=17 xoffset=0 yoffset=0 xadvance=16 page=0 chnl=15 +char id=12540 x=307 y=145 width=16 height=8 xoffset=0 yoffset=7 xadvance=16 page=0 chnl=15 +char id=12541 x=325 y=145 width=16 height=9 xoffset=0 yoffset=6 xadvance=16 page=0 chnl=15 +char id=12542 x=343 y=145 width=16 height=12 xoffset=0 yoffset=3 xadvance=16 page=0 chnl=15 +char id=12289 x=361 y=145 width=16 height=5 xoffset=0 yoffset=12 xadvance=16 page=0 chnl=15 +char id=12290 x=379 y=145 width=16 height=6 xoffset=0 yoffset=11 xadvance=16 page=0 chnl=15 +char id=12539 x=397 y=145 width=16 height=8 xoffset=0 yoffset=7 xadvance=16 page=0 chnl=15 +char id=12300 x=415 y=145 width=16 height=14 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=12301 x=433 y=145 width=16 height=12 xoffset=0 yoffset=5 xadvance=16 page=0 chnl=15 +char id=12302 x=451 y=145 width=16 height=14 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=12303 x=469 y=145 width=16 height=12 xoffset=0 yoffset=5 xadvance=16 page=0 chnl=15 +char id=65288 x=487 y=145 width=16 height=16 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=65289 x=1 y=164 width=16 height=16 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=12304 x=19 y=164 width=16 height=15 xoffset=0 yoffset=2 xadvance=16 page=0 chnl=15 +char id=12305 x=37 y=164 width=16 height=15 xoffset=0 yoffset=2 xadvance=16 page=0 chnl=15 +char id=12316 x=55 y=164 width=16 height=9 xoffset=0 yoffset=6 xadvance=16 page=0 chnl=15 +char id=8230 x=73 y=164 width=16 height=7 xoffset=0 yoffset=8 xadvance=16 page=0 chnl=15 +char id=65281 x=91 y=164 width=16 height=14 xoffset=0 yoffset=2 xadvance=16 page=0 chnl=15 +char id=65311 x=109 y=164 width=16 height=14 xoffset=0 yoffset=2 xadvance=16 page=0 chnl=15 +char id=65306 x=127 y=164 width=16 height=12 xoffset=0 yoffset=3 xadvance=16 page=0 chnl=15 +char id=65291 x=145 y=164 width=16 height=13 xoffset=0 yoffset=3 xadvance=16 page=0 chnl=15 +char id=65293 x=163 y=164 width=16 height=7 xoffset=0 yoffset=8 xadvance=16 page=0 chnl=15 +char id=215 x=181 y=164 width=10 height=9 xoffset=0 yoffset=6 xadvance=10 page=0 chnl=15 +char id=247 x=193 y=164 width=10 height=8 xoffset=0 yoffset=7 xadvance=10 page=0 chnl=15 +char id=65309 x=205 y=164 width=16 height=9 xoffset=0 yoffset=6 xadvance=16 page=0 chnl=15 +char id=65285 x=223 y=164 width=16 height=12 xoffset=0 yoffset=3 xadvance=16 page=0 chnl=15 +char id=65286 x=241 y=164 width=16 height=15 xoffset=0 yoffset=2 xadvance=16 page=0 chnl=15 +char id=65283 x=259 y=164 width=16 height=14 xoffset=0 yoffset=2 xadvance=16 page=0 chnl=15 +char id=65290 x=277 y=164 width=16 height=13 xoffset=0 yoffset=3 xadvance=16 page=0 chnl=15 +char id=12288 x=295 y=164 width=0 height=0 xoffset=0 yoffset=15 xadvance=16 page=0 chnl=15 +char id=38283 x=297 y=164 width=16 height=16 xoffset=0 yoffset=2 xadvance=16 page=0 chnl=15 +char id=22987 x=315 y=164 width=16 height=16 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=32066 x=333 y=164 width=16 height=16 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=20102 x=351 y=164 width=16 height=15 xoffset=0 yoffset=2 xadvance=16 page=0 chnl=15 +char id=19968 x=369 y=164 width=16 height=7 xoffset=0 yoffset=8 xadvance=16 page=0 chnl=15 +char id=26178 x=387 y=164 width=16 height=16 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=20572 x=405 y=164 width=16 height=16 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=27490 x=423 y=164 width=16 height=15 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=20877 x=441 y=164 width=16 height=16 xoffset=0 yoffset=2 xadvance=16 page=0 chnl=15 +char id=32154 x=459 y=164 width=16 height=16 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=34892 x=477 y=164 width=16 height=17 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=24471 x=495 y=164 width=16 height=16 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=28857 x=1 y=183 width=16 height=16 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=26368 x=19 y=183 width=16 height=15 xoffset=0 yoffset=2 xadvance=16 page=0 chnl=15 +char id=39640 x=37 y=183 width=16 height=17 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=27531 x=55 y=183 width=16 height=17 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=27231 x=73 y=183 width=16 height=16 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=20307 x=91 y=183 width=16 height=16 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=21147 x=109 y=183 width=16 height=17 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=21629 x=127 y=183 width=16 height=16 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=21213 x=145 y=183 width=16 height=17 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=21033 x=163 y=183 width=16 height=16 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=25943 x=181 y=183 width=16 height=16 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=21271 x=199 y=183 width=16 height=16 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=24341 x=217 y=183 width=16 height=17 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=20998 x=235 y=183 width=16 height=17 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=27425 x=253 y=183 width=16 height=16 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=38754 x=271 y=183 width=16 height=15 xoffset=0 yoffset=2 xadvance=16 page=0 chnl=15 +char id=25147 x=289 y=183 width=16 height=15 xoffset=0 yoffset=2 xadvance=16 page=0 chnl=15 +char id=36984 x=307 y=183 width=16 height=16 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=25246 x=325 y=183 width=16 height=17 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=27770 x=343 y=183 width=16 height=16 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=23450 x=361 y=183 width=16 height=16 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=35373 x=379 y=183 width=16 height=16 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=38899 x=397 y=183 width=16 height=16 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=37327 x=415 y=183 width=16 height=14 xoffset=0 yoffset=2 xadvance=16 page=0 chnl=15 +char id=36895 x=433 y=183 width=16 height=16 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=24230 x=451 y=183 width=16 height=16 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=38291 x=469 y=183 width=16 height=16 xoffset=0 yoffset=2 xadvance=16 page=0 chnl=15 +char id=31186 x=487 y=183 width=16 height=16 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=22238 x=1 y=202 width=16 height=15 xoffset=0 yoffset=2 xadvance=16 page=0 chnl=15 +char id=20154 x=19 y=202 width=16 height=15 xoffset=0 yoffset=2 xadvance=16 page=0 chnl=15 +char id=25973 x=37 y=202 width=16 height=17 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=21619 x=55 y=202 width=16 height=16 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=26041 x=73 y=202 width=16 height=17 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=23453 x=91 y=202 width=16 height=16 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=31665 x=109 y=202 width=16 height=16 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=37749 x=127 y=202 width=16 height=16 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=25161 x=145 y=202 width=16 height=15 xoffset=0 yoffset=2 xadvance=16 page=0 chnl=15 +char id=26449 x=163 y=202 width=16 height=16 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=30010 x=181 y=202 width=16 height=15 xoffset=0 yoffset=2 xadvance=16 page=0 chnl=15 +char id=26862 x=199 y=202 width=16 height=16 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=36947 x=217 y=202 width=16 height=16 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=22478 x=235 y=202 width=16 height=17 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=29579 x=253 y=202 width=16 height=14 xoffset=0 yoffset=2 xadvance=16 page=0 chnl=15 +char id=23019 x=271 y=202 width=16 height=16 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=21191 x=289 y=202 width=16 height=17 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=32773 x=307 y=202 width=16 height=16 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=21091 x=325 y=202 width=16 height=17 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=30462 x=343 y=202 width=16 height=16 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=24339 x=361 y=202 width=16 height=16 xoffset=0 yoffset=2 xadvance=16 page=0 chnl=15 +char id=30690 x=379 y=202 width=16 height=16 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=34220 x=397 y=202 width=16 height=16 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=33609 x=415 y=202 width=16 height=16 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=37329 x=433 y=202 width=16 height=16 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=37504 x=451 y=202 width=16 height=16 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=37509 x=469 y=202 width=16 height=17 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=30707 x=487 y=202 width=16 height=15 xoffset=0 yoffset=2 xadvance=16 page=0 chnl=15 +char id=26408 x=1 y=221 width=16 height=16 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=27700 x=19 y=221 width=16 height=16 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=28779 x=37 y=221 width=16 height=15 xoffset=0 yoffset=2 xadvance=16 page=0 chnl=15 +char id=39080 x=55 y=221 width=16 height=16 xoffset=0 yoffset=2 xadvance=16 page=0 chnl=15 +char id=22303 x=73 y=221 width=16 height=15 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=20809 x=91 y=221 width=16 height=17 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=38343 x=109 y=221 width=16 height=16 xoffset=0 yoffset=2 xadvance=16 page=0 chnl=15 +char id=25915 x=127 y=221 width=16 height=16 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=25731 x=145 y=221 width=16 height=16 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=38450 x=163 y=221 width=16 height=17 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=24481 x=181 y=221 width=16 height=16 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=39764 x=199 y=221 width=16 height=16 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=27861 x=217 y=221 width=16 height=16 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=25216 x=235 y=221 width=16 height=17 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=24517 x=253 y=221 width=16 height=16 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=27578 x=271 y=221 width=16 height=16 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=24489 x=289 y=221 width=16 height=16 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=27602 x=307 y=221 width=16 height=16 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=30496 x=325 y=221 width=16 height=15 xoffset=0 yoffset=2 xadvance=16 page=0 chnl=15 +char id=27494 x=343 y=221 width=16 height=16 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=22120 x=361 y=221 width=16 height=15 xoffset=0 yoffset=2 xadvance=16 page=0 chnl=15 +char id=20855 x=379 y=221 width=16 height=15 xoffset=0 yoffset=2 xadvance=16 page=0 chnl=15 +char id=25345 x=397 y=221 width=16 height=17 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=29289 x=415 y=221 width=16 height=17 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=35013 x=433 y=221 width=16 height=16 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=20633 x=451 y=221 width=16 height=16 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=36023 x=469 y=221 width=16 height=15 xoffset=0 yoffset=2 xadvance=16 page=0 chnl=15 +char id=22770 x=487 y=221 width=16 height=16 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=24215 x=1 y=240 width=16 height=16 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=23487 x=19 y=240 width=16 height=16 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=23627 x=37 y=240 width=16 height=15 xoffset=0 yoffset=2 xadvance=16 page=0 chnl=15 +char id=35441 x=55 y=240 width=16 height=16 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=32862 x=73 y=240 width=16 height=16 xoffset=0 yoffset=2 xadvance=16 page=0 chnl=15 +char id=35211 x=91 y=240 width=16 height=17 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=26469 x=109 y=240 width=16 height=16 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=20837 x=127 y=240 width=16 height=15 xoffset=0 yoffset=2 xadvance=16 page=0 chnl=15 +char id=20986 x=145 y=240 width=16 height=16 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=19978 x=163 y=240 width=16 height=15 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=19979 x=181 y=240 width=16 height=15 xoffset=0 yoffset=2 xadvance=16 page=0 chnl=15 +char id=24038 x=199 y=240 width=16 height=16 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=21491 x=217 y=240 width=16 height=16 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=21069 x=235 y=240 width=16 height=17 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=24460 x=253 y=240 width=16 height=16 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=26481 x=271 y=240 width=16 height=16 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=35199 x=289 y=240 width=16 height=15 xoffset=0 yoffset=2 xadvance=16 page=0 chnl=15 +char id=21335 x=307 y=240 width=16 height=16 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=25276 x=325 y=240 width=16 height=17 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=38626 x=343 y=240 width=16 height=16 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=25163 x=361 y=240 width=16 height=17 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=36275 x=379 y=240 width=16 height=15 xoffset=0 yoffset=2 xadvance=16 page=0 chnl=15 +char id=38957 x=397 y=240 width=16 height=15 xoffset=0 yoffset=2 xadvance=16 page=0 chnl=15 +char id=30446 x=415 y=240 width=16 height=15 xoffset=0 yoffset=2 xadvance=16 page=0 chnl=15 +char id=21475 x=433 y=240 width=16 height=14 xoffset=0 yoffset=3 xadvance=16 page=0 chnl=15 +char id=32819 x=451 y=240 width=16 height=15 xoffset=0 yoffset=2 xadvance=16 page=0 chnl=15 +char id=24515 x=469 y=240 width=16 height=16 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=27671 x=487 y=240 width=16 height=17 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=20803 x=1 y=259 width=16 height=15 xoffset=0 yoffset=2 xadvance=16 page=0 chnl=15 +char id=22825 x=19 y=259 width=16 height=15 xoffset=0 yoffset=2 xadvance=16 page=0 chnl=15 +char id=22320 x=37 y=259 width=16 height=16 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=23665 x=55 y=259 width=16 height=16 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=24029 x=73 y=259 width=16 height=15 xoffset=0 yoffset=2 xadvance=16 page=0 chnl=15 +char id=28023 x=91 y=259 width=16 height=16 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=31354 x=109 y=259 width=16 height=16 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=26143 x=127 y=259 width=16 height=15 xoffset=0 yoffset=2 xadvance=16 page=0 chnl=15 +char id=26376 x=145 y=259 width=16 height=16 xoffset=0 yoffset=2 xadvance=16 page=0 chnl=15 +char id=26085 x=163 y=259 width=16 height=15 xoffset=0 yoffset=2 xadvance=16 page=0 chnl=15 +char id=24180 x=181 y=259 width=16 height=16 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=20170 x=199 y=259 width=16 height=16 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=26397 x=217 y=259 width=16 height=17 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=26172 x=235 y=259 width=16 height=16 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=22812 x=253 y=259 width=16 height=16 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=36196 x=271 y=259 width=16 height=17 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=38738 x=289 y=259 width=16 height=17 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=40644 x=307 y=259 width=16 height=16 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=32209 x=325 y=259 width=16 height=16 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=30333 x=343 y=259 width=16 height=16 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=40658 x=361 y=259 width=16 height=15 xoffset=0 yoffset=2 xadvance=16 page=0 chnl=15 +char id=33394 x=379 y=259 width=16 height=16 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=22823 x=397 y=259 width=16 height=16 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=23567 x=415 y=259 width=16 height=17 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=20302 x=433 y=259 width=16 height=16 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=38263 x=451 y=259 width=16 height=16 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=30701 x=469 y=259 width=16 height=16 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=26032 x=487 y=259 width=16 height=16 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=21476 x=1 y=278 width=16 height=16 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=22810 x=19 y=278 width=16 height=16 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=23569 x=37 y=278 width=16 height=16 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=26089 x=55 y=278 width=16 height=15 xoffset=0 yoffset=2 xadvance=16 page=0 chnl=15 +char id=36933 x=73 y=278 width=16 height=16 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=24375 x=91 y=278 width=16 height=17 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=24369 x=109 y=278 width=16 height=17 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=37325 x=127 y=278 width=16 height=15 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=36605 x=145 y=278 width=16 height=16 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=33391 x=163 y=278 width=16 height=16 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=24746 x=181 y=278 width=16 height=16 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=27491 x=199 y=278 width=16 height=14 xoffset=0 yoffset=2 xadvance=16 page=0 chnl=15 +char id=20840 x=217 y=278 width=16 height=16 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=37096 x=235 y=278 width=16 height=16 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=21322 x=253 y=278 width=16 height=16 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=25968 x=271 y=278 width=16 height=16 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=23383 x=289 y=278 width=16 height=16 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=25991 x=307 y=278 width=16 height=16 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=35501 x=325 y=278 width=16 height=16 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=26360 x=343 y=278 width=16 height=16 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=35328 x=361 y=278 width=16 height=15 xoffset=0 yoffset=2 xadvance=16 page=0 chnl=15 +char id=35486 x=379 y=278 width=16 height=15 xoffset=0 yoffset=2 xadvance=16 page=0 chnl=15 +char id=33521 x=397 y=278 width=16 height=16 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=26412 x=415 y=278 width=16 height=16 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=20013 x=433 y=278 width=16 height=16 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=22269 x=451 y=278 width=16 height=15 xoffset=0 yoffset=2 xadvance=16 page=0 chnl=15 +char id=21517 x=469 y=278 width=16 height=16 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=30058 x=487 y=278 width=16 height=16 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=21495 x=1 y=297 width=16 height=17 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=31532 x=19 y=297 width=16 height=16 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=31456 x=37 y=297 width=16 height=16 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=35352 x=55 y=297 width=16 height=15 xoffset=0 yoffset=2 xadvance=16 page=0 chnl=15 +char id=37682 x=73 y=297 width=16 height=16 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=20445 x=91 y=297 width=16 height=16 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=23384 x=109 y=297 width=16 height=16 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=36796 x=127 y=297 width=16 height=16 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=21066 x=145 y=297 width=16 height=16 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=38500 x=163 y=297 width=16 height=16 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=30011 x=181 y=297 width=16 height=15 xoffset=0 yoffset=2 xadvance=16 page=0 chnl=15 +char id=34920 x=199 y=297 width=16 height=16 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=31034 x=217 y=297 width=16 height=15 xoffset=0 yoffset=2 xadvance=16 page=0 chnl=15 +char id=25805 x=235 y=297 width=16 height=17 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=20316 x=253 y=297 width=16 height=16 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=35500 x=271 y=297 width=16 height=16 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=26126 x=289 y=297 width=16 height=16 xoffset=0 yoffset=2 xadvance=16 page=0 chnl=15 +char id=36938 x=307 y=297 width=16 height=16 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=38627 x=325 y=297 width=16 height=16 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=26131 x=343 y=297 width=16 height=16 xoffset=0 yoffset=2 xadvance=16 page=0 chnl=15 +char id=26222 x=361 y=297 width=16 height=16 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=36890 x=379 y=297 width=16 height=16 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=31777 x=397 y=297 width=16 height=17 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=21336 x=415 y=297 width=16 height=16 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=32244 x=433 y=297 width=16 height=16 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=32722 x=451 y=297 width=16 height=15 xoffset=0 yoffset=2 xadvance=16 page=0 chnl=15 +char id=23550 x=469 y=297 width=16 height=16 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=25126 x=487 y=297 width=16 height=17 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=35430 x=1 y=316 width=16 height=17 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=21512 x=19 y=316 width=16 height=16 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=36000 x=37 y=316 width=16 height=16 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=28310 x=55 y=316 width=16 height=16 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=23436 x=73 y=316 width=16 height=16 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=25104 x=91 y=316 width=16 height=17 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=21151 x=109 y=316 width=16 height=17 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=22833 x=127 y=316 width=16 height=16 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=24565 x=145 y=316 width=16 height=16 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=27515 x=163 y=316 width=16 height=16 xoffset=0 yoffset=2 xadvance=16 page=0 chnl=15 +char id=29983 x=181 y=316 width=16 height=16 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=30772 x=199 y=316 width=16 height=16 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=20498 x=217 y=316 width=16 height=16 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=24618 x=235 y=316 width=16 height=16 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=20027 x=253 y=316 width=16 height=16 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=20844 x=271 y=316 width=16 height=16 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=20210 x=289 y=316 width=16 height=16 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=26053 x=307 y=316 width=16 height=17 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=20882 x=325 y=316 width=16 height=15 xoffset=0 yoffset=2 xadvance=16 page=0 chnl=15 +char id=38522 x=343 y=316 width=16 height=16 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=19990 x=361 y=316 width=16 height=16 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=30028 x=379 y=316 width=16 height=16 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=22259 x=397 y=316 width=16 height=15 xoffset=0 yoffset=2 xadvance=16 page=0 chnl=15 +char id=37489 x=415 y=316 width=16 height=16 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=27934 x=433 y=316 width=16 height=16 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=31391 x=451 y=316 width=16 height=16 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=22612 x=469 y=316 width=16 height=16 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=38272 x=487 y=316 width=16 height=16 xoffset=0 yoffset=2 xadvance=16 page=0 chnl=15 +char id=27211 x=1 y=335 width=16 height=17 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=23478 x=19 y=335 width=16 height=17 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=23460 x=37 y=335 width=16 height=16 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=38542 x=55 y=335 width=16 height=16 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=27573 x=73 y=335 width=16 height=16 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=31348 x=91 y=335 width=16 height=16 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=33853 x=109 y=335 width=16 height=16 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=25342 x=127 y=335 width=16 height=16 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=20351 x=145 y=335 width=16 height=16 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=25448 x=163 y=335 width=16 height=17 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=21463 x=181 y=335 width=16 height=16 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=28193 x=199 y=335 width=16 height=16 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=25506 x=217 y=335 width=16 height=17 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=35519 x=235 y=335 width=16 height=17 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=38598 x=253 y=335 width=16 height=16 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=24403 x=271 y=335 width=16 height=16 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=31227 x=289 y=335 width=16 height=16 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=21205 x=307 y=335 width=16 height=17 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=36208 x=325 y=335 width=16 height=16 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=32937 x=343 y=335 width=16 height=15 xoffset=0 yoffset=2 xadvance=16 page=0 chnl=15 +char id=36339 x=361 y=335 width=16 height=16 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=24382 x=379 y=335 width=16 height=17 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=22635 x=397 y=335 width=16 height=16 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=19977 x=415 y=335 width=16 height=14 xoffset=0 yoffset=2 xadvance=16 page=0 chnl=15 +char id=31216 x=433 y=335 width=16 height=16 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=20219 x=451 y=335 width=16 height=16 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=21209 x=469 y=335 width=16 height=17 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=29575 x=487 y=335 width=16 height=16 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=29031 x=1 y=354 width=16 height=16 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=29401 x=19 y=354 width=16 height=16 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=23556 x=37 y=354 width=16 height=17 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=37507 x=55 y=354 width=16 height=17 xoffset=0 yoffset=1 xadvance=16 page=0 chnl=15 +char id=38360 x=73 y=354 width=16 height=16 xoffset=0 yoffset=2 xadvance=16 page=0 chnl=15 diff --git a/games/tps/assets/fonts/mono16.png b/games/tps/assets/fonts/mono16.png new file mode 100644 index 0000000..c082c30 Binary files /dev/null and b/games/tps/assets/fonts/mono16.png differ diff --git a/games/tps/assets/levels/arena.level b/games/tps/assets/levels/arena.level new file mode 100644 index 0000000..ebd13bb --- /dev/null +++ b/games/tps/assets/levels/arena.level @@ -0,0 +1,87 @@ +# arena.level — the TPS level (chapter 36). Units: metres, +Y up, north = -Z. yaw in degrees (multiples of 90). +# Commands (one per line, # starts a comment): +# model [noshadow] [nocollide] [vary=N] a piece type (one GLB, drawn instanced) +# box x0 y0 z0 x1 y1 z1 collision box in the piece's model space (any number; default = its bounds) +# solid x0 y0 z0 x1 y1 z1 an invisible world-space collision box +# place x y z yaw one piece +# row x y z yaw dx dz count count pieces, (dx, dz) apart +# grid x y z yaw step nx nz nx × nz pieces, step apart +# spawn x y z yaw the player's start (yaw 0 = facing north, -Z) + +model floor games/tps/assets/models/floor_tile.glb noshadow nocollide vary=0.06 +model wall games/tps/assets/models/wall.glb vary=0.05 +model cover games/tps/assets/models/cover.glb +model pillar games/tps/assets/models/pillar.glb +model platform games/tps/assets/models/platform.glb +model stairs games/tps/assets/models/stairs.glb +model crate assets/models/crate.glb vary=0.12 +model barrel assets/models/barrel.glb + +# 階段:段ごとの箱(モデルを作った時に表示した値) / the stairs: one box per step (printed when the model was made) +box stairs -1 0 -1.5 1 0.25 1.5 +box stairs -1 0 -1.5 1 0.5 1 +box stairs -1 0 -1.5 1 0.75 0.5 +box stairs -1 0 -1.5 1 1 0 +box stairs -1 0 -1.5 1 1.25 -0.5 +box stairs -1 0 -1.5 1 1.5 -1 + +# 床:8 × 8枚の4 mタイル(当たり判定は1枚の厚い箱:薄い箱は落ちる速さですり抜ける) +# floor: 8 × 8 tiles of 4 m (collision is one thick box: thin boxes can be tunnelled at falling speed) +grid floor -14 0 -14 0 4 8 8 +solid -16 -1 -16 16 0 16 + +# 外壁(高さ3 m)と四隅の柱 / outer walls (3 m high) and corner pillars +row wall -14 0 -16.2 0 4 0 8 +row wall -14 0 16.2 0 4 0 8 +row wall -16.2 0 -14 90 0 4 8 +row wall 16.2 0 -14 90 0 4 8 +place pillar -16.2 0 -16.2 0 +place pillar 16.2 0 -16.2 0 +place pillar -16.2 0 16.2 0 +place pillar 16.2 0 16.2 0 + +# 中央の台(4 × 8 m、高さ1.5 m)と両端の階段 / the central platform (4 × 8 m, 1.5 m high) with stairs at both ends +place platform 0 0 -2 0 +place platform 0 0 2 0 +place stairs 0 0 5.5 0 +place stairs 0 0 -5.5 180 +place pillar -3.2 0 -5 0 +place pillar 3.2 0 -5 0 +place pillar -3.2 0 5 0 +place pillar 3.2 0 5 0 + +# 西と東の壁(L字の遮蔽) / west and east walls (L-shaped cover) +row wall -9 0 -8 90 0 4 2 +place wall -11 0 -10.2 0 +row wall 9 0 4 90 0 4 2 +place wall 11 0 10.2 0 +place pillar -9 0 -10.2 0 +place pillar 9 0 10.2 0 + +# 低い遮蔽 / low cover +place cover -5 0 9.5 0 +place cover 5.5 0 10 0 +place cover -12 0 2 90 +place cover 12 0 -2 90 +place cover -5 0 -11 0 +place cover 5 0 -10.5 0 +place cover 0 0 -13 0 + +# 箱と樽(共有のassets/models) / crates and barrels (the shared assets/models) +place crate -13.5 0 13.5 0 +place crate -12.4 0 13.6 90 +place crate -13.4 0 12.4 0 +place crate -13.4 1 13.4 90 +place crate 12.5 0 -13.5 0 +place crate 13.6 0 -13.4 0 +place crate 13.5 0 -12.3 90 +place crate 6 0 0 0 +place crate -6.5 0 -1 0 +place barrel 13.2 0 13 0 +place barrel 12.4 0 13.5 90 +place barrel 13.4 0 12.1 180 +place barrel -13 0 -13.2 0 +place barrel -12.2 0 -13.6 90 +place barrel 6.9 0 0.3 0 + +spawn 0 0 11.5 0 diff --git a/games/tps/assets/levels/pieces.level b/games/tps/assets/levels/pieces.level new file mode 100644 index 0000000..41d4715 --- /dev/null +++ b/games/tps/assets/levels/pieces.level @@ -0,0 +1,19 @@ +# pieces.level — every level piece in a row, for looking at them (./build/games/tps/tps games/tps/assets/levels/pieces.level) +model floor games/tps/assets/models/floor_tile.glb noshadow nocollide +model wall games/tps/assets/models/wall.glb +model cover games/tps/assets/models/cover.glb +model pillar games/tps/assets/models/pillar.glb +model platform games/tps/assets/models/platform.glb +model stairs games/tps/assets/models/stairs.glb +model crate assets/models/crate.glb +model barrel assets/models/barrel.glb +grid floor -10 0 -6 0 4 6 4 +solid -12 -1 -8 12 0 8 +place wall -9 0 -4 0 +place cover -4.5 0 -3 0 +place pillar -1.5 0 -3.5 0 +place platform 2.5 0 -4 0 +place stairs 2.5 0 -0.5 0 +place crate 6.5 0 -3 0 +place barrel 8 0 -3 0 +spawn 0 0 4 0 diff --git a/games/tps/assets/models/cover.glb b/games/tps/assets/models/cover.glb new file mode 100644 index 0000000..7d49ba4 Binary files /dev/null and b/games/tps/assets/models/cover.glb differ diff --git a/games/tps/assets/models/floor_tile.glb b/games/tps/assets/models/floor_tile.glb new file mode 100644 index 0000000..6c70e28 Binary files /dev/null and b/games/tps/assets/models/floor_tile.glb differ diff --git a/games/tps/assets/models/pillar.glb b/games/tps/assets/models/pillar.glb new file mode 100644 index 0000000..cbae5fc Binary files /dev/null and b/games/tps/assets/models/pillar.glb differ diff --git a/games/tps/assets/models/platform.glb b/games/tps/assets/models/platform.glb new file mode 100644 index 0000000..ead23b6 Binary files /dev/null and b/games/tps/assets/models/platform.glb differ diff --git a/games/tps/assets/models/player.glb b/games/tps/assets/models/player.glb new file mode 100644 index 0000000..4090ff8 Binary files /dev/null and b/games/tps/assets/models/player.glb differ diff --git a/games/tps/assets/models/rifle.glb b/games/tps/assets/models/rifle.glb new file mode 100644 index 0000000..9433011 Binary files /dev/null and b/games/tps/assets/models/rifle.glb differ diff --git a/games/tps/assets/models/stairs.glb b/games/tps/assets/models/stairs.glb new file mode 100644 index 0000000..be4d16a Binary files /dev/null and b/games/tps/assets/models/stairs.glb differ diff --git a/games/tps/assets/models/wall.glb b/games/tps/assets/models/wall.glb new file mode 100644 index 0000000..b08e41b Binary files /dev/null and b/games/tps/assets/models/wall.glb differ diff --git a/games/tps/shaders/instanced.vert b/games/tps/shaders/instanced.vert new file mode 100644 index 0000000..e64bb00 --- /dev/null +++ b/games/tps/shaders/instanced.vert @@ -0,0 +1,43 @@ +#version 460 core +// レベルの部品のインスタンシング(第19章):phong.vertにインスタンスの行列と色を足しただけ(第19章の小惑星の公転なし)。 +// フラグメントシェーダーはエンジンのpbr.frag +// Instancing for the level pieces (chapter 19): phong.vert plus the per-instance matrix and color (without the +// chapter 19 asteroid orbit). Fragment shader: the engine's pbr.frag +layout(location = 0) in vec3 aPosition; +layout(location = 1) in vec3 aNormal; +layout(location = 2) in vec2 aUv; +layout(location = 3) in vec4 aTangent; // 接線(第22章) / tangent (chapter 22) +layout(location = 4) in mat4 aInstanceModel; // 4〜7 / locations 4..7 +layout(location = 8) in vec3 aInstanceColor; // pbr.fragがベースカラーに掛ける / pbr.frag multiplies the base color + +// カメラ(ユニフォームバッファ、結合点0、std140)。使う全部のシェーダーで同じ宣言(C++ではCameraBlock) +// The camera (uniform buffer, binding 0, std140). The same declaration in every shader that uses it (CameraBlock in C++) +layout(std140, binding = 0) uniform Camera { + mat4 uView; + mat4 uProj; + vec3 uViewPos; // カメラの位置(ワールド座標) / camera position (world space) + float uTime; // アニメーションの時間(秒) / animation time (seconds) +}; + +uniform mat4 uModel; // モデルの中のノードの行列 / the node's matrix inside the model +uniform mat3 uNormalMatrix; // その法線行列 / its normal matrix + +out vec3 vWorldPos; +out vec3 vNormal; +out vec2 vUv; +out vec4 vTangent; +out vec3 vTint; + +void main() { + mat4 model = aInstanceModel * uModel; + vec4 world = model * vec4(aPosition, 1.0); + vWorldPos = world.xyz; + // 部品はY軸周りに回すだけ(拡大縮小なし)なので、法線は行列の3×3で回せば良い + // Pieces are only turned about Y (no scaling), so the 3×3 part rotates the normal correctly + vNormal = mat3(aInstanceModel) * (uNormalMatrix * aNormal); + vUv = aUv; + mat3 m = mat3(model); + vTangent = vec4(m * aTangent.xyz, aTangent.w * (determinant(m) < 0.0 ? -1.0 : 1.0)); + vTint = aInstanceColor; + gl_Position = uProj * uView * world; +} diff --git a/games/tps/src/character.cc b/games/tps/src/character.cc new file mode 100644 index 0000000..242a6db --- /dev/null +++ b/games/tps/src/character.cc @@ -0,0 +1,155 @@ +#include "character.hh" + +#include +#include +#include +#include + +std::optional CharacterRig::find(const Model &model) { + CharacterRig rig; + rig.hips = model.findNode("Hips"); + rig.spine = model.findNode("Spine"); + rig.head = model.findNode("Head"); + rig.weapon = model.findNode("Weapon"); + rig.cameraPivot = model.findNode("CameraPivot"); + const char *side[2] = {"L", "R"}; + for (int s = 0; s < 2; ++s) { + rig.leg[s] = model.findNode(std::string("Leg") + side[s]); + rig.knee[s] = model.findNode(std::string("Knee") + side[s]); + rig.shoulder[s] = model.findNode(std::string("Shoulder") + side[s]); + rig.elbow[s] = model.findNode(std::string("Elbow") + side[s]); + rig.hand[s] = model.findNode(std::string("Hand") + side[s]); + } + for (int n : {rig.hips, rig.spine, rig.head, rig.weapon, rig.cameraPivot, rig.leg[0], rig.leg[1], rig.knee[0], + rig.knee[1], rig.shoulder[0], rig.shoulder[1], rig.elbow[0], rig.elbow[1], rig.hand[0], rig.hand[1]}) + if (n < 0) { + fprintf(stderr, "キャラクターの関節が足りない / a character joint is missing\n"); + return std::nullopt; + } + rig.rest = model.nodes; + return rig; +} + +Mat4 characterMatrix(Vec3 position, float heading) { return translate(position) * rotateY(PI - heading); } + +// X軸周りの回転 / rotation about X +static Quat rotX(float a) { return Quat::fromAxisAngle({1.0f, 0.0f, 0.0f}, a); } +static Quat rotY(float a) { return Quat::fromAxisAngle({0.0f, 1.0f, 0.0f}, a); } + +// 回転行列の列(3本の直交する単位ベクトル)からクォータニオンへ / rotation matrix columns (three orthonormal unit +// vectors) → quaternion +static Quat quatFromBasis(Vec3 x, Vec3 y, Vec3 z) { + float m00 = x.x, m01 = y.x, m02 = z.x, m10 = x.y, m11 = y.y, m12 = z.y, m20 = x.z, m21 = y.z, m22 = z.z; + float trace = m00 + m11 + m22; + Quat q; + if (trace > 0.0f) { + float s = 2.0f * std::sqrt(trace + 1.0f); + q = {0.25f * s, (m21 - m12) / s, (m02 - m20) / s, (m10 - m01) / s}; + } else if (m00 > m11 && m00 > m22) { + float s = 2.0f * std::sqrt(1.0f + m00 - m11 - m22); + q = {(m21 - m12) / s, 0.25f * s, (m01 + m10) / s, (m02 + m20) / s}; + } else if (m11 > m22) { + float s = 2.0f * std::sqrt(1.0f + m11 - m00 - m22); + q = {(m02 - m20) / s, (m01 + m10) / s, 0.25f * s, (m12 + m21) / s}; + } else { + float s = 2.0f * std::sqrt(1.0f + m22 - m00 - m11); + q = {(m10 - m01) / s, (m02 + m20) / s, (m12 + m21) / s, 0.25f * s}; + } + return normalize(q); +} + +static Vec3 origin(const Mat4 &m) { return {m.c[3].x, m.c[3].y, m.c[3].z}; } +static Vec3 column(const Mat4 &m, int i) { return {m.c[i].x, m.c[i].y, m.c[i].z}; } +// 回転だけの行列の逆で向きを戻す(転置を掛ける) / undo a pure rotation (multiply by its transpose) +static Vec3 toLocal(const Mat4 &m, Vec3 v) { return {dot(v, column(m, 0)), dot(v, column(m, 1)), dot(v, column(m, 2))}; } + +// 2本の骨のIK:肩から手先をtargetへ届かせる。腕は休みの姿勢で−Yに垂れ、肘は局所X軸の周りに曲がる。 +// poleは肘を向けたい方向(モデル座標)。肩と肘の局所の回転を書く +// Two-bone IK: makes the arm reach target from the shoulder. In the rest pose the arm hangs along −Y and the elbow bends +// about its local X axis. pole = where the elbow should point (model space). Writes the shoulder's and the elbow's local +// rotations +static void solveArm(Model &model, const CharacterRig &rig, int s, Vec3 target, Vec3 pole) { + GltfNode &shoulder = model.nodes[static_cast(rig.shoulder[s])]; + GltfNode &elbow = model.nodes[static_cast(rig.elbow[s])]; + const GltfNode &hand = model.nodes[static_cast(rig.hand[s])]; + Mat4 parent = model.nodeTransform(shoulder.parent); // 背骨(もう姿勢が入っている) / the spine (already posed) + Vec3 p0 = origin(parent * translate(shoulder.translation)); + float l1 = length(elbow.translation), l2 = length(hand.translation); + + // 余弦定理:肩の角A(目標への向きと上腕の間) / law of cosines: the shoulder angle A (between the target direction + // and the upper arm) + Vec3 d = target - p0; + float dist = std::clamp(length(d), std::fabs(l1 - l2) + 0.01f, l1 + l2 - 0.001f); + Vec3 t = normalize(d); + float cosA = std::clamp((l1 * l1 + dist * dist - l2 * l2) / (2.0f * l1 * dist), -1.0f, 1.0f); + // 曲げる平面:目標への向きとpoleで決まる / the bend plane: spanned by the target direction and the pole + Vec3 b = pole - dot(pole, t) * t; + b = length(b) > 1e-5f ? normalize(b) : Vec3{0.0f, -1.0f, 0.0f}; + Vec3 upper = cosA * t + std::sqrt(1.0f - cosA * cosA) * b; // 上腕の向き / upper arm direction + Vec3 elbowPos = p0 + l1 * upper; + Vec3 fore = normalize(p0 + dist * t - elbowPos); // 前腕の向き / forearm direction + + // 上腕の局所の軸:Y = −上腕(腕は−Yに垂れる)、Z = 前腕が曲がっていく向き、X = Y × Z(肘の蝶番の軸) + // The upper arm's local axes: Y = −upper (the arm hangs along −Y), Z = the way the forearm bends, X = Y × Z (the + // elbow's hinge axis) + Vec3 u = toLocal(parent, upper), f = toLocal(parent, fore); + Vec3 z = f - dot(f, u) * u; + z = length(z) > 1e-5f ? normalize(z) : normalize(cross(u, Vec3{1.0f, 0.0f, 0.0f})); + Vec3 y = -u; + Vec3 x = cross(y, z); + shoulder.rotation = quatFromBasis(x, y, z); + // 肘:Rx(−θ)で前腕が+Z(曲がる側)へ傾く。θ = 上腕と前腕の間の角 / the elbow: Rx(−θ) tilts the forearm towards +Z + // (the bend side). θ = the angle between upper arm and forearm + float theta = std::acos(std::clamp(dot(upper, fore), -1.0f, 1.0f)); + elbow.rotation = rotX(-theta); +} + +void applyPose(Model &model, const Model &weapon, const CharacterRig &rig, const CharacterPose &pose) { + auto node = [&](int i) -> GltfNode & { return model.nodes[static_cast(i)]; }; + auto rest = [&](int i) -> const GltfNode & { return rig.rest[static_cast(i)]; }; + float w = pose.walkAmount, phase = pose.walkPhase; + + // 腰:歩くと上下に揺れ、移動の向きへ回る(脚が進む向きを向く) / hips: bob while walking and turn towards the + // movement (the legs point where they go) + node(rig.hips).translation = rest(rig.hips).translation + Vec3{0.0f, w * (0.03f * std::cos(2.0f * phase) - 0.03f), 0.0f}; + node(rig.hips).rotation = rest(rig.hips).rotation * rotY(pose.legYaw); + + // 脚:太ももを前後に振り、前へ出ていく脚の膝を曲げる(足を持ち上げる) / legs: swing the thighs back and forth and + // bend the knee of the leg that swings forward (lifting the foot) + float swing = 0.5f * pose.stride * w * std::sin(phase); + for (int s = 0; s < 2; ++s) { + float sign = s == 0 ? 1.0f : -1.0f; // 左右は逆位相 / left and right are in opposite phase + node(rig.leg[s]).rotation = rest(rig.leg[s]).rotation * rotX(-sign * swing); + float forwardSwing = std::fmax(0.0f, sign * std::cos(phase)); // この脚が前へ動いている / this leg moves forward + node(rig.knee[s]).rotation = rest(rig.knee[s]).rotation * rotX(w * pose.stride * (0.12f + 1.0f * forwardSwing)); + } + + // 上半身:腰の回転を打ち消して狙う向きを保つ。狙いの上下は背骨・頭・銃で分ける。走ると少し前かがみ + // Upper body: undo the hips' turn so it keeps facing the aim. The aim pitch is split between the spine, the head and + // the weapon. Lean forward a little when running + float lean = 0.1f * w * pose.stride; + node(rig.spine).rotation = rest(rig.spine).rotation * rotY(-pose.legYaw) * rotX(lean - 0.45f * pose.aimPitch); + node(rig.head).rotation = rest(rig.head).rotation * rotX(-0.35f * pose.aimPitch - lean); + // 銃は残りの上下を受け持つので、合計でちょうどaimPitch(前かがみも打ち消す) / the weapon takes the rest of the + // pitch, so the total is exactly aimPitch (the lean is undone too) + node(rig.weapon).rotation = rest(rig.weapon).rotation * rotX(-0.55f * pose.aimPitch - lean); + + // 腕:銃の握り(原点)と前の握り(Foregripソケット)へIKで手を届かせる。肘は下・外・少し後ろへ + // Arms: IK puts the hands on the rifle's grip (its origin) and on its Foregrip socket. Elbows point down, out and a + // little back + Mat4 weaponM = model.nodeTransform(rig.weapon); + Vec3 grip = origin(weaponM); + int foregrip = weapon.findNode("Foregrip"); + Vec3 front = foregrip >= 0 ? origin(weaponM * weapon.nodeTransform(foregrip)) : grip; + Mat4 spineM = model.nodeTransform(rig.spine); + auto spineDir = [&](Vec3 v) { + Vec3 r = v.x * column(spineM, 0) + v.y * column(spineM, 1) + v.z * column(spineM, 2); + return r; + }; + solveArm(model, rig, 0, front, spineDir({0.7f, -1.0f, -0.3f})); + solveArm(model, rig, 1, grip, spineDir({-0.8f, -1.0f, -0.5f})); +} + +Mat4 weaponMatrix(const Model &model, const CharacterRig &rig, const Mat4 &characterTransform) { + return characterTransform * model.nodeTransform(rig.weapon); +} diff --git a/games/tps/src/character.hh b/games/tps/src/character.hh new file mode 100644 index 0000000..d262966 --- /dev/null +++ b/games/tps/src/character.hh @@ -0,0 +1,46 @@ +// キャラクター(第36章):部品の階層でできたGLBを、ノードのTRSをコードで書き換えて動かす。 +// glTFのスキンとアニメーションは私たちのローダーが読み飛ばす(第13・14章)ので、歩き・狙い・腕は手続き的に作る +// Characters (chapter 36): a GLB made of parts in a node hierarchy, animated by rewriting the nodes' TRS in code. +// Our loader skips glTF skins and animations (chapters 13-14), so walking, aiming and the arms are procedural +#pragma once + +#include "engine/model.hh" +#include "engine/shader.hh" +#include "engine/texture.hh" + +#include + +// 関節のノード番号(findNodeで一度だけ探す)と、読み込んだときの姿勢(休みの姿勢) +// The joints' node indices (looked up once with findNode) and the pose as loaded (the rest pose) +struct CharacterRig { + int hips = -1, spine = -1, head = -1, weapon = -1, cameraPivot = -1; + int leg[2] = {-1, -1}, knee[2] = {-1, -1}; // [0] = 左 / left, [1] = 右 / right + int shoulder[2] = {-1, -1}, elbow[2] = {-1, -1}, hand[2] = {-1, -1}; + std::vector rest; + + // 全部の関節が見つかればリグを返す / returns the rig if every joint exists + static std::optional find(const Model &model); +}; + +// 一人分の姿勢のパラメーター(毎ステップ、ゲームの状態から作る) / one character's pose parameters (built from the +// game state every step) +struct CharacterPose { + float walkPhase = 0.0f; // 歩きの周期(ラジアン、進んだ距離に比例) / walk cycle (radians, ∝ distance traveled) + float walkAmount = 0.0f; // 0 = 立つ、1 = 歩く・走る / 0 = standing, 1 = walking / running + float stride = 1.0f; // 足の振りの大きさ(走ると大きい) / leg swing size (bigger when running) + float legYaw = 0.0f; // 腰から下を移動の向きへ回す(ラジアン) / turns the legs towards the movement (radians) + float aimPitch = 0.0f; // 銃の上下(ラジアン、正 = 上) / the gun's pitch (radians, positive = up) +}; + +// ゲームの中の位置と向き → モデル行列。headingはカメラのyawと同じ決まり(0 = −Zを向く、正 = 右へ回る)で、 +// モデルの正面は+Z(第14章の決まり)なので rotateY(π − heading) +// Position and heading in the game → model matrix. heading uses the camera's yaw convention (0 = facing −Z, positive +// turns right); the model's front is +Z (chapter 14's convention), hence rotateY(π − heading) +Mat4 characterMatrix(Vec3 position, float heading); + +// 姿勢をモデルのノードに書く。同じModelを何人もが使うので、描く直前に毎回呼ぶ +// Writes the pose into the model's nodes. Several characters share one Model, so call this right before drawing each +void applyPose(Model &model, const Model &weapon, const CharacterRig &rig, const CharacterPose &pose); + +// 銃をWeaponソケットに付けて描く行列 / the matrix the weapon is drawn with, attached to the Weapon socket +Mat4 weaponMatrix(const Model &model, const CharacterRig &rig, const Mat4 &characterTransform); diff --git a/games/tps/src/collision3d.cc b/games/tps/src/collision3d.cc new file mode 100644 index 0000000..95f9134 --- /dev/null +++ b/games/tps/src/collision3d.cc @@ -0,0 +1,91 @@ +#include "collision3d.hh" + +#include +#include +#include + +Aabb placeAabb(const Aabb &box, Vec3 position, int quarterTurns) { + // rotateY(90°)は (x, z) → (z, −x)。角2つを回して並べ直せば良い / rotateY(90°) maps (x, z) → (z, −x): turn both + // corners and sort them again + Vec3 a = box.lo, b = box.hi; + for (int i = 0; i < ((quarterTurns % 4) + 4) % 4; ++i) { + a = {a.z, a.y, -a.x}; + b = {b.z, b.y, -b.x}; + } + Vec3 lo = {std::fmin(a.x, b.x), std::fmin(a.y, b.y), std::fmin(a.z, b.z)}; + Vec3 hi = {std::fmax(a.x, b.x), std::fmax(a.y, b.y), std::fmax(a.z, b.z)}; + return {lo + position, hi + position}; +} + +bool overlaps(const Aabb &a, const Aabb &b) { + return a.lo.x < b.hi.x && b.lo.x < a.hi.x && a.lo.y < b.hi.y && b.lo.y < a.hi.y && a.lo.z < b.hi.z && + b.lo.z < a.hi.z; +} + +std::optional rayAabb(const Ray &ray, const Aabb &box, float maxT) { + // スラブ法:軸ごとに、2枚の平面(スラブ)の間にいるtの区間を求め、3つの区間の重なりを取る。 + // 入る時刻tEnterの最大と、出る時刻tExitの最小。tEnter ≤ tExitなら当たり + // The slab method: per axis, the interval of t during which the ray is between the two planes (the slab); the hit + // is the overlap of the three intervals: the latest entry tEnter and the earliest exit tExit. Hit if tEnter ≤ tExit + const float o[3] = {ray.origin.x, ray.origin.y, ray.origin.z}; + const float d[3] = {ray.direction.x, ray.direction.y, ray.direction.z}; + const float lo[3] = {box.lo.x, box.lo.y, box.lo.z}; + const float hi[3] = {box.hi.x, box.hi.y, box.hi.z}; + float tEnter = -1e30f, tExit = 1e30f; + int enterAxis = -1; + float enterSign = 0.0f; + for (int axis = 0; axis < 3; ++axis) { + if (std::fabs(d[axis]) < 1e-8f) { + // 平面に平行:スラブの外なら絶対に当たらない / parallel to the planes: outside the slab means no hit at all + if (o[axis] < lo[axis] || o[axis] > hi[axis]) return std::nullopt; + continue; + } + float inv = 1.0f / d[axis]; + float t0 = (lo[axis] - o[axis]) * inv, t1 = (hi[axis] - o[axis]) * inv; + // 負の向きに進むなら、先に当たるのはhiの面 / moving the negative way, the hi plane comes first + float sign = -1.0f; + if (t0 > t1) { + std::swap(t0, t1); + sign = 1.0f; + } + if (t0 > tEnter) { + tEnter = t0; + enterAxis = axis; + enterSign = sign; + } + tExit = std::fmin(tExit, t1); + if (tEnter > tExit) return std::nullopt; + } + if (tExit < 0.0f) return std::nullopt; // 箱は後ろ / the box is behind the ray + if (tEnter < 0.0f) return RayHit{0.0f, {}, -1}; // 始点が箱の中 / the origin is inside + if (tEnter > maxT) return std::nullopt; + RayHit hit{tEnter, {}, -1}; + if (enterAxis == 0) hit.normal.x = enterSign; + if (enterAxis == 1) hit.normal.y = enterSign; + if (enterAxis == 2) hit.normal.z = enterSign; + return hit; +} + +std::optional raycast(const Ray &ray, std::span boxes, float maxT) { + std::optional best; + for (size_t i = 0; i < boxes.size(); ++i) { + std::optional hit = rayAabb(ray, boxes[i], best ? best->t : maxT); + if (hit && (!best || hit->t < best->t)) { + best = hit; + best->index = static_cast(i); + } + } + return best; +} + +std::optional sphereCast(const Ray &ray, float radius, std::span boxes, float maxT) { + std::optional best; + for (size_t i = 0; i < boxes.size(); ++i) { + std::optional hit = rayAabb(ray, boxes[i].expanded(radius), best ? best->t : maxT); + if (hit && (!best || hit->t < best->t)) { + best = hit; + best->index = static_cast(i); + } + } + return best; +} diff --git a/games/tps/src/collision3d.hh b/games/tps/src/collision3d.hh new file mode 100644 index 0000000..af2f463 --- /dev/null +++ b/games/tps/src/collision3d.hh @@ -0,0 +1,51 @@ +// 3Dの当たり判定(第36章):軸に平行な箱(AABB)と、レイ・球を飛ばすテスト。カメラが壁にめり込まないために使う +// 3D collision (chapter 36): axis-aligned boxes (AABBs) and ray / sphere casts. The camera uses them to stay out of +// the walls +#pragma once + +#include "engine/mathx.hh" + +#include +#include + +// 軸に平行な箱。lo = 小さい方の角、hi = 大きい方の角(min/maxという名前はWindowsのマクロとぶつかる) +// An axis-aligned box. lo = the smaller corner, hi = the larger one (the names min/max clash with Windows macros) +struct Aabb { + Vec3 lo, hi; + + Vec3 centre() const { return 0.5f * (lo + hi); } + Vec3 halfSize() const { return 0.5f * (hi - lo); } + // 全方向にrだけ大きくした箱 / the box grown by r in every direction + Aabb expanded(float r) const { return {lo - Vec3{r, r, r}, hi + Vec3{r, r, r}}; } +}; + +// モデル座標の箱を、Y軸周りに90°×quarterTurns回して、positionへ動かす。90°単位なら箱は箱のまま +// Turns a model-space box by quarterTurns × 90° about Y and moves it to position. In 90° steps a box stays a box +Aabb placeAabb(const Aabb &box, Vec3 position, int quarterTurns); + +// 2つの箱が重なるか(触れているだけなら重ならない) / do two boxes overlap (touching does not count)? +bool overlaps(const Aabb &a, const Aabb &b); + +// 半直線:origin + t·direction(directionは単位ベクトル、t ≥ 0) / a ray: origin + t·direction (unit direction, t ≥ 0) +struct Ray { + Vec3 origin; + Vec3 direction; +}; + +// レイが当たった所:距離t、面の法線、何番目の箱か / where a ray hit: distance t, the surface normal, which box +struct RayHit { + float t = 0.0f; + Vec3 normal; + int index = -1; +}; + +// レイと箱(スラブ法)。maxTより遠い当たりは無視。始点が箱の中ならt = 0、法線 = 0 +// Ray against a box (the slab method). Hits farther than maxT are ignored. If the origin is inside: t = 0, normal 0 +std::optional rayAabb(const Ray &ray, const Aabb &box, float maxT); +// 箱の並びの中で一番近い当たり / the nearest hit among a list of boxes +std::optional raycast(const Ray &ray, std::span boxes, float maxT); +// 半径radiusの球を飛ばす:箱をradiusだけ大きくしてレイを当てる(角は本当は丸いので、角の近くでは少し手前で止まる。 +// カメラには安全側で十分) +// Casts a sphere of the given radius: a ray against the boxes grown by the radius (the real Minkowski sum has rounded +// corners, so near corners this stops a little early, which is the safe side for a camera) +std::optional sphereCast(const Ray &ray, float radius, std::span boxes, float maxT); diff --git a/games/tps/src/frustum.cc b/games/tps/src/frustum.cc new file mode 100644 index 0000000..5cd2ddd --- /dev/null +++ b/games/tps/src/frustum.cc @@ -0,0 +1,28 @@ +#include "frustum.hh" + +#include + +Frustum Frustum::fromMatrix(const Mat4 &m) { + // クリップ座標 c = M·p。視錐台の中は −w ≤ x, y, z ≤ w。例えば左の平面 x ≥ −w は (行3 + 行0)·p ≥ 0 + // Clip coordinates c = M·p. Inside the frustum −w ≤ x, y, z ≤ w. E.g. the left plane x ≥ −w is (row 3 + row 0)·p ≥ 0 + auto row = [&](int r) { return Vec4{m.at(r, 0), m.at(r, 1), m.at(r, 2), m.at(r, 3)}; }; + Vec4 r0 = row(0), r1 = row(1), r2 = row(2), r3 = row(3); + Frustum f; + f.planes[0] = r3 + r0; // 左 / left + f.planes[1] = r3 - r0; // 右 / right + f.planes[2] = r3 + r1; // 下 / bottom + f.planes[3] = r3 - r1; // 上 / top + f.planes[4] = r3 + r2; // 手前 / near + f.planes[5] = r3 - r2; // 奥 / far + for (Vec4 &p : f.planes) { + float len = std::sqrt(p.x * p.x + p.y * p.y + p.z * p.z); + p = (1.0f / len) * p; // 距離をメートルで比べられるように / so distances compare in meters + } + return f; +} + +bool Frustum::sphereVisible(Vec3 c, float radius) const { + for (const Vec4 &p : planes) + if (p.x * c.x + p.y * c.y + p.z * c.z + p.w < -radius) return false; + return true; +} diff --git a/games/tps/src/frustum.hh b/games/tps/src/frustum.hh new file mode 100644 index 0000000..387a85e --- /dev/null +++ b/games/tps/src/frustum.hh @@ -0,0 +1,19 @@ +// 視錐台カリング(第36章):画面に映らない部品は描かない / frustum culling (chapter 36): pieces the camera cannot see +// are not drawn +#pragma once + +#include "engine/mathx.hh" + +// 視錐台の6枚の平面。法線は内向き:dot(n, p) + d ≥ 0 なら内側 +// The six planes of a view frustum. The normals point inwards: dot(n, p) + d ≥ 0 means inside +struct Frustum { + Vec4 planes[6]; // (n.x, n.y, n.z, d)、nは単位ベクトル / n is a unit vector + + // 投影 × ビュー行列から取り出す(Gribb-Hartmann法)。正射影の行列(影の光の箱)でも使える + // Extracts the planes from projection × view (the Gribb-Hartmann method). Works for orthographic matrices too (the + // shadow light box) + static Frustum fromMatrix(const Mat4 &viewProjection); + // 球が少しでも中にあるか(6枚のどれかの完全に外側なら見えない) / is any part of the sphere inside? (completely + // outside one plane = invisible) + bool sphereVisible(Vec3 centre, float radius) const; +}; diff --git a/games/tps/src/game.hh b/games/tps/src/game.hh new file mode 100644 index 0000000..0e57845 --- /dev/null +++ b/games/tps/src/game.hh @@ -0,0 +1,57 @@ +// TPS全体で一つの共有データ。mainが作り、シーンは参照で持つ(第26章のデモと同じ形) +// The data the whole TPS shares. main creates it and the scenes keep a reference (the same shape as chapter 26's demo) +#pragma once + +#include "character.hh" +#include "level.hh" +#include "renderer.hh" + +#include "engine/camera2d.hh" +#include "engine/font.hh" +#include "engine/game_loop.hh" +#include "engine/input.hh" +#include "engine/model.hh" +#include "engine/sprite_batch.hh" +#include "engine/window.hh" + +struct Game { + Window &window; + Input &input; + GameLoop &loop; + Renderer &renderer; + SpriteBatch &batch; + const Font &ui; // mono16 + Level &level; + Model &player; // player.glb(姿勢を書き込むので非const) / non-const: poses are written into it + Model &rifle; + const CharacterRig &playerRig; + Camera2D screen; // 1280 × 720のUI / the 1280 × 720 UI + Viewport uiViewport; + int frame = 0; // 描いたフレームの数 / frames drawn so far + int lookFrame = -1; // マウスの動きを最後に使ったフレーム / the frame whose mouse movement was last used + bool showBoxes = false; // B:当たり判定の箱 / collision boxes + bool showStats = false; // F3:時間と描いた数 / timings and draw counts + double frameMs = 0.0; // 1フレームのCPUの時間(壁時計、表示だけ) / CPU time per frame (wall clock, display only) + + Vec2 unusedMouse = {0.0f, 0.0f}; // 更新のなかったフレームのマウスの動き / movement of frames that ran no update + + // このフレームのマウスの動き。1フレームに複数の更新ステップがあっても、最初のステップだけが受け取る + // (window.mouseDelta()はフレームごとの値:ステップごとに使うと2回分回ってしまう) + // This frame's mouse movement. With several update steps in one frame only the first step gets it + // (window.mouseDelta() is per frame: using it in every step would turn twice as far) + Vec2 takeMouseDelta() { + if (lookFrame == frame || !window.cursorCaptured()) return {0.0f, 0.0f}; + lookFrame = frame; + Vec2 delta = unusedMouse + window.mouseDelta(); + unusedMouse = {0.0f, 0.0f}; + return delta; + } + // 毎フレームの最後に呼ぶ:更新が1回もなかったフレーム(画面が60 Hzより速いと良くある)の動きを捨てずに、 + // 次のステップへ持ち越す + // Call at the end of every frame: the movement of a frame that ran no update (common on screens faster than + // 60 Hz) is carried over to the next step instead of being lost + void keepUnusedMouse() { + if (!window.cursorCaptured()) unusedMouse = {0.0f, 0.0f}; + else if (loop.stats().steps == 0) unusedMouse = unusedMouse + window.mouseDelta(); + } +}; diff --git a/games/tps/src/level.cc b/games/tps/src/level.cc new file mode 100644 index 0000000..b402619 --- /dev/null +++ b/games/tps/src/level.cc @@ -0,0 +1,203 @@ +#include "level.hh" + +#include "engine/file_util.hh" + +#include +#include +#include +#include +#include + +// 部品の番号から作る決まった乱数(インスタンスの色のばらつき用) / a fixed pseudo-random number from a piece's index +// (for the per-instance tint) +static float hash01(std::uint32_t x) { + x ^= x >> 16; + x *= 0x7feb352du; + x ^= x >> 15; + x *= 0x846ca68bu; + x ^= x >> 16; + return static_cast(x >> 8) / 16777216.0f; +} + +int Level::findType(const std::string &name) const { + for (size_t i = 0; i < types.size(); ++i) + if (types[i].name == name) return static_cast(i); + return -1; +} + +std::optional Level::load(const std::string &path) { + std::optional text = readTextFile(path); + if (!text) { + fprintf(stderr, "%s: 開けない / cannot open\n", path.c_str()); + return std::nullopt; + } + Level level; + std::istringstream lines(*text); + std::string line; + int lineNo = 0; + auto fail = [&](const char *why) { + fprintf(stderr, "%s:%d: %s\n", path.c_str(), lineNo, why); + return std::nullopt; + }; + // 部品を一つ置く(向きは90°単位) / places one piece (yaw in 90° steps) + auto place = [&](int type, Vec3 p, float yawDegrees) -> bool { + float q = yawDegrees / 90.0f; + if (std::fabs(q - std::round(q)) > 1e-4f) return false; + Piece piece; + piece.type = type; + piece.position = p; + piece.quarterTurns = static_cast(std::lround(q)); + piece.model = translate(p) * rotateY(radians(90.0f * static_cast(piece.quarterTurns))); + level.pieces.push_back(piece); + return true; + }; + + while (std::getline(lines, line)) { + ++lineNo; + if (size_t hash = line.find('#'); hash != std::string::npos) line.erase(hash); + std::istringstream in(line); + std::string command; + if (!(in >> command)) continue; // 空行 / empty line + if (command == "model") { + // model <名前> [noshadow] [nocollide] [vary=0.1] + PieceType type; + std::string file, option; + if (!(in >> type.name >> file)) return fail("model [noshadow] [nocollide] [vary=N]"); + while (in >> option) { + if (option == "noshadow") type.castsShadow = false; + else if (option == "nocollide") type.collides = false; + else if (option.rfind("vary=", 0) == 0) type.tintVariation = std::strtof(option.c_str() + 5, nullptr); + else return fail("知らないオプション / unknown option"); + } + if (level.findType(type.name) >= 0) return fail("同じ名前の部品 / duplicate piece name"); + type.model = Model::load(file); + if (!type.model) return fail("GLBを読めない / cannot load the GLB"); + level.types.push_back(std::move(type)); + } else if (command == "box") { + // box <部品> x0 y0 z0 x1 y1 z1:モデル座標の当たり判定(何個でも) / model-space collision box (any number) + std::string name; + Aabb b; + if (!(in >> name >> b.lo.x >> b.lo.y >> b.lo.z >> b.hi.x >> b.hi.y >> b.hi.z)) + return fail("box x0 y0 z0 x1 y1 z1"); + int t = level.findType(name); + if (t < 0) return fail("先にmodelで部品を宣言する / declare the piece with model first"); + level.types[static_cast(t)].boxes.push_back(b); + } else if (command == "solid") { + // solid x0 y0 z0 x1 y1 z1:見えないワールドの箱(地面、見えない壁) / an invisible world box (ground, walls) + Aabb b; + if (!(in >> b.lo.x >> b.lo.y >> b.lo.z >> b.hi.x >> b.hi.y >> b.hi.z)) return fail("solid x0 y0 z0 x1 y1 z1"); + level.solids.push_back(b); + } else if (command == "place" || command == "row" || command == "grid") { + // place <部品> x y z yaw + // row <部品> x y z yaw dx dz count (count個、(dx, dz)ずつずらす / count pieces, (dx, dz) apart) + // grid <部品> x y z yaw step nx nz (nx × nz個、stepの間隔 / nx × nz pieces, step apart) + std::string name; + Vec3 p; + float yaw = 0.0f; + if (!(in >> name >> p.x >> p.y >> p.z >> yaw)) return fail("place/row/grid x y z yaw ..."); + int t = level.findType(name); + if (t < 0) return fail("先にmodelで部品を宣言する / declare the piece with model first"); + bool ok = true; + if (command == "place") { + ok = place(t, p, yaw); + } else if (command == "row") { + float dx = 0, dz = 0; + int count = 0; + if (!(in >> dx >> dz >> count) || count < 1) return fail("row x y z yaw dx dz count"); + for (int i = 0; i < count && ok; ++i) + ok = place(t, p + Vec3{dx * static_cast(i), 0.0f, dz * static_cast(i)}, yaw); + } else { + float step = 0; + int nx = 0, nz = 0; + if (!(in >> step >> nx >> nz) || nx < 1 || nz < 1) return fail("grid x y z yaw step nx nz"); + for (int i = 0; i < nz && ok; ++i) + for (int j = 0; j < nx && ok; ++j) + ok = place(t, p + Vec3{step * static_cast(j), 0.0f, step * static_cast(i)}, yaw); + } + if (!ok) return fail("向きは90°の倍数だけ / yaw must be a multiple of 90 degrees"); + } else if (command == "spawn") { + float yaw = 0.0f; + if (!(in >> level.spawn.x >> level.spawn.y >> level.spawn.z >> yaw)) return fail("spawn x y z yaw"); + level.spawnYaw = radians(yaw); + } else { + return fail("知らない命令 / unknown command"); + } + } + + // 種類ごとの外接球と、置いた部品のワールドの箱・球・色 / per type: bounding sphere; per piece: world boxes, sphere, + // tint + for (PieceType &type : level.types) { + type.sphereCentre = 0.5f * (type.model->boundsMin + type.model->boundsMax); + type.sphereRadius = length(0.5f * (type.model->boundsMax - type.model->boundsMin)); + if (type.boxes.empty()) type.boxes.push_back({type.model->boundsMin, type.model->boundsMax}); + } + level.bounds = {{1e9f, 1e9f, 1e9f}, {-1e9f, -1e9f, -1e9f}}; + for (size_t i = 0; i < level.pieces.size(); ++i) { + Piece &piece = level.pieces[i]; + PieceType &type = level.types[static_cast(piece.type)]; + type.pieces.push_back(static_cast(i)); + Vec4 c = piece.model * Vec4{type.sphereCentre.x, type.sphereCentre.y, type.sphereCentre.z, 1.0f}; + piece.sphereCentre = {c.x, c.y, c.z}; + piece.sphereRadius = type.sphereRadius; + float shade = 1.0f + type.tintVariation * (2.0f * hash01(static_cast(i) * 2654435761u) - 1.0f); + piece.tint = {shade, shade, shade}; + for (const Aabb &b : type.boxes) { + Aabb w = placeAabb(b, piece.position, piece.quarterTurns); + if (type.collides) level.solids.push_back(w); + level.bounds.lo = {std::fmin(level.bounds.lo.x, w.lo.x), std::fmin(level.bounds.lo.y, w.lo.y), + std::fmin(level.bounds.lo.z, w.lo.z)}; + level.bounds.hi = {std::fmax(level.bounds.hi.x, w.hi.x), std::fmax(level.bounds.hi.y, w.hi.y), + std::fmax(level.bounds.hi.z, w.hi.z)}; + } + } + // インスタンスのバッファ:種類ごとに置いた数だけ。毎フレーム見える分を先頭から書き直す + // Instance buffers: one per type, as large as its placements. Each frame the visible ones are rewritten from the + // start + for (PieceType &type : level.types) { + if (type.pieces.empty()) continue; + type.instances = Buffer(nullptr, static_cast(type.pieces.size() * sizeof(InstanceData)), + GL_DYNAMIC_STORAGE_BIT); + type.model->setInstanceBuffer(type.instances, sizeof(InstanceData), kInstanceLayout); + } + printf("%s: %zu piece types, %zu pieces, %zu collision boxes\n", path.c_str(), level.types.size(), + level.pieces.size(), level.solids.size()); + return level; +} + +LevelDrawStats Level::draw(const Shader &shader, const Texture2D &white, const Frustum &view) { + LevelDrawStats stats; + // ファイルと逆の順:床(全部の後ろ)を最後に。GPUは手前の物が先に描かれていれば、隠れたフラグメントを + // シェーダーの前に捨てられる(早い深度テスト) / reverse file order: the floor (behind everything) last. A GPU can + // reject hidden fragments before shading them when nearer things were drawn first (early depth test) + for (auto it = types.rbegin(); it != types.rend(); ++it) { + PieceType &type = *it; + scratch.clear(); + for (int i : type.pieces) { + const Piece &piece = pieces[static_cast(i)]; + ++stats.total; + if (!view.sphereVisible(piece.sphereCentre, piece.sphereRadius)) continue; + scratch.push_back({piece.model, piece.tint}); + } + if (scratch.empty()) continue; + stats.visible += static_cast(scratch.size()); + stats.drawCalls += static_cast(type.model->primitiveCount()); + type.instances.update(scratch.data(), static_cast(scratch.size() * sizeof(InstanceData))); + type.model->drawInstanced(shader, white, static_cast(scratch.size()), Shading::Pbr); + } + return stats; +} + +LevelDrawStats Level::drawShadows(const Shader &shadow, const Texture2D &white, const Frustum &lightBox) const { + LevelDrawStats stats; + for (const PieceType &type : types) { + for (int i : type.pieces) { + const Piece &piece = pieces[static_cast(i)]; + ++stats.total; + if (!type.castsShadow || !lightBox.sphereVisible(piece.sphereCentre, piece.sphereRadius)) continue; + ++stats.visible; + stats.drawCalls += static_cast(type.model->primitiveCount()); + type.model->drawDepth(shadow, piece.model, white); + } + } + return stats; +} diff --git a/games/tps/src/level.hh b/games/tps/src/level.hh new file mode 100644 index 0000000..7ad0112 --- /dev/null +++ b/games/tps/src/level.hh @@ -0,0 +1,75 @@ +// レベル:GLBの部品をテキストファイルの通りに並べる(第36章)。部品の種類ごとにインスタンシングで描き(第19章)、 +// 当たり判定の箱は部品の大きさ(またはファイルに書いた箱)から作る +// The level: GLB pieces placed as a text file says (chapter 36). Each piece type is drawn with instancing (chapter +// 19); the collision boxes come from the pieces' bounds (or from boxes written in the file) +#pragma once + +#include "collision3d.hh" +#include "frustum.hh" + +#include "engine/buffer.hh" +#include "engine/model.hh" +#include "engine/shader.hh" +#include "engine/texture.hh" + +#include +#include +#include + +// 部品の種類:一つのGLB / a piece type: one GLB +struct PieceType { + std::string name; + std::optional model; + std::vector boxes; // モデル座標の当たり判定(空ならモデルの箱) / model-space collision (empty = bounds) + bool castsShadow = true; + bool collides = true; + float tintVariation = 0.0f; // インスタンスごとの明るさのばらつき / per-instance brightness variation + Vec3 sphereCentre; // モデル座標の外接球 / model-space bounding sphere + float sphereRadius = 0.0f; + Buffer instances; // InstanceData × 置いた数(GL_DYNAMIC_STORAGE_BIT) / InstanceData × placements + std::vector pieces; // この種類の部品(Level::piecesの番号) / pieces of this type (indices) +}; + +// 置いた部品一つ / one placed piece +struct Piece { + int type = 0; + Vec3 position; + int quarterTurns = 0; // Y軸周りに90°単位 / about Y in 90° steps + Mat4 model; + Vec3 tint = {1.0f, 1.0f, 1.0f}; + Vec3 sphereCentre; // ワールドの外接球(カリング用) / world-space bounding sphere (for culling) + float sphereRadius = 0.0f; +}; + +// 描いた数(画面の数字とNOTES用) / how much was drawn (for the overlay and the notes) +struct LevelDrawStats { + int visible = 0, total = 0, drawCalls = 0; +}; + +class Level { +public: + // レベルのファイルを読み、使う部品のGLBも読む。失敗したら「ファイル:行: 理由」を表示してstd::nullopt + // Reads a level file and the GLBs it uses. On failure prints "file:line: reason" and returns std::nullopt + static std::optional load(const std::string &path); + + // カメラのパス:見える部品だけを種類ごとにインスタンスのバッファへ書き、1種類=プリミティブごとに1回の描画で描く。 + // shaderはinstanced.vert + pbr.frag + // Camera pass: writes only the visible pieces of each type into its instance buffer and draws each type with one + // draw call per primitive. shader = instanced.vert + pbr.frag + LevelDrawStats draw(const Shader &shader, const Texture2D &white, const Frustum &view); + // 影のパス:光の箱に入る部品だけを、一つずつdrawDepthで(エンジンのModelにインスタンシングの深度描画がないため) + // Shadow pass: only the pieces inside the light box, one drawDepth each (the engine's Model has no instanced depth + // drawing) + LevelDrawStats drawShadows(const Shader &shadow, const Texture2D &white, const Frustum &lightBox) const; + + std::vector types; + std::vector pieces; + std::vector solids; // ワールドの当たり判定の箱 / world-space collision boxes + Vec3 spawn; // プレイヤーの出発点 / the player's start + float spawnYaw = 0.0f; // ラジアン、0 = −Zを向く / radians, 0 = facing −Z + Aabb bounds; // 全部を囲む箱 / box around everything + +private: + int findType(const std::string &name) const; + std::vector scratch; // 毎フレーム使い回す / reused every frame +}; diff --git a/games/tps/src/main.cc b/games/tps/src/main.cc new file mode 100644 index 0000000..7292dc9 --- /dev/null +++ b/games/tps/src/main.cc @@ -0,0 +1,109 @@ +// 第36〜39章:三人称シューティング(TPS)。第36章:レベル、キャラクター、三人称カメラ +// Chapters 36-39: the third-person shooter (TPS). Chapter 36: the level, the character and the third-person camera +// +// 操作 / Controls: +// WASD カメラの向きに対して移動 / move relative to the camera +// マウス / mouse 見回す / look around +// Shift 走る(前へ) / run (forwards) +// Q 右肩 ⇔ 左肩 / right ⇔ left shoulder +// B 当たり判定の箱 / collision boxes +// F3 時間と描いた数 / timings and draw counts +// F4 視錐台カリングのオン・オフ / frustum culling on / off +// C カメラだけ回す(キャラクターを前から見る) / turn only the camera (look at the character) +// K カメラの当たり判定のオン・オフ / camera collision on / off +// P 手続き的な姿勢のオン・オフ(読み込んだままの姿勢) / procedural pose on / off (the pose as loaded) +// Tab カーソルのキャプチャ / cursor capture +// Esc 終了 / quit +// 実行はプロジェクトのルートから:./build/games/tps/tps / run from the project root: ./build/games/tps/tps +#include "game.hh" +#include "play_scene.hh" + +#include "engine/scene.hh" + +#include +#include +#include +#include + +int main(int argc, char **argv) { + Window window; + if (!window.create(1280, 720, "OpenGL Tutorial - TPS")) return 1; + + std::unique_ptr renderer = Renderer::create(window.width(), window.height()); + if (!renderer) return 1; + window.onResize = [&](int width, int height) { renderer->resize(width, height); }; + + // 引数でほかのレベルも読める(例:部品を並べたpieces.level) / another level can be given as an argument (e.g. + // pieces.level, which lines up every piece) + std::optional level = Level::load(argc > 1 ? argv[1] : "games/tps/assets/levels/arena.level"); + std::optional player = Model::load("games/tps/assets/models/player.glb"); + std::optional rifle = Model::load("games/tps/assets/models/rifle.glb"); + if (!level || !player || !rifle) return 1; + std::optional playerRig = CharacterRig::find(*player); + if (!playerRig) return 1; + + // HUDと文字(第25・26章の2Dの道具を3Dの絵の上に) / HUD and text (the chapter 25-26 2D toolkit over the 3D image) + std::optional batch = SpriteBatch::create(); + // このゲームの文字のアトラス:共有のmono16にゲームで使う漢字を足したもの(同じ作り方) + // This game's font atlas: the shared mono16 plus the kanji the game uses (made the same way) + std::optional ui = Font::load("games/tps/assets/fonts/mono16.fnt"); + if (!batch || !ui) return 1; + + Input input; + input.attach(window); + input.bind("forward", {InputBinding::key(GLFW_KEY_W), InputBinding::key(GLFW_KEY_UP)}); + input.bind("back", {InputBinding::key(GLFW_KEY_S), InputBinding::key(GLFW_KEY_DOWN)}); + input.bind("left", {InputBinding::key(GLFW_KEY_A), InputBinding::key(GLFW_KEY_LEFT)}); + input.bind("right", {InputBinding::key(GLFW_KEY_D), InputBinding::key(GLFW_KEY_RIGHT)}); + input.bind("run", {InputBinding::key(GLFW_KEY_LEFT_SHIFT)}); + + GameLoop loop({.step = 1.0 / 60.0, .maxSteps = 5}); + Game game{.window = window, .input = input, .loop = loop, .renderer = *renderer, .batch = *batch, .ui = *ui, + .level = *level, .player = *player, .rifle = *rifle, .playerRig = *playerRig, + .screen = Camera2D::screen({1280.0f, 720.0f}), .uiViewport = {}}; + + SceneManager scenes; + scenes.push(std::make_unique(game)); + // pushは予約だけ:更新0回の最初のフレームも描けるように、ここで適用する(シーンの更新は呼ばれない) + // push only queues the request: apply it now so that the first frame (which runs no update) has a scene to draw + // (no scene's update is called) + scenes.update(0.0f); + + auto last = std::chrono::steady_clock::now(); + double sum[5] = {}; + loop.run( + window, input, + [&](float dt) { + scenes.update(dt); + if (scenes.empty()) window.close(); + }, + [&](float alpha) { + // 1. 3Dの世界(影 → 場面 → 後処理 → 画面) / 1. the 3D world (shadows → scene → post → screen) + scenes.draw(alpha); + // 2. UI:後処理の後の画面に、2Dの道具で(色はsRGBのまま、第25章) / 2. the UI: on top of the post-processed + // image with the 2D toolkit (colors stay sRGB, chapter 25) + game.uiViewport = letterbox(window.width(), window.height(), game.screen.viewSize, false); + game.uiViewport.apply(); + scenes.drawUi(alpha); + scenes.drawFade(*batch, game.screen.matrix(), game.screen.viewSize); + // 表示用の時間だけ壁時計で測る(ゲームの中身には使わない) / the wall clock is only for the displayed time + auto now = std::chrono::steady_clock::now(); + game.frameMs = std::chrono::duration(now - last).count(); + last = now; + // 60フレームの平均を標準出力へ(llvmpipeの数字は揺れるので平均で比べる) / the average of 60 frames to stdout + // (llvmpipe numbers are noisy: compare averages) + sum[0] += game.frameMs; + sum[1] += renderer->timings.shadowMs; + sum[2] += renderer->timings.sceneMs; + sum[3] += renderer->timings.postMs; + sum[4] += static_cast(renderer->timings.sceneFragments); + game.keepUnusedMouse(); + if (++game.frame % 60 == 0) { + printf("frames %d-%d: CPU %.1f ms/frame, llvmpipe raster shadow %.1f / scene %.1f / post %.1f ms, " + "scene fragments %.2f M\n", + game.frame - 59, game.frame, sum[0] / 60, sum[1] / 60, sum[2] / 60, sum[3] / 60, sum[4] / 60e6); + for (double &v : sum) v = 0.0; + } + }); + return 0; +} diff --git a/games/tps/src/play_scene.cc b/games/tps/src/play_scene.cc new file mode 100644 index 0000000..cffd807 --- /dev/null +++ b/games/tps/src/play_scene.cc @@ -0,0 +1,240 @@ +#include "play_scene.hh" + +#include +#include +#include +#include + +// 角度を −π〜π に / wraps an angle into −π..π +static float wrapAngle(float a) { + while (a > PI) a -= 2.0f * PI; + while (a < -PI) a += 2.0f * PI; + return a; +} +// 目標の角度へ短い方の向きで近づく / approaches a target angle the short way round +static float approachAngle(float current, float target, float k) { return current + wrapAngle(target - current) * k; } +static float approach(float rate, float dt) { return 1.0f - std::exp(-rate * dt); } + +constexpr float kWalkSpeed = 3.2f; // m/s +constexpr float kRunSpeed = 6.0f; // m/s(Shift) +constexpr float kAcceleration = 12.0f; // 速度が目標に近づく割合(毎秒) / how fast the velocity approaches its target + +PlayScene::PlayScene(Game &game) : g(game) {} + +Vec3 PlayScene::cameraPivot() const { + // CameraPivotソケット(空のノード)のワールドの位置:モデル行列 × ノードの行列の原点 + // The world position of the CameraPivot socket (an empty node): model matrix × the node's matrix, origin + Vec4 p = characterMatrix(position, heading) * g.player.nodeTransform(g.playerRig.cameraPivot) * + Vec4{0.0f, 0.0f, 0.0f, 1.0f}; + return {p.x, p.y, p.z}; +} + +void PlayScene::enter() { + position = prevPosition = g.level.spawn; + heading = prevHeading = g.level.spawnYaw; + camera.yaw = g.level.spawnYaw; + camera.reset(cameraPivot(), g.level.solids); + prevEye = camera.eye(); + prevForward = camera.forward(); + g.window.setCursorCaptured(true); +} + +void PlayScene::pause() { + // 止まっている間に補間で揺れないように / no interpolation wobble while paused (chapter 26) + prevPosition = position; + prevHeading = heading; + prevEye = camera.eye(); + prevForward = camera.forward(); +} + +void PlayScene::update(float dt) { + Input &in = g.input; + prevPosition = position; + prevHeading = heading; + prevEye = camera.eye(); + prevForward = camera.forward(); + time += dt; + + if (in.pressed(GLFW_KEY_ESCAPE)) scenes().pop(); // 最後のシーン → 終了 / the last scene → quit + if (in.pressed(GLFW_KEY_TAB)) g.window.setCursorCaptured(!g.window.cursorCaptured()); + if (in.pressed(GLFW_KEY_Q)) camera.shoulderSide = -camera.shoulderSide; + if (in.pressed(GLFW_KEY_B)) g.showBoxes = !g.showBoxes; + if (in.pressed(GLFW_KEY_F3)) g.showStats = !g.showStats; + if (in.pressed(GLFW_KEY_C)) inspect = !inspect; + if (in.pressed(GLFW_KEY_K)) cameraCollision = !cameraCollision; + if (in.pressed(GLFW_KEY_P)) posing = !posing; + if (in.pressed(GLFW_KEY_F4)) culling = !culling; + + // 1. 見回す(マウスの動きはフレームごと:最初のステップだけが使う) / 1. look around (mouse movement is per frame: + // only the first step uses it) + Vec2 mouse = g.takeMouseDelta(); + camera.look(mouse.x, mouse.y); + + // 2. カメラに対する移動:入力(右, 前)を、カメラの水平の右と前に掛ける(ワールドの軸ではない) + // 2. movement relative to the camera: the input (right, forward) times the camera's horizontal right and forward + // vectors (not the world axes) + Vec2 stick = {in.axis("left", "right"), in.axis("back", "forward")}; + if (inspect) stick = {0.0f, 0.0f}; // C:キャラクターの周りを見るだけ / C: only look around the character + Vec3 wish = stick.x * camera.right() + stick.y * camera.flatForward(); + float wishLength = length(wish); + if (wishLength > 1.0f) wish = wish / wishLength; // 斜めでも同じ速さ / same speed diagonally + bool running = in.actionHeld("run") && stick.y > 0.0f; + Vec3 target = (running ? kRunSpeed : kWalkSpeed) * wish; + velocity = velocity + approach(kAcceleration, dt) * (target - velocity); + position = position + dt * velocity; // 第36章:まだ当たり判定なし / chapter 36: no collision yet + + // 3. キャラクターはカメラの向きを向く(肩越しの撃ち合いの決まり)。脚は移動の向きへ + // 3. the character faces where the camera looks (the over-the-shoulder shooter convention); the legs turn towards + // the movement + if (!inspect) heading = approachAngle(heading, camera.yaw, approach(14.0f, dt)); + float speed = length(Vec3{velocity.x, 0.0f, velocity.z}); + float legTarget = 0.0f, direction = 1.0f; + if (speed > 0.2f) { + // 速度をキャラクターの座標へ:+Zが前、+Xが左(右手系で+Zを向くと+Xは左) / velocity in character space: +Z is + // forward, +X is LEFT (facing +Z in a right-handed system, +X is on the left) + Vec3 fwd = {std::sin(heading), 0.0f, -std::cos(heading)}, rgt = {std::cos(heading), 0.0f, std::sin(heading)}; + float mz = dot(velocity, fwd), mx = -dot(velocity, rgt); + legTarget = std::atan2(mx, mz); + if (std::fabs(legTarget) > radians(100.0f)) { // 後ろ歩き:脚は前を向いたまま逆に回す / walking backwards + legTarget = wrapAngle(legTarget - PI); + direction = -1.0f; + } + legTarget = std::clamp(legTarget, radians(-70.0f), radians(70.0f)); + } + pose.legYaw = approachAngle(pose.legYaw, legTarget, approach(10.0f, dt)); + // 歩きの周期は進んだ距離に比例:足が地面を滑らない / the walk cycle advances with distance: feet do not skate + float run = std::clamp((speed - kWalkSpeed) / (kRunSpeed - kWalkSpeed), 0.0f, 1.0f); + float cycleLength = 1.5f + 0.9f * run; // 1周期(2歩)のm / meters per cycle (two steps) + pose.walkPhase = std::fmod(pose.walkPhase + direction * 2.0f * PI * speed * dt / cycleLength, 2.0f * PI); + pose.walkAmount = std::clamp(speed / kWalkSpeed, 0.0f, 1.0f); + pose.stride = 1.0f + 0.5f * run; + if (!inspect) pose.aimPitch = camera.pitch; + + // 4. カメラ:CameraPivotソケットを追う / 4. the camera follows the CameraPivot socket + // (Kで当たり判定なしのカメラと比べられる) / (K compares with a camera that ignores the walls) + camera.update(cameraPivot(), cameraCollision ? std::span(g.level.solids) : std::span(), dt); +} + +void PlayScene::drawCharacters(const Shader &shader, bool depthOnly, Vec3 eye) { + // 前のステップと今のステップの間をdrawAlphaで補間(第26章) / interpolate between the last and the current step + // with drawAlpha (chapter 26) + Mat4 m = characterMatrix(lerp(prevPosition, position, drawAlpha), approachAngle(prevHeading, heading, drawAlpha)); + if (posing) applyPose(g.player, g.rifle, g.playerRig, pose); + else g.player.nodes = g.playerRig.rest; // P:読み込んだままの姿勢 / P: the pose as loaded + Mat4 w = weaponMatrix(g.player, g.playerRig, m); + if (depthOnly) { + g.player.drawDepth(shader, m, g.renderer.white); + g.rifle.drawDepth(shader, w, g.renderer.white); + } else { + g.player.draw(shader, m, g.renderer.white, ModelPass::Opaque, eye, Shading::Pbr); + g.rifle.draw(shader, w, g.renderer.white, ModelPass::Opaque, eye, Shading::Pbr); + } +} + +void PlayScene::drawDebugBoxes() { + // 当たり判定の箱を線で(unlit、HDRの色) / the collision boxes as lines (unlit, HDR color) + const Shader &s = *g.renderer.unlit; + s.use(); + s.set("uColor", Vec3{0.1f, 1.2f, 0.3f}); + glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); + glDisable(GL_CULL_FACE); + for (const Aabb &b : g.level.solids) { + s.set("uModel", translate(b.centre()) * scale(b.hi - b.lo)); + g.renderer.cube.draw(); + } + glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); + // ソケット(空のノード)を小さな箱で、体に隠れないように深度テストなしで:CameraPivot 水色、Weapon 紫、 + // 両手 黄色、Muzzle 赤 + // The sockets (empty nodes) as small boxes, without the depth test so the body does not hide them: CameraPivot + // cyan, Weapon magenta, the hands yellow, Muzzle red + glDisable(GL_DEPTH_TEST); + Mat4 m = characterMatrix(lerp(prevPosition, position, drawAlpha), approachAngle(prevHeading, heading, drawAlpha)); + auto marker = [&](const Mat4 &socket, Vec3 color) { + s.set("uColor", color); + s.set("uModel", socket * scale({0.07f, 0.07f, 0.07f})); + g.renderer.cube.draw(); + }; + const CharacterRig &rig = g.playerRig; + marker(m * g.player.nodeTransform(rig.cameraPivot), {0.0f, 2.0f, 2.0f}); + marker(m * g.player.nodeTransform(rig.weapon), {2.0f, 0.0f, 2.0f}); + marker(m * g.player.nodeTransform(rig.hand[0]), {2.0f, 2.0f, 0.0f}); + marker(m * g.player.nodeTransform(rig.hand[1]), {2.0f, 2.0f, 0.0f}); + int muzzle = g.rifle.findNode("Muzzle"); + if (muzzle >= 0) marker(weaponMatrix(g.player, rig, m) * g.rifle.nodeTransform(muzzle), {3.0f, 0.1f, 0.1f}); + glEnable(GL_DEPTH_TEST); + glEnable(GL_CULL_FACE); +} + +void PlayScene::draw(float alpha) { + drawAlpha = alpha; + Renderer &r = g.renderer; + FrameView view; + view.eye = lerp(prevEye, camera.eye(), alpha); + view.forward = normalize(lerp(prevForward, camera.forward(), alpha)); + view.fovY = camera.fovY; + view.aspect = static_cast(g.window.width()) / static_cast(g.window.height()); + view.time = time; + + // 昼の光(第21・24章の値):太陽と、Blinn-Phong用の環境光(PBRは空のIBL) / daylight (the chapter 21/24 values): + // the sun and the Blinn-Phong ambient (PBR uses the sky's IBL) + LightSet lights; + lights.ambient = {0.20f, 0.24f, 0.33f}; + lights.directional = {.direction = {-0.5f, -1.0f, -0.35f}, .color = {2.6f, 2.45f, 2.2f}}; + r.beginFrame(view, lights); + + // カメラが体の中に入ったら(壁際で寄せられて)自分を描かない:頭や胴の内側が映る。肩へずらしているので、 + // 距離が短いだけでは入らない:体の軸からの水平距離で決める + // When the camera ends up inside the body (pulled in at a wall) do not draw the player: we would see the inside of + // the head or torso. Thanks to the shoulder offset a short distance alone does not mean that: decide by the + // horizontal distance from the body's axis + Vec3 feet = lerp(prevPosition, position, alpha); + float axisDistance = length(Vec3{view.eye.x - feet.x, 0.0f, view.eye.z - feet.z}); + bool drawPlayer = axisDistance > 0.5f || view.eye.y > feet.y + 2.0f; + + // 1. 影 / 1. shadows + if (r.beginShadows()) { + shadowStats = g.level.drawShadows(*r.shadow, r.white, r.lightFrustum()); + drawCharacters(*r.shadow, true, view.eye); + r.endShadows(); + } + // 2. 場面 / 2. the scene + r.beginScene(); + // 手前の物から:キャラクター → レベル(床は最後) / nearest first: the character → the level (floor last) + r.pbr->use(); + if (drawPlayer) drawCharacters(*r.pbr, false, view.eye); + r.pbrInstanced->use(); + // F4:カリングなし(全部の部品をインスタンスのバッファへ)と比べる。平面(0, 0, 0, 1)なら全部が内側 + // F4: compare with no culling (every piece goes into the instance buffers). Planes (0, 0, 0, 1) keep everything in + Frustum everything; + for (Vec4 &plane : everything.planes) plane = {0.0f, 0.0f, 0.0f, 1.0f}; + levelStats = g.level.draw(*r.pbrInstanced, r.white, culling ? r.viewFrustum() : everything); + if (g.showBoxes) drawDebugBoxes(); + r.drawSky(); + r.endScene(); + // 3. 後処理 → 画面 / 3. post-processing → the screen + r.present(g.window.width(), g.window.height()); +} + +void PlayScene::drawUi(float /*alpha*/) { + SpriteBatch &batch = g.batch; + batch.begin(g.screen.matrix()); + const TextStyle small{.color = {1.0f, 1.0f, 1.0f, 0.85f}, .shadow = {0.0f, 0.0f, 0.0f, 0.8f}}; + if (g.showStats) { + const Renderer &r = g.renderer; + std::string lines = std::format( + "CPU frame {:.1f} ms (wall clock) llvmpipe raster: shadow {:.1f} ms, scene {:.1f} ms, post {:.1f} ms\n" + "level pieces drawn {}/{} ({} draw calls) shadow casters {} ({} draw calls) shadow texel {:.1f} mm\n" + "camera distance {:.2f} m{}{} collision boxes {} culling {} scene fragments {:.2f} M", + g.frameMs, r.timings.shadowMs, r.timings.sceneMs, r.timings.postMs, levelStats.visible, levelStats.total, + levelStats.drawCalls, shadowStats.visible, shadowStats.drawCalls, r.shadowTexelMm(), + camera.currentDistance(), camera.blocked() ? " (pulled in by a wall)" : "", + cameraCollision ? "" : " (camera collision OFF)", g.level.solids.size(), culling ? "on" : "OFF (F4)", + static_cast(r.timings.sceneFragments) / 1e6); + batch.drawRect({0.0f, 0.0f, 1280.0f, 68.0f}, {0.0f, 0.0f, 0.0f, 0.45f}); + g.ui.draw(batch, lines, {10.0f, 6.0f}, small); + } + g.ui.draw(batch, "WASD 移動 / move マウス / mouse: look Shift 走る / run Q 肩 / shoulder B 箱 / boxes F3", + {640.0f, 694.0f}, {.color = {1.0f, 1.0f, 1.0f, 0.7f}, .align = TextAlign::Centre, + .shadow = {0.0f, 0.0f, 0.0f, 0.8f}}); + batch.end(); +} diff --git a/games/tps/src/play_scene.hh b/games/tps/src/play_scene.hh new file mode 100644 index 0000000..7c9e7d7 --- /dev/null +++ b/games/tps/src/play_scene.hh @@ -0,0 +1,44 @@ +// 遊ぶシーン(第36章):レベルの中をキャラクターで歩き回る。カメラの向きに対して動き、カメラは壁を避けて付いてくる +// The play scene (chapter 36): walk a character around the level. It moves relative to the camera, and the camera +// follows without entering walls +#pragma once + +#include "game.hh" +#include "third_person_camera.hh" + +#include "engine/scene.hh" + +class PlayScene : public Scene { +public: + explicit PlayScene(Game &game); + void enter() override; + void pause() override; + void update(float dt) override; + void draw(float alpha) override; + void drawUi(float alpha) override; + +private: + // 見えるもの全部(影のパスと場面のパスで同じ物を描く) / everything visible (the shadow and the scene pass draw + // the same things) + void drawCharacters(const Shader &shader, bool depthOnly, Vec3 eye); + void drawDebugBoxes(); + Vec3 cameraPivot() const; + + Game &g; + ThirdPersonCamera camera; + Vec3 prevEye, prevForward; // 前のステップのカメラ(補間用) / last step's camera (for interpolation) + + // プレイヤー(第37章で当たり判定と重力が付く) / the player (chapter 37 adds collision and gravity) + Vec3 position, prevPosition; + Vec3 velocity; + float heading = 0.0f, prevHeading = 0.0f; // カメラのyawと同じ決まり / same convention as the camera yaw + CharacterPose pose; + float time = 0.0f; + bool inspect = false; // C:カメラだけ回す(キャラクターを前から見る) / C: turn only the camera (to see + // the character from the front) + bool cameraCollision = true; // K:カメラの当たり判定 / camera collision + bool culling = true; // F4:視錐台カリング / frustum culling + bool posing = true; // P:手続き的な姿勢 / procedural pose + float drawAlpha = 1.0f; // drawの補間の割合 / draw's interpolation factor + LevelDrawStats levelStats, shadowStats; +}; diff --git a/games/tps/src/renderer.cc b/games/tps/src/renderer.cc new file mode 100644 index 0000000..40f6244 --- /dev/null +++ b/games/tps/src/renderer.cc @@ -0,0 +1,164 @@ +#include "renderer.hh" + +#include "engine/shapes.hh" + +#include +#include + +FragmentCounter::FragmentCounter() { glCreateQueries(GL_SAMPLES_PASSED, kQueries, queries); } + +FragmentCounter::~FragmentCounter() { glDeleteQueries(kQueries, queries); } + +void FragmentCounter::begin() { + if (pending[next]) return; // 前の結果がまだ:今回は数えない / previous result not read yet: skip + glBeginQuery(GL_SAMPLES_PASSED, queries[next]); + running = true; +} + +void FragmentCounter::end() { + if (!running) return; + glEndQuery(GL_SAMPLES_PASSED); + pending[next] = true; + next = (next + 1) % kQueries; + running = false; +} + +long long FragmentCounter::latest() { + for (int i = 0; i < kQueries; ++i) { + int k = (next + i) % kQueries; // 古い順 / oldest first + if (!pending[k]) continue; + GLint ready = 0; + glGetQueryObjectiv(queries[k], GL_QUERY_RESULT_AVAILABLE, &ready); + if (!ready) continue; + GLuint64 v = 0; + glGetQueryObjectui64v(queries[k], GL_QUERY_RESULT, &v); + value = static_cast(v); + pending[k] = false; + } + return value; +} + +Mat4 FrameView::view() const { return lookAt(eye, eye + forward, {0.0f, 1.0f, 0.0f}); } +Mat4 FrameView::projection() const { return perspectiveGl(fovY, aspect, nearPlane, farPlane); } + +std::unique_ptr Renderer::create(int width, int height, const RenderSettings &settings) { + std::unique_ptr r(new Renderer()); + r->settings = settings; + r->pbr = Shader::load("engine/shaders/phong.vert", "engine/shaders/pbr.frag"); + r->pbrInstanced = Shader::load("games/tps/shaders/instanced.vert", "engine/shaders/pbr.frag"); + r->shadow = Shader::load("engine/shaders/shadow.vert", "engine/shaders/shadow.frag"); + r->unlit = Shader::load("engine/shaders/unlit.vert", "engine/shaders/unlit.frag"); + r->skybox = Shader::load("engine/shaders/skybox.vert", "engine/shaders/skybox.frag"); + // 空は色の画像なのでsRGB(第21章) / the sky is a color image: sRGB (chapter 21) + r->sky = Cubemap::loadDirectory("assets/textures/sky", ".png", true); + if (!r->pbr || !r->pbrInstanced || !r->shadow || !r->unlit || !r->skybox || !r->sky) return nullptr; + // 新しいプログラムも含めて、全部のブロックの大きさをC++の構造体と比べる(第19章からの決まり) + // Check every block of every program (including the new one) against the C++ structs (the rule since chapter 19) + for (const Shader *s : {&*r->pbr, &*r->pbrInstanced, &*r->shadow, &*r->unlit, &*r->skybox}) + if (!s->checkUniformBlock("Camera", sizeof(CameraBlock)) || !s->checkUniformBlock("Lights", sizeof(LightsBlock)) || + !s->checkUniformBlock("Post", sizeof(PostBlock)) || !s->checkUniformBlock("Shadow", sizeof(ShadowBlock))) + return nullptr; + + // IBLを作る前にシームレスなフィルタリング(第18・24章) / seamless filtering before building the IBL (ch. 18, 24) + glEnable(GL_TEXTURE_CUBE_MAP_SEAMLESS); + r->ibl = Ibl::build(*r->sky); + r->shadowMap.emplace(settings.shadowMapSize); + r->post = PostChain::create(width, height, settings.post); + if (!r->ibl || !r->shadowMap->complete() || !r->post) return nullptr; + + const unsigned char whitePixel[4] = {255, 255, 255, 255}; + r->white = Texture2D::fromPixels(whitePixel, 1, 1, {.flipY = false, .mipmaps = false}); + r->cube = makeCube(); + return r; +} + +void Renderer::beginFrame(const FrameView &view, const LightSet &lights) { + current = view; + sunDirection = lights.directional.direction; + CameraBlock camera; + camera.view = view.view(); + camera.proj = view.projection(); + camera.viewPos = view.eye; + camera.time = view.time; + cameraUbo.update(camera); + lightsUbo.update(lights.toBlock()); + cameraFrustum = Frustum::fromMatrix(camera.proj * camera.view); + post->settings.exposure = std::exp2(exposureEv); + post->settings.bloomStrength = 0.08f; +} + +bool Renderer::beginShadows() { + // 光の箱をカメラの視錐台の0.1〜shadowDistance mを囲む球に合わせる(第23章のJ、エンジンのfrustumSphere)。 + // 球なのでカメラが回っても箱の大きさは同じ、中心はテクセル単位で動く → 影の縁がちらつかない + // Fit the light box to the sphere around 0.1..shadowDistance m of the camera frustum (chapter 23's J, the engine's + // frustumSphere). A sphere keeps the box size constant while the camera turns, and its center moves in whole texels: + // shadow edges do not shimmer + BoundingSphere fit = frustumSphere(current.eye, current.forward, current.fovY, current.aspect, current.nearPlane, + settings.shadowDistance); + shadowTimer.begin(); + bool draw = shadowMap->begin(sunDirection, fit, ShadowBias{}, ShadowFilter::Pcf3x3, settings.shadows); + lightBox = Frustum::fromMatrix(shadowMap->block().lightSpace); + if (draw) { + shadow->use(); + shadow->set("uAlphaMask", 0); + } else { + shadowTimer.end(); + } + return draw; +} + +void Renderer::endShadows() { + shadowTimer.end(); + glEnable(GL_CULL_FACE); + glCullFace(GL_BACK); +} + +void Renderer::setFrameUniforms(const Shader &s) const { + s.set("uViewMode", 0); + s.set("uEnvironmentTint", Vec3{1.0f, 1.0f, 1.0f}); + s.set("uLighting", 0); +} + +void Renderer::beginScene() { + shadowMap->end(); // 深度テクスチャをユニット5へ(影を切っていてもUBOが「影なし」と言う) / depth → unit 5 + sceneTimer.begin(); + post->beginScene(); + sceneFragments.begin(); + glEnable(GL_DEPTH_TEST); + glDepthFunc(GL_LESS); + glDepthMask(GL_TRUE); + glEnable(GL_CULL_FACE); + glDisable(GL_BLEND); + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); + sky->bind(3); + ibl->bind(); + setFrameUniforms(*pbr); + setFrameUniforms(*pbrInstanced); +} + +void Renderer::drawSky() { + glDepthFunc(GL_LEQUAL); + glDisable(GL_CULL_FACE); + skybox->use(); + skybox->set("uEnvironmentTint", Vec3{1.0f, 1.0f, 1.0f}); + cube.draw(); + glEnable(GL_CULL_FACE); + glDepthFunc(GL_LESS); +} + +void Renderer::endScene() { + sceneFragments.end(); + post->endScene(); + sceneTimer.end(); +} + +void Renderer::present(int windowWidth, int windowHeight) { + postTimer.begin(); + post->present(windowWidth, windowHeight, 0); + postTimer.end(); + if (std::optional ms = shadowTimer.latestMs()) timings.shadowMs = *ms; + if (std::optional ms = sceneTimer.latestMs()) timings.sceneMs = *ms; + if (std::optional ms = postTimer.latestMs()) timings.postMs = *ms; + if (!settings.shadows) timings.shadowMs = 0.0; + timings.sceneFragments = sceneFragments.latest(); +} diff --git a/games/tps/src/renderer.hh b/games/tps/src/renderer.hh new file mode 100644 index 0000000..5adbb5e --- /dev/null +++ b/games/tps/src/renderer.hh @@ -0,0 +1,144 @@ +// TPSの3Dのフレーム(第36章):第23・24章の流れをエンジンの部品(ShadowMap・PostChain・Ibl)で組む。 +// 1. 影:太陽の箱をカメラの視錐台の手前20 mに合わせる(レベルは第23章の場面より大きい) +// 2. 場面:HDRのFBOに、空・IBL・PBR(pbr.frag)・影で描く +// 3. 後処理:ブルーム、露出、トーンマッピング、sRGB → 画面 +// The TPS's 3D frame (chapter 36): the chapter 23/24 pipeline built from the engine's pieces (ShadowMap, PostChain, +// Ibl): +// 1. shadows: the sun's box is fitted to the first 20 m of the camera frustum (the level is bigger than the +// chapter 23 scene) +// 2. scene: into the HDR FBO with the sky, IBL, PBR (pbr.frag) and shadows +// 3. post: bloom, exposure, tone mapping, sRGB → the screen +#pragma once + +#include "frustum.hh" + +#include "engine/cubemap.hh" +#include "engine/gpu_timer.hh" +#include "engine/ibl.hh" +#include "engine/lights.hh" +#include "engine/mesh.hh" +#include "engine/renderer3d.hh" +#include "engine/shader.hh" +#include "engine/texture.hh" +#include "engine/uniforms.hh" + +#include +#include + +// このフレームのカメラ / this frame's camera +struct FrameView { + Vec3 eye; + Vec3 forward; // 単位ベクトル / unit vector + float fovY = radians(55.0f); + float aspect = 16.0f / 9.0f; + float nearPlane = 0.1f, farPlane = 120.0f; + float time = 0.0f; // シェーダーのuTime / the shaders' uTime + + Mat4 view() const; + Mat4 projection() const; +}; + +// 速さと見た目の兼ね合い(llvmpipeでも動くように既定は軽め) / speed vs. quality (light defaults so that llvmpipe +// copes) +struct RenderSettings { + int shadowMapSize = 2048; + float shadowDistance = 20.0f; // 影を付ける範囲(カメラからm) / shadows cover this far from the camera (m) + bool shadows = true; + // MSAAなし、R11F_G11F_B10F(RGBA16Fの半分の大きさ)、ブルーム3組 / no MSAA, R11F_G11F_B10F (half the size of + // RGBA16F), 3 bloom pass pairs + PostChainSettings post = {.samples = 0, .format = GL_R11F_G11F_B10F, .bloomPasses = 3}; +}; + +// 深度テストを通ったフラグメントを数えるクエリ(GL_SAMPLES_PASSED、遮蔽クエリ)。GpuTimerと同じく4つを順に使い、 +// 結果を待たない。llvmpipeの時間は他の処理で大きく揺れるが、この数は毎回同じ:1フレームの重さの正直な目安 +// A query counting the fragments that pass the depth test (GL_SAMPLES_PASSED, an occlusion query). Like GpuTimer it +// cycles through 4 queries and never waits. llvmpipe's times swing with other load, but this count is the same every +// run: an honest measure of a frame's weight +class FragmentCounter { +public: + FragmentCounter(); + ~FragmentCounter(); + FragmentCounter(const FragmentCounter &) = delete; + FragmentCounter &operator=(const FragmentCounter &) = delete; + void begin(); + void end(); + // 最新の結果(まだなければ前の値) / the latest result (the previous one while none is ready) + long long latest(); + +private: + static constexpr int kQueries = 4; + GLuint queries[kQueries] = {}; + bool pending[kQueries] = {}; + int next = 0; + bool running = false; + long long value = 0; +}; + +// パスごとの時間(ms)。llvmpipeではGPUの時間ではなく、CPUがラスタライズした時間 / per-pass times (ms). On llvmpipe +// these are the CPU rasterizer's times, not GPU times +struct RenderTimings { + double shadowMs = 0.0, sceneMs = 0.0, postMs = 0.0; + long long sceneFragments = 0; // 場面のパスで深度テストを通ったフラグメント / scene-pass fragments that passed depth +}; + +class Renderer { +public: + // シェーダー・空・IBL・影の地図・後処理を用意する。GpuTimerなどが動かせないので、ヒープに作って返す + // Loads the shaders, the sky, the IBL, the shadow map and the post chain. Returned on the heap (GpuTimer and the + // UBOs are not movable) + static std::unique_ptr create(int width, int height, const RenderSettings &settings = {}); + Renderer(const Renderer &) = delete; + Renderer &operator=(const Renderer &) = delete; + + // UBO(カメラ・光・後処理の設定)を書く / writes the UBOs (camera, lights, post settings) + void beginFrame(const FrameView &view, const LightSet &lights); + // 影のパスの始まり:trueなら影を落とす物をshadowシェーダー+Model::drawDepthで描き、endShadowsを呼ぶ + // Starts the shadow pass: if it returns true, draw the casters with the shadow shader + Model::drawDepth, then call + // endShadows + bool beginShadows(); + void endShadows(); + // 光の箱(影の地図に入る範囲)の視錐台:影のパスのカリング用 / the light box as a frustum: culling for the shadow pass + const Frustum &lightFrustum() const { return lightBox; } + // カメラの視錐台 / the camera's frustum + const Frustum &viewFrustum() const { return cameraFrustum; } + + // 場面のパス:HDRのFBOに切り替え、クリアし、空とIBLを繋ぐ / scene pass: binds the HDR FBO, clears, binds sky + IBL + void beginScene(); + // 空(不透明な物の後、半透明の前) / the sky box (after the opaque objects, before the transparent ones) + void drawSky(); + // 解決とブルーム / resolve and bloom + void endScene(); + // 画面へ(後処理)。この後は既定のフレームバッファ / to the screen (post); afterwards the default framebuffer is bound + void present(int windowWidth, int windowHeight); + void resize(int width, int height) { post->resize(width, height); } + + // ゲームが描くのに使うもの / what the game draws with + std::optional pbr; // phong.vert + pbr.frag:一つずつ描く物 / single objects + std::optional pbrInstanced; // instanced.vert + pbr.frag:レベルの部品 / level pieces + std::optional shadow; // shadow.vert + shadow.frag + std::optional unlit; // 光らない一色(デバッグの箱) / unlit color (debug boxes) + Texture2D white; + Mesh cube; // 1 × 1 × 1、中心が原点 / centered unit cube + + RenderSettings settings; + RenderTimings timings; // 数フレーム遅れの値 / values a few frames old + float exposureEv = 0.0f; + float shadowTexelMm() const { return 1000.0f * shadowMap->metresPerTexel(); } + +private: + Renderer() = default; + void setFrameUniforms(const Shader &s) const; + + std::optional skybox; + std::optional sky; + std::optional ibl; + std::optional shadowMap; + std::optional post; + UniformBuffer cameraUbo{kCameraBinding}; + UniformBuffer lightsUbo{kLightsBinding}; + GpuTimer shadowTimer, sceneTimer, postTimer; + FragmentCounter sceneFragments; + FrameView current; + Vec3 sunDirection = {-0.5f, -1.0f, -0.35f}; + Frustum lightBox, cameraFrustum; +}; diff --git a/games/tps/src/third_person_camera.cc b/games/tps/src/third_person_camera.cc new file mode 100644 index 0000000..bf0270d --- /dev/null +++ b/games/tps/src/third_person_camera.cc @@ -0,0 +1,59 @@ +#include "third_person_camera.hh" + +#include +#include + +void ThirdPersonCamera::look(float dxPixels, float dyPixels) { + yaw += dxPixels * sensitivity; + pitch = std::clamp(pitch - dyPixels * sensitivity, radians(-60.0f), radians(50.0f)); +} + +Vec3 ThirdPersonCamera::forward() const { + return {std::cos(pitch) * std::sin(yaw), std::sin(pitch), -std::cos(pitch) * std::cos(yaw)}; +} +Vec3 ThirdPersonCamera::flatForward() const { return {std::sin(yaw), 0.0f, -std::cos(yaw)}; } +Vec3 ThirdPersonCamera::right() const { return {std::cos(yaw), 0.0f, std::sin(yaw)}; } + +// 指数的な近づき方:毎秒rateの割合で目標へ(ステップの長さによらない) / exponential smoothing: approaches the target +// at `rate` per second, independent of the step length +static float approach(float rate, float dt) { return 1.0f - std::exp(-rate * dt); } + +void ThirdPersonCamera::update(Vec3 pivot, std::span solids, float dt) { + // 1. 注視点を追う:水平は速く、上下はゆっくり(ジャンプや段差でカメラが跳ねない) + // 1. follow the pivot: quickly sideways, slowly up and down (jumps and steps do not jolt the camera) + float kxz = approach(25.0f, dt), ky = approach(8.0f, dt); + smoothPivot = {smoothPivot.x + (pivot.x - smoothPivot.x) * kxz, smoothPivot.y + (pivot.y - smoothPivot.y) * ky, + smoothPivot.z + (pivot.z - smoothPivot.z) * kxz}; + side += (shoulderSide - side) * approach(10.0f, dt); + + // 2. 肩へずらす。横に壁があればそこまで / 2. offset to the shoulder, but not into a wall at the side + Vec3 offset = (shoulderOffset * side) * right(); + float offsetLength = length(offset); + shoulderPos = smoothPivot + offset; + if (offsetLength > 1e-4f) { + Ray sideways{smoothPivot, offset / offsetLength}; + if (std::optional hit = sphereCast(sideways, probeRadius, solids, offsetLength)) + shoulderPos = smoothPivot + std::fmax(hit->t - 0.02f, 0.0f) * sideways.direction; + } + + // 3. 肩から後ろへ球を飛ばす。当たったら、その手前までしか下がれない + // 3. cast the sphere backwards from the shoulder. If it hits, the camera may only go back as far as the hit + Ray back{shoulderPos, -forward()}; + float allowed = distance; + std::optional hit = sphereCast(back, probeRadius, solids, distance); + hitWall = hit.has_value(); + if (hit) allowed = std::fmax(hit->t - 0.05f, 0.0f); + + // 4. 寄るときはすぐ(壁の中を映さない)、離れるときはゆっくり(壁を回り込んだ後にカメラが飛ばない) + // 4. move in immediately (never show the inside of a wall), move out slowly (no jump after rounding a corner) + if (allowed < dist) dist = allowed; + else dist += (allowed - dist) * approach(4.0f, dt); + eyePos = shoulderPos + dist * back.direction; +} + +void ThirdPersonCamera::reset(Vec3 pivot, std::span solids) { + smoothPivot = pivot; + side = shoulderSide; + dist = distance; + update(pivot, solids, 0.0f); +} diff --git a/games/tps/src/third_person_camera.hh b/games/tps/src/third_person_camera.hh new file mode 100644 index 0000000..f60538f --- /dev/null +++ b/games/tps/src/third_person_camera.hh @@ -0,0 +1,44 @@ +// 三人称カメラ(第36章):キャラクターの肩越しに、注視点(CameraPivotソケット)の周りを回る。 +// 壁にめり込まないように、注視点から後ろへ球を飛ばし(スフィアキャスト)、当たったら手前に寄せる +// The third-person camera (chapter 36): over the character's shoulder, orbiting the pivot (the CameraPivot socket). +// To stay out of walls it casts a sphere backwards from the pivot (a sphere cast) and moves in where it hits +#pragma once + +#include "collision3d.hh" + +#include + +class ThirdPersonCamera { +public: + float yaw = 0.0f; // ラジアン:0で−Zを向き、正で右へ回る(エンジンのCameraと同じ) / radians: 0 looks + // down −Z, positive turns right (like the engine's Camera) + float pitch = radians(-8.0f); // 正で上を向く / positive looks up + float sensitivity = 0.0025f; // ラジアン毎ピクセル / radians per pixel + float distance = 3.6f; // 肩からの距離(何もなければ) / distance from the shoulder (when nothing is in the way) + float shoulderOffset = 0.7f; // 右へのずらし(m) / sideways offset (m) + float shoulderSide = 1.0f; // +1 = 右肩、−1 = 左肩(Q) / +1 = right shoulder, −1 = left (Q) + float probeRadius = 0.2f; // 飛ばす球の半径(ニアクリップ面より大きく) / cast sphere radius (> the near plane) + float fovY = radians(55.0f); + + // マウスで回す(1フレームに一度) / turn with the mouse (once per frame) + void look(float dxPixels, float dyPixels); + // 1ステップ:注視点を追い、肩へずらし、後ろへ球を飛ばして距離を決める / one step: follow the pivot, offset to the + // shoulder, cast backwards and decide the distance + void update(Vec3 pivot, std::span solids, float dt); + // 初期化:今すぐpivotの後ろへ(なめらかにしない) / snap behind pivot now (no smoothing) + void reset(Vec3 pivot, std::span solids); + + Vec3 forward() const; // 見ている向き / view direction + Vec3 flatForward() const; // 水平の前 / horizontal forward + Vec3 right() const; // 水平の右 / horizontal right + Vec3 eye() const { return eyePos; } + Vec3 shoulder() const { return shoulderPos; } + float currentDistance() const { return dist; } + bool blocked() const { return hitWall; } // 今のステップで壁に当たって寄せたか / pulled in by a wall this step + +private: + Vec3 smoothPivot, shoulderPos, eyePos; + float dist = 3.6f; + float side = 1.0f; + bool hitWall = false; +};