diff --git a/src/gfx/renderer.cpp b/src/gfx/renderer.cpp index 514ec33..764e07a 100644 --- a/src/gfx/renderer.cpp +++ b/src/gfx/renderer.cpp @@ -154,20 +154,10 @@ namespace simpleengine::gfx { bool Renderer::render_job(const float& interpolate_alpha, const RenderingJob &job) { Mesh *mesh = job.rendering_mesh; - /* glm::mat4 transform_mat = job.transform_mat * interpolate_alpha + - job.last_transform_mat * (1.f - interpolate_alpha); */ - - //glm::mat4 transform_mat = lerp(job.transform_mat, job.last_transform_mat, interpolate_alpha); + // Iterpolate between transforms glm::mat4 transform_mat = lerp(job.last_transform_mat, job.transform_mat, interpolate_alpha); - std::cout << "Last transform: " << glm::to_string(job.last_transform_mat) << std::endl << - "Current Transform: " << glm::to_string(job.transform_mat) << std::endl << - "Lerp: " << glm::to_string(transform_mat) << std::endl << std::endl; - - //std::cout << "Current: " << job.transform_mat[3] - shader.set_uniform_matrix_4f("u_transform_matrix", transform_mat); - //shader.set_uniform_matrix_4f("u_transform_matrix", job.transform_mat); std::optional &material = mesh->material; diff --git a/src/scene.cpp b/src/scene.cpp index 875acd8..20630ff 100644 --- a/src/scene.cpp +++ b/src/scene.cpp @@ -6,6 +6,9 @@ #include "ecs/entity.h" #include "gfx/renderer.h" +#include +#include + namespace simpleengine { Scene::Scene(std::shared_ptr renderer) : renderer(renderer) { @@ -16,6 +19,11 @@ namespace simpleengine { } void Scene::update(const float& delta_time) { + // Update the last transform matrix + registry.view().each([this, &delta_time](TransformComponent& transform) { + transform.last_transform_matrix = transform.transform_matrix; + }); + // Rotate the model registry.view().each([this, &delta_time](TransformComponent& transform, RotatingComponent& rotating) { transform.rotate(rotating.rate * delta_time, rotating.rotation_axis); @@ -32,7 +40,6 @@ namespace simpleengine { } renderer->queue_job(gfx::RenderingJob(rendering_type, mesh, transform.last_transform_matrix, transform.transform_matrix)); - transform.last_transform_matrix = transform.transform_matrix; // Update last transform } }); @@ -43,7 +50,6 @@ namespace simpleengine { } renderer->queue_job(gfx::RenderingJob(rendering_type, mesh_component.mesh, transform.last_transform_matrix, transform.transform_matrix)); - transform.last_transform_matrix = transform.transform_matrix; // Update last transform }); renderer->render(interpolate_alpha, frame_time);