# "イルカ本" Chapter 4 を元にした実験 (2026-01-11) ```cpp // render loop while (!glfwWindowShouldClose(window)) { // ... // いろいろなコード // ... int const num_cubes = 20000; for (int i = 0; i < num_cubes; ++i) { float const tf = static_cast(current_time + i); // tf means "time factor" // make cube translation and rotation matrix float const move_scale = (8.0f / 24) * num_cubes * (3.0f / tf) * (tf * 0.003f); // (1) float const tx = sinf(0.35f * tf) * move_scale; float const ty = cosf(0.52f * tf) * move_scale; float const tz = sinf(0.7f * tf) * move_scale * 15.0f; // (2) glm::mat4 t_mat = glm::translate(glm::mat4{1.0f}, glm::vec3{tx, ty, tz}); glm::mat4 r_mat = glm::rotate(glm::mat4{1.0f}, 1.75f * tf, glm::vec3{0.0f, 1.0f, 0.0f}); r_mat = glm::rotate(r_mat, 1.75f * tf, glm::vec3{1.0f, 0.0f, 0.0f}); r_mat = glm::rotate(r_mat, 1.75f * tf, glm::vec3{0.0f, 0.0f, 1.0f}); // ... // いろいろなコード // ... glDrawArrays(GL_TRIANGLES, 0, 36); // 36 means 3 vertices * 2 triangles * 6 faces } glfwSwapBuffers(window); glfwPollEvents(); } ``` 変化 - 主に(1)の部分の値をいじったときの変化の観察。 - (2)も少し変えたりした。 - カメラのZ座標はいい感じなるように適当に変更している。 ファイル名のルール - (1)の`num_cubes`より後ろの部分と、もしあれば、(2)の`move_scale`より後ろ部分を含めている。 - カメラの位置情報は含まれていない。 - 例えば、上のコードの場合 **20260111-dolphin_book_exp__20000_cubes_x_(3.0_div_tf)_x_(tf_x_0.003)_and_tz_x_15.0.webm** というファイル名になっている。