summaryrefslogtreecommitdiff
path: root/src/blu_cat/gra/skeletal_model.cpp
diff options
context:
space:
mode:
authorFrederico Linhares <fred@linhares.blue>2025-09-05 09:55:25 -0300
committerFrederico Linhares <fred@linhares.blue>2025-09-05 09:55:25 -0300
commit6deda4129825b4b77fb7179f43d4bb7a755c4813 (patch)
treec3d85044f53144257de73819bfcb9dc41af45f70 /src/blu_cat/gra/skeletal_model.cpp
parent68761609f3b98bfc99f2164eece12027d5575c0b (diff)
feat Add hierarchy to skeletal meshHEADmaster
Diffstat (limited to 'src/blu_cat/gra/skeletal_model.cpp')
-rw-r--r--src/blu_cat/gra/skeletal_model.cpp40
1 files changed, 23 insertions, 17 deletions
diff --git a/src/blu_cat/gra/skeletal_model.cpp b/src/blu_cat/gra/skeletal_model.cpp
index 4b44910..726b97e 100644
--- a/src/blu_cat/gra/skeletal_model.cpp
+++ b/src/blu_cat/gra/skeletal_model.cpp
@@ -172,30 +172,30 @@ SkeletalModel::~SkeletalModel()
void
SkeletalModel::tick(float delta)
{
- BluCat::GRA::Animation *current_animation =
- &this->skeletal_mesh->animations[this->animation_index];
+ BluCat::GRA::Animation &current_animation =
+ this->skeletal_mesh->animations[this->animation_index];
{ // update time
this->animation_time += delta;
- if(this->animation_time > current_animation->final_time)
+ if(this->animation_time > current_animation.final_time)
{
- this->animation_time -= current_animation->final_time;
+ this->animation_time -= current_animation.final_time;
for(BluCat::GRA::BoneTransform &bone_transform:
- current_animation->bone_transforms)
+ current_animation.bone_transforms)
{
- bone_transform.positions.current_index = 0;
- bone_transform.rotations.current_index = 0;
- bone_transform.scales.current_index = 0;
+ bone_transform.positions.current_index = 0;
+ bone_transform.rotations.current_index = 0;
+ bone_transform.scales.current_index = 0;
}
}
}
- for(int i{0}; i < current_animation->bone_transforms.size(); i++)
+ for(UI16 i{0}; i < current_animation.bone_transforms.size(); i++)
{
- BluCat::GRA::BoneTransform *bone_transform =
- &current_animation->bone_transforms[i];
+ BluCat::GRA::BoneTransform &bone_transform =
+ current_animation.bone_transforms[i];
- auto position{bone_transform->positions.interpolate(
+ auto position{bone_transform.positions.interpolate(
this->animation_time,
[](glm::vec3 frame)
{
@@ -208,7 +208,7 @@ SkeletalModel::tick(float delta)
return glm::translate(glm::mat4(1.0f), final_position);
})};
- auto rotation{bone_transform->rotations.interpolate(
+ auto rotation{bone_transform.rotations.interpolate(
this->animation_time,
[](glm::quat frame)
{
@@ -220,7 +220,7 @@ SkeletalModel::tick(float delta)
previous_frame, next_frame, scale_factor));
})};
- auto scale{bone_transform->scales.interpolate(
+ auto scale{bone_transform.scales.interpolate(
this->animation_time,
[](glm::vec3 frame)
{
@@ -233,9 +233,15 @@ SkeletalModel::tick(float delta)
return glm::scale(glm::mat4(1.0f), scale);
})};
- this->bone_transforms[i] =
- this->skeletal_mesh->bones[i].offset_matrix *
- (position * rotation * scale);
+ auto parent{this->skeletal_mesh->bones[i].parent};
+ auto node_transform{(this->skeletal_mesh->bones[i].offset_matrix *
+ (position * rotation * scale))};
+
+ if(parent == i)
+ this->bone_transforms[i] = node_transform;
+ else
+ this->bone_transforms[i] =
+ this->bone_transforms[parent] * node_transform;
}
}