summaryrefslogtreecommitdiff
path: root/src/renderer/render.c
diff options
context:
space:
mode:
authoromnisci3nce <17525998+omnisci3nce@users.noreply.github.com>2024-04-07 21:46:51 +1000
committeromnisci3nce <17525998+omnisci3nce@users.noreply.github.com>2024-04-07 21:46:51 +1000
commit61d96cf09e2e125f36a94a4c64ed5682fda0df1c (patch)
treeaa79fe48e1a0800bec0157460a4adf7d19d88077 /src/renderer/render.c
parent42924fe7b32e93bf55ce034467ceb52e0436c303 (diff)
its bending but not deforming as expected, looks like rotating around model origin
Diffstat (limited to 'src/renderer/render.c')
-rw-r--r--src/renderer/render.c14
1 files changed, 13 insertions, 1 deletions
diff --git a/src/renderer/render.c b/src/renderer/render.c
index 42f6ee4..d7e2d48 100644
--- a/src/renderer/render.c
+++ b/src/renderer/render.c
@@ -1,6 +1,7 @@
#include <assert.h>
#include <stdlib.h>
#include <string.h>
+#include "animation.h"
#include "maths_types.h"
#include "mem.h"
#define STB_IMAGE_IMPLEMENTATION
@@ -192,8 +193,19 @@ void draw_skinned_mesh(renderer* ren, mesh* mesh, transform tf, material* mat, m
// for now assume correct ordering
mat4* bone_transforms = malloc(n_bones * sizeof(mat4));
+ mat4 parent = mat4_ident();
for (int bone_i = 0; bone_i < n_bones; bone_i++) {
- bone_transforms[bone_i] = mat4_ident();
+ transform tf = mesh->bones->data[bone_i].transform_components;
+ mat4 local = transform_to_mat(&mesh->bones->data[bone_i].transform_components);
+ bone_transforms[bone_i] = mat4_mult(parent, local);
+ parent = bone_transforms[bone_i];
+ }
+
+ // premultiply the inverses
+ for (int bone_i = 0; bone_i < n_bones; bone_i++) {
+ joint j = mesh->bones->data[bone_i];
+ // bone_transforms[bone_i] = mat4_mult(bone_transforms[bone_i], j.inverse_bind_matrix);
+ bone_transforms[bone_i] = mat4_mult(bone_transforms[bone_i], j.inverse_bind_matrix);
}
glUniformMatrix4fv(glGetUniformLocation(lighting_shader.program_id, "boneMatrices"), n_bones,