Skip to content

Commit

Permalink
gltfpack: Fix rotation deviation calculation
Browse files Browse the repository at this point in the history
acos(dot(q1, q2)) returns half-angle of rotation between two
quaternions, so our deviation was off by 2x.

This should not have a significant effect on constant track detection
but it makes the thresholds more accurate and may help with future
animation optimizations.
  • Loading branch information
zeux committed Sep 16, 2024
1 parent fc5c85e commit e50eac8
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion gltf/animation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ static float getDelta(const Attr& l, const Attr& r, cgltf_animation_path_type ty
return std::max(std::max(fabsf(l.f[0] - r.f[0]), fabsf(l.f[1] - r.f[1])), fabsf(l.f[2] - r.f[2]));

case cgltf_animation_path_type_rotation:
return acosf(std::min(1.f, fabsf(l.f[0] * r.f[0] + l.f[1] * r.f[1] + l.f[2] * r.f[2] + l.f[3] * r.f[3])));
return 2 * acosf(std::min(1.f, fabsf(l.f[0] * r.f[0] + l.f[1] * r.f[1] + l.f[2] * r.f[2] + l.f[3] * r.f[3])));

case cgltf_animation_path_type_scale:
return std::max(std::max(fabsf(l.f[0] / r.f[0] - 1), fabsf(l.f[1] / r.f[1] - 1)), fabsf(l.f[2] / r.f[2] - 1));
Expand Down

0 comments on commit e50eac8

Please sign in to comment.