diff --git a/res/scripts/components/player.lua b/res/scripts/components/player.lua index f3f37584..2fc25b7e 100644 --- a/res/scripts/components/player.lua +++ b/res/scripts/components/player.lua @@ -67,12 +67,12 @@ function on_physics_update(delta) mob.set_flight(player.is_flight(pid)) body:set_body_type(player.is_noclip(pid) and "kinematic" or "dynamic") - if hud and pid == hud.get_player() then - local pos = tsf:get_pos() - local rot = get_player_rotation(pid) - local front = mat4.mul(rot, {0, 0, -1}) + local rot = get_player_rotation(pid) + local front = mat4.mul(rot, {0, 0, -1}) + local pos = tsf:get_pos() + if hud and pid == hud.get_player() then process_player_inputs(pid, rot, delta) - mob.look_at(vec3.add(pos, front)) end + mob.look_at(vec3.add(pos, front)) end diff --git a/src/graphics/render/HandsRenderer.cpp b/src/graphics/render/HandsRenderer.cpp index db598a43..c1891ccf 100644 --- a/src/graphics/render/HandsRenderer.cpp +++ b/src/graphics/render/HandsRenderer.cpp @@ -27,8 +27,7 @@ void HandsRenderer::renderHands( auto& skeleton = *this->skeleton; const auto& config = *skeleton.config; - // render modelBatch.setLightsOffset(camera.position); config.update(skeleton, glm::mat4(1.0f), glm::vec3()); - config.render(assets, modelBatch, skeleton, glm::mat4(1.0f), glm::vec3()); + config.render(assets, modelBatch, skeleton, glm::mat3(1.0f), glm::vec3()); } diff --git a/src/objects/Entities.cpp b/src/objects/Entities.cpp index a95f2ad1..8cd0f5f7 100644 --- a/src/objects/Entities.cpp +++ b/src/objects/Entities.cpp @@ -412,7 +412,7 @@ void Entities::render( const auto& size = transform.size; if (!frustum || frustum->isBoxVisible(pos - size, pos + size)) { const auto* rigConfig = skeleton.config; - rigConfig->render(assets, batch, skeleton, transform.combined, pos); + rigConfig->render(assets, batch, skeleton, transform.rot, pos); } } } diff --git a/src/objects/rigging.cpp b/src/objects/rigging.cpp index 1da11f8c..3f50e905 100644 --- a/src/objects/rigging.cpp +++ b/src/objects/rigging.cpp @@ -1,14 +1,14 @@ #include "rigging.hpp" +#include +#include + #include "assets/Assets.hpp" #include "coders/json.hpp" #include "data/dv_util.hpp" #include "graphics/commons/Model.hpp" #include "graphics/render/ModelBatch.hpp" -#include -#include - using namespace rigging; void ModelReference::refresh(const Assets& assets) { @@ -122,21 +122,26 @@ size_t SkeletonConfig::update( return count; } +static glm::mat4 build_matrix(const glm::mat3& rot, const glm::vec3& pos) { + glm::mat4 combined(1.0f); + combined = glm::translate(combined, pos); + combined = combined * glm::mat4(rot); + return combined; +} + void SkeletonConfig::update( - Skeleton& skeleton, const glm::mat4& matrix, const glm::vec3& position + Skeleton& skeleton, const glm::mat3& rotation, const glm::vec3& position ) const { if (skeleton.interpolation.isEnabled()) { const auto& interpolation = skeleton.interpolation; - glm::vec3 scale, translation, skew; - glm::quat rotation; - glm::vec4 perspective; - glm::decompose(matrix, scale, rotation, translation, skew, perspective); - - auto delta = interpolation.getCurrent() - position; - auto interpolatedMatrix = glm::translate(matrix, delta); - update(0, skeleton, root.get(), interpolatedMatrix); + update( + 0, + skeleton, + root.get(), + build_matrix(rotation, interpolation.getCurrent()) + ); } else { - update(0, skeleton, root.get(), matrix); + update(0, skeleton, root.get(), rotation); } } @@ -144,10 +149,10 @@ void SkeletonConfig::render( const Assets& assets, ModelBatch& batch, Skeleton& skeleton, - const glm::mat4& matrix, + const glm::mat3& rotation, const glm::vec3& position ) const { - update(skeleton, matrix, position); + update(skeleton, rotation, position); if (!skeleton.visible) { return; diff --git a/src/objects/rigging.hpp b/src/objects/rigging.hpp index 76ee764b..46019065 100644 --- a/src/objects/rigging.hpp +++ b/src/objects/rigging.hpp @@ -120,7 +120,7 @@ namespace rigging { void update( Skeleton& skeleton, - const glm::mat4& matrix, + const glm::mat3& rotation, const glm::vec3& position ) const; @@ -128,7 +128,7 @@ namespace rigging { const Assets& assets, ModelBatch& batch, Skeleton& skeleton, - const glm::mat4& matrix, + const glm::mat3& rotation, const glm::vec3& position ) const;