From e5495790aeba905505152ad3b6690f459a44df03 Mon Sep 17 00:00:00 2001 From: omniscient <17525998+omnisci3nce@users.noreply.github.com> Date: Fri, 5 Apr 2024 00:28:24 +1100 Subject: close. --- examples/gltf_loading/ex_gltf_loading.c | 5 +++++ examples/property_animation/ex_property_animation.c | 19 ++++++++++++++++++- 2 files changed, 23 insertions(+), 1 deletion(-) (limited to 'examples') diff --git a/examples/gltf_loading/ex_gltf_loading.c b/examples/gltf_loading/ex_gltf_loading.c index 867ddb2..1d279eb 100644 --- a/examples/gltf_loading/ex_gltf_loading.c +++ b/examples/gltf_loading/ex_gltf_loading.c @@ -1,8 +1,10 @@ #include +#include "animation.h" #include "camera.h" #include "core.h" #include "loaders.h" +#include "log.h" #include "maths.h" #include "maths_types.h" #include "render.h" @@ -54,6 +56,9 @@ int main() { scene our_scene = { .dir_light = dir_light, .n_point_lights = 4 }; memcpy(&our_scene.point_lights, &point_lights, sizeof(point_light[4])); + animation_clip track = cube->animations->data[0]; + f32 total_time = 0.0; + while (!glfwWindowShouldClose(core->renderer.window)) { currentFrame = glfwGetTime(); deltaTime = currentFrame - lastFrame; diff --git a/examples/property_animation/ex_property_animation.c b/examples/property_animation/ex_property_animation.c index e175b31..0d4a0d7 100644 --- a/examples/property_animation/ex_property_animation.c +++ b/examples/property_animation/ex_property_animation.c @@ -1,5 +1,6 @@ #include +#include "animation.h" #include "camera.h" #include "core.h" #include "input.h" @@ -30,6 +31,10 @@ typedef struct game_state { void update_camera_rotation(input_state* input, game_state* game, camera* cam); int main() { + double currentFrame = glfwGetTime(); + double lastFrame = currentFrame; + double deltaTime; + core* core = core_bringup(); model_handle animated_cube_handle = @@ -67,9 +72,19 @@ int main() { const f32 camera_lateral_speed = 0.2; const f32 camera_zoom_speed = 0.15; + // animation + animation_clip track = cube->animations->data[0]; + f64 total_time = 0.0; + while (!should_exit(core)) { input_update(&core->input); + currentFrame = glfwGetTime(); + deltaTime = currentFrame - lastFrame; + total_time += deltaTime * 0.00001; + f64 t = fmod(total_time * 1000.0, 1.0); + INFO("Total time: %f", t); + vec3 translation = VEC3_ZERO; if (key_is_pressed(KEYCODE_W) || key_is_pressed(KEYCODE_KEY_UP)) { translation = vec3_mult(game.camera.front, camera_zoom_speed); @@ -89,7 +104,9 @@ int main() { render_frame_begin(&core->renderer); mat4 model = mat4_translation(VEC3_ZERO); - transform tf = transform_create(VEC3_ZERO, quat_ident(), 1.0); + quat rot = animation_sample(track.rotation, t).rotation; + // quat rot = quat_ident(); + transform tf = transform_create(VEC3_ZERO, rot, 1.0); draw_model(&core->renderer, &game.camera, cube, tf, &our_scene); -- cgit v1.2.3-70-g09d2