From 935094fe0bcb2a7aa0ece67aefef746d7d42862e Mon Sep 17 00:00:00 2001 From: 3gg <3gg@shellblade.net> Date: Thu, 30 Oct 2025 20:09:14 -0700 Subject: Camera and animation changes --- src/plugins/viewer.c | 33 ++++++++++++--------------------- 1 file changed, 12 insertions(+), 21 deletions(-) (limited to 'src/plugins') 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 @@ #include "plugin.h" +#include #include #include #include @@ -12,8 +13,6 @@ #include #include -#include - #include // Skybox. @@ -46,7 +45,7 @@ static const char* GIRL = static const char* BOXES = "/home/jeanne/Nextcloud/assets/models/boxes/boxes.gltf"; -#define DEFAULT_SCENE_FILE SPONZA +#define DEFAULT_SCENE_FILE GIRL static const bool RenderBoundingBoxes = false; static const R DefaultCameraSpeed = (R)6.0; @@ -72,7 +71,7 @@ typedef struct CameraController { typedef struct State { Scene* scene; Model* model; - SceneCamera* camera; + Camera camera; CameraController camera_controller; } State; @@ -115,9 +114,6 @@ static Model* load_model(Game* game, State* state, const char* scene_filepath) { assert(state); assert(state->scene); - Camera* camera = gfx_get_camera_camera(state->camera); - spatial3_set_position(&camera->spatial, vec3_make(0, 0, 2)); - SceneNode* root = gfx_get_scene_root(state->scene); SceneNode* sky_light_node = load_skyquad(game->gfx, root); if (!sky_light_node) { @@ -156,9 +152,6 @@ bool init(Game* game, State** pp_state) { if (!((state->scene = gfx_make_scene()))) { goto cleanup; } - if (!((state->camera = gfx_make_camera()))) { - goto cleanup; - } state->model = load_model(game, state, scene_filepath); if (!state->model) { @@ -178,8 +171,10 @@ bool init(Game* game, State** pp_state) { .name = "Jumping-jack-arms-mid", .loop = true});*/ } - spatial3_set_position( - &gfx_get_camera_camera(state->camera)->spatial, DefaultCameraPosition); + state->camera = camera_perspective( + /*fovy=*/90.0 * TO_RAD, /*aspect=*/16.0 / 9.0, + /*near=*/0.1, /*far=*/1000); + spatial3_set_position(&state->camera.spatial, DefaultCameraPosition); state->camera_controller.camera_speed = DefaultCameraSpeed; state->camera_controller.mouse_sensitivity = DefaultMouseSensitivity; @@ -198,7 +193,6 @@ cleanup: void shutdown(Game* game, State* state) { assert(game); if (state) { - gfx_destroy_camera(&state->camera); gfx_destroy_scene(&state->scene); // State freed by plugin engine. } @@ -251,7 +245,6 @@ void update(Game* game, State* state, double t, double dt) { assert(game->app); assert(state); assert(state->scene); - assert(state->camera); double mouse_x, mouse_y; 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) { make_camera_command_from_input(game->app); update_camera( &state->camera_controller, (R)dt, mouse_position, camera_command, - &gfx_get_camera_camera(state->camera)->spatial); + &state->camera.spatial); // const vec3 orbit_point = vec3_make(0, 2, 0); // Camera* camera = gfx_get_camera_camera(state->camera); @@ -271,7 +264,7 @@ void update(Game* game, State* state, double t, double dt) { // /*azimuth=*/(R)(t * 0.5), /*zenith=*/0); // spatial3_lookat(&camera->spatial, orbit_point); - gfx_update(state->scene, state->camera, (R)t); + gfx_update(state->scene, &state->camera, (R)t); } /// Render the bounding boxes of all scene objects. @@ -346,7 +339,7 @@ static void render_bounding_boxes(const Game* game, const State* state) { gfx_set_polygon_offset(gfxcore, -1.5f, -1.0f); gfx_imm_start(imm); - gfx_llr_set_camera(llr, gfx_get_camera_camera(state->camera)); + gfx_llr_set_camera(llr, &state->camera); gfx_imm_set_colour(imm, vec4_make(0.3f, 0.3f, 0.9f, 0.1f)); render_bounding_boxes_rec( llr, imm, anima, &id, gfx_get_scene_root(state->scene)); @@ -362,7 +355,6 @@ void render(const Game* game, const State* state) { assert(game); assert(game->gfx); assert(state->scene); - assert(state->camera); Renderer* renderer = gfx_get_renderer(game->gfx); assert(renderer); @@ -370,7 +362,7 @@ void render(const Game* game, const State* state) { gfx_render_scene( renderer, &(RenderSceneParams){.mode = RenderDefault, .scene = state->scene, - .camera = state->camera}); + .camera = &state->camera}); if (RenderBoundingBoxes) { render_bounding_boxes(game, state); @@ -387,6 +379,5 @@ void resize(Game* game, State* state, int width, int height) { const R far = 1000; const mat4 projection = mat4_perspective(fovy, aspect, near, far); - Camera* camera = gfx_get_camera_camera(state->camera); - camera->projection = projection; + state->camera.projection = projection; } -- cgit v1.2.3