diff options
| author | 3gg <3gg@shellblade.net> | 2025-10-30 20:09:14 -0700 |
|---|---|---|
| committer | 3gg <3gg@shellblade.net> | 2025-10-30 20:09:14 -0700 |
| commit | 935094fe0bcb2a7aa0ece67aefef746d7d42862e (patch) | |
| tree | 7f4de5fb4a531ceb4c61aaa4fc8809377945efcf /src/plugins/viewer.c | |
| parent | 02b70c053cc5f896e8a5105245bf8dd174643ae7 (diff) | |
Camera and animation changes
Diffstat (limited to 'src/plugins/viewer.c')
| -rw-r--r-- | src/plugins/viewer.c | 33 |
1 files changed, 12 insertions, 21 deletions
diff --git a/src/plugins/viewer.c b/src/plugins/viewer.c index b05cfe1..6853065 100644 --- a/src/plugins/viewer.c +++ b/src/plugins/viewer.c | |||
| @@ -1,5 +1,6 @@ | |||
| 1 | #include "plugin.h" | 1 | #include "plugin.h" |
| 2 | 2 | ||
| 3 | #include <gfx/animation.h> | ||
| 3 | #include <gfx/app.h> | 4 | #include <gfx/app.h> |
| 4 | #include <gfx/asset.h> | 5 | #include <gfx/asset.h> |
| 5 | #include <gfx/gfx.h> | 6 | #include <gfx/gfx.h> |
| @@ -12,8 +13,6 @@ | |||
| 12 | #include <math/spatial3.h> | 13 | #include <math/spatial3.h> |
| 13 | #include <math/vec2.h> | 14 | #include <math/vec2.h> |
| 14 | 15 | ||
| 15 | #include <log/log.h> | ||
| 16 | |||
| 17 | #include <stdlib.h> | 16 | #include <stdlib.h> |
| 18 | 17 | ||
| 19 | // Skybox. | 18 | // Skybox. |
| @@ -46,7 +45,7 @@ static const char* GIRL = | |||
| 46 | static const char* BOXES = | 45 | static const char* BOXES = |
| 47 | "/home/jeanne/Nextcloud/assets/models/boxes/boxes.gltf"; | 46 | "/home/jeanne/Nextcloud/assets/models/boxes/boxes.gltf"; |
| 48 | 47 | ||
| 49 | #define DEFAULT_SCENE_FILE SPONZA | 48 | #define DEFAULT_SCENE_FILE GIRL |
| 50 | 49 | ||
| 51 | static const bool RenderBoundingBoxes = false; | 50 | static const bool RenderBoundingBoxes = false; |
| 52 | static const R DefaultCameraSpeed = (R)6.0; | 51 | static const R DefaultCameraSpeed = (R)6.0; |
| @@ -72,7 +71,7 @@ typedef struct CameraController { | |||
| 72 | typedef struct State { | 71 | typedef struct State { |
| 73 | Scene* scene; | 72 | Scene* scene; |
| 74 | Model* model; | 73 | Model* model; |
| 75 | SceneCamera* camera; | 74 | Camera camera; |
| 76 | CameraController camera_controller; | 75 | CameraController camera_controller; |
| 77 | } State; | 76 | } State; |
| 78 | 77 | ||
| @@ -115,9 +114,6 @@ static Model* load_model(Game* game, State* state, const char* scene_filepath) { | |||
| 115 | assert(state); | 114 | assert(state); |
| 116 | assert(state->scene); | 115 | assert(state->scene); |
| 117 | 116 | ||
| 118 | Camera* camera = gfx_get_camera_camera(state->camera); | ||
| 119 | spatial3_set_position(&camera->spatial, vec3_make(0, 0, 2)); | ||
| 120 | |||
| 121 | SceneNode* root = gfx_get_scene_root(state->scene); | 117 | SceneNode* root = gfx_get_scene_root(state->scene); |
| 122 | SceneNode* sky_light_node = load_skyquad(game->gfx, root); | 118 | SceneNode* sky_light_node = load_skyquad(game->gfx, root); |
| 123 | if (!sky_light_node) { | 119 | if (!sky_light_node) { |
| @@ -156,9 +152,6 @@ bool init(Game* game, State** pp_state) { | |||
| 156 | if (!((state->scene = gfx_make_scene()))) { | 152 | if (!((state->scene = gfx_make_scene()))) { |
| 157 | goto cleanup; | 153 | goto cleanup; |
| 158 | } | 154 | } |
| 159 | if (!((state->camera = gfx_make_camera()))) { | ||
| 160 | goto cleanup; | ||
| 161 | } | ||
| 162 | 155 | ||
| 163 | state->model = load_model(game, state, scene_filepath); | 156 | state->model = load_model(game, state, scene_filepath); |
| 164 | if (!state->model) { | 157 | if (!state->model) { |
| @@ -178,8 +171,10 @@ bool init(Game* game, State** pp_state) { | |||
| 178 | .name = "Jumping-jack-arms-mid", .loop = true});*/ | 171 | .name = "Jumping-jack-arms-mid", .loop = true});*/ |
| 179 | } | 172 | } |
| 180 | 173 | ||
| 181 | spatial3_set_position( | 174 | state->camera = camera_perspective( |
| 182 | &gfx_get_camera_camera(state->camera)->spatial, DefaultCameraPosition); | 175 | /*fovy=*/90.0 * TO_RAD, /*aspect=*/16.0 / 9.0, |
| 176 | /*near=*/0.1, /*far=*/1000); | ||
| 177 | spatial3_set_position(&state->camera.spatial, DefaultCameraPosition); | ||
| 183 | 178 | ||
| 184 | state->camera_controller.camera_speed = DefaultCameraSpeed; | 179 | state->camera_controller.camera_speed = DefaultCameraSpeed; |
| 185 | state->camera_controller.mouse_sensitivity = DefaultMouseSensitivity; | 180 | state->camera_controller.mouse_sensitivity = DefaultMouseSensitivity; |
| @@ -198,7 +193,6 @@ cleanup: | |||
| 198 | void shutdown(Game* game, State* state) { | 193 | void shutdown(Game* game, State* state) { |
| 199 | assert(game); | 194 | assert(game); |
| 200 | if (state) { | 195 | if (state) { |
| 201 | gfx_destroy_camera(&state->camera); | ||
| 202 | gfx_destroy_scene(&state->scene); | 196 | gfx_destroy_scene(&state->scene); |
| 203 | // State freed by plugin engine. | 197 | // State freed by plugin engine. |
| 204 | } | 198 | } |
| @@ -251,7 +245,6 @@ void update(Game* game, State* state, double t, double dt) { | |||
| 251 | assert(game->app); | 245 | assert(game->app); |
| 252 | assert(state); | 246 | assert(state); |
| 253 | assert(state->scene); | 247 | assert(state->scene); |
| 254 | assert(state->camera); | ||
| 255 | 248 | ||
| 256 | double mouse_x, mouse_y; | 249 | double mouse_x, mouse_y; |
| 257 | gfx_app_get_mouse_position(game->app, &mouse_x, &mouse_y); | 250 | gfx_app_get_mouse_position(game->app, &mouse_x, &mouse_y); |
| @@ -261,7 +254,7 @@ void update(Game* game, State* state, double t, double dt) { | |||
| 261 | make_camera_command_from_input(game->app); | 254 | make_camera_command_from_input(game->app); |
| 262 | update_camera( | 255 | update_camera( |
| 263 | &state->camera_controller, (R)dt, mouse_position, camera_command, | 256 | &state->camera_controller, (R)dt, mouse_position, camera_command, |
| 264 | &gfx_get_camera_camera(state->camera)->spatial); | 257 | &state->camera.spatial); |
| 265 | 258 | ||
| 266 | // const vec3 orbit_point = vec3_make(0, 2, 0); | 259 | // const vec3 orbit_point = vec3_make(0, 2, 0); |
| 267 | // Camera* camera = gfx_get_camera_camera(state->camera); | 260 | // Camera* camera = gfx_get_camera_camera(state->camera); |
| @@ -271,7 +264,7 @@ void update(Game* game, State* state, double t, double dt) { | |||
| 271 | // /*azimuth=*/(R)(t * 0.5), /*zenith=*/0); | 264 | // /*azimuth=*/(R)(t * 0.5), /*zenith=*/0); |
| 272 | // spatial3_lookat(&camera->spatial, orbit_point); | 265 | // spatial3_lookat(&camera->spatial, orbit_point); |
| 273 | 266 | ||
| 274 | gfx_update(state->scene, state->camera, (R)t); | 267 | gfx_update(state->scene, &state->camera, (R)t); |
| 275 | } | 268 | } |
| 276 | 269 | ||
| 277 | /// Render the bounding boxes of all scene objects. | 270 | /// Render the bounding boxes of all scene objects. |
| @@ -346,7 +339,7 @@ static void render_bounding_boxes(const Game* game, const State* state) { | |||
| 346 | gfx_set_polygon_offset(gfxcore, -1.5f, -1.0f); | 339 | gfx_set_polygon_offset(gfxcore, -1.5f, -1.0f); |
| 347 | 340 | ||
| 348 | gfx_imm_start(imm); | 341 | gfx_imm_start(imm); |
| 349 | gfx_llr_set_camera(llr, gfx_get_camera_camera(state->camera)); | 342 | gfx_llr_set_camera(llr, &state->camera); |
| 350 | gfx_imm_set_colour(imm, vec4_make(0.3f, 0.3f, 0.9f, 0.1f)); | 343 | gfx_imm_set_colour(imm, vec4_make(0.3f, 0.3f, 0.9f, 0.1f)); |
| 351 | render_bounding_boxes_rec( | 344 | render_bounding_boxes_rec( |
| 352 | llr, imm, anima, &id, gfx_get_scene_root(state->scene)); | 345 | llr, imm, anima, &id, gfx_get_scene_root(state->scene)); |
| @@ -362,7 +355,6 @@ void render(const Game* game, const State* state) { | |||
| 362 | assert(game); | 355 | assert(game); |
| 363 | assert(game->gfx); | 356 | assert(game->gfx); |
| 364 | assert(state->scene); | 357 | assert(state->scene); |
| 365 | assert(state->camera); | ||
| 366 | 358 | ||
| 367 | Renderer* renderer = gfx_get_renderer(game->gfx); | 359 | Renderer* renderer = gfx_get_renderer(game->gfx); |
| 368 | assert(renderer); | 360 | assert(renderer); |
| @@ -370,7 +362,7 @@ void render(const Game* game, const State* state) { | |||
| 370 | gfx_render_scene( | 362 | gfx_render_scene( |
| 371 | renderer, &(RenderSceneParams){.mode = RenderDefault, | 363 | renderer, &(RenderSceneParams){.mode = RenderDefault, |
| 372 | .scene = state->scene, | 364 | .scene = state->scene, |
| 373 | .camera = state->camera}); | 365 | .camera = &state->camera}); |
| 374 | 366 | ||
| 375 | if (RenderBoundingBoxes) { | 367 | if (RenderBoundingBoxes) { |
| 376 | render_bounding_boxes(game, state); | 368 | render_bounding_boxes(game, state); |
| @@ -387,6 +379,5 @@ void resize(Game* game, State* state, int width, int height) { | |||
| 387 | const R far = 1000; | 379 | const R far = 1000; |
| 388 | const mat4 projection = mat4_perspective(fovy, aspect, near, far); | 380 | const mat4 projection = mat4_perspective(fovy, aspect, near, far); |
| 389 | 381 | ||
| 390 | Camera* camera = gfx_get_camera_camera(state->camera); | 382 | state->camera.projection = projection; |
| 391 | camera->projection = projection; | ||
| 392 | } | 383 | } |
