Implement transform interpolation for slower TPS than FPS
This commit is contained in:
parent
78ef93bcf5
commit
4a53c24e9c
|
@ -154,20 +154,10 @@ namespace simpleengine::gfx {
|
||||||
bool Renderer::render_job(const float& interpolate_alpha, const RenderingJob &job) {
|
bool Renderer::render_job(const float& interpolate_alpha, const RenderingJob &job) {
|
||||||
Mesh *mesh = job.rendering_mesh;
|
Mesh *mesh = job.rendering_mesh;
|
||||||
|
|
||||||
/* glm::mat4 transform_mat = job.transform_mat * interpolate_alpha +
|
// Iterpolate between transforms
|
||||||
job.last_transform_mat * (1.f - interpolate_alpha); */
|
|
||||||
|
|
||||||
//glm::mat4 transform_mat = lerp(job.transform_mat, job.last_transform_mat, interpolate_alpha);
|
|
||||||
glm::mat4 transform_mat = lerp(job.last_transform_mat, job.transform_mat, interpolate_alpha);
|
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", transform_mat);
|
||||||
//shader.set_uniform_matrix_4f("u_transform_matrix", job.transform_mat);
|
|
||||||
|
|
||||||
std::optional<Material> &material = mesh->material;
|
std::optional<Material> &material = mesh->material;
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,9 @@
|
||||||
#include "ecs/entity.h"
|
#include "ecs/entity.h"
|
||||||
#include "gfx/renderer.h"
|
#include "gfx/renderer.h"
|
||||||
|
|
||||||
|
#include <glm/gtx/string_cast.hpp>
|
||||||
|
#include <stdexcept>
|
||||||
|
|
||||||
namespace simpleengine {
|
namespace simpleengine {
|
||||||
Scene::Scene(std::shared_ptr<gfx::Renderer> renderer) : renderer(renderer) {
|
Scene::Scene(std::shared_ptr<gfx::Renderer> renderer) : renderer(renderer) {
|
||||||
|
|
||||||
|
@ -16,6 +19,11 @@ namespace simpleengine {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Scene::update(const float& delta_time) {
|
void Scene::update(const float& delta_time) {
|
||||||
|
// Update the last transform matrix
|
||||||
|
registry.view<TransformComponent>().each([this, &delta_time](TransformComponent& transform) {
|
||||||
|
transform.last_transform_matrix = transform.transform_matrix;
|
||||||
|
});
|
||||||
|
|
||||||
// Rotate the model
|
// Rotate the model
|
||||||
registry.view<TransformComponent, RotatingComponent>().each([this, &delta_time](TransformComponent& transform, RotatingComponent& rotating) {
|
registry.view<TransformComponent, RotatingComponent>().each([this, &delta_time](TransformComponent& transform, RotatingComponent& rotating) {
|
||||||
transform.rotate(rotating.rate * delta_time, rotating.rotation_axis);
|
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));
|
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));
|
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);
|
renderer->render(interpolate_alpha, frame_time);
|
||||||
|
|
Loading…
Reference in New Issue