fix non-local players interpolation and head direction

This commit is contained in:
MihailRis 2025-09-29 22:21:14 +03:00
parent e9222976ef
commit 75ef603df0
5 changed files with 29 additions and 25 deletions

View File

@ -67,12 +67,12 @@ function on_physics_update(delta)
mob.set_flight(player.is_flight(pid)) mob.set_flight(player.is_flight(pid))
body:set_body_type(player.is_noclip(pid) and "kinematic" or "dynamic") body:set_body_type(player.is_noclip(pid) and "kinematic" or "dynamic")
if hud and pid == hud.get_player() then local rot = get_player_rotation(pid)
local pos = tsf:get_pos() local front = mat4.mul(rot, {0, 0, -1})
local rot = get_player_rotation(pid) local pos = tsf:get_pos()
local front = mat4.mul(rot, {0, 0, -1})
if hud and pid == hud.get_player() then
process_player_inputs(pid, rot, delta) process_player_inputs(pid, rot, delta)
mob.look_at(vec3.add(pos, front))
end end
mob.look_at(vec3.add(pos, front))
end end

View File

@ -27,8 +27,7 @@ void HandsRenderer::renderHands(
auto& skeleton = *this->skeleton; auto& skeleton = *this->skeleton;
const auto& config = *skeleton.config; const auto& config = *skeleton.config;
// render
modelBatch.setLightsOffset(camera.position); modelBatch.setLightsOffset(camera.position);
config.update(skeleton, glm::mat4(1.0f), glm::vec3()); 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());
} }

View File

@ -412,7 +412,7 @@ void Entities::render(
const auto& size = transform.size; const auto& size = transform.size;
if (!frustum || frustum->isBoxVisible(pos - size, pos + size)) { if (!frustum || frustum->isBoxVisible(pos - size, pos + size)) {
const auto* rigConfig = skeleton.config; const auto* rigConfig = skeleton.config;
rigConfig->render(assets, batch, skeleton, transform.combined, pos); rigConfig->render(assets, batch, skeleton, transform.rot, pos);
} }
} }
} }

View File

@ -1,14 +1,14 @@
#include "rigging.hpp" #include "rigging.hpp"
#include <glm/ext/matrix_transform.hpp>
#include <glm/gtx/matrix_decompose.hpp>
#include "assets/Assets.hpp" #include "assets/Assets.hpp"
#include "coders/json.hpp" #include "coders/json.hpp"
#include "data/dv_util.hpp" #include "data/dv_util.hpp"
#include "graphics/commons/Model.hpp" #include "graphics/commons/Model.hpp"
#include "graphics/render/ModelBatch.hpp" #include "graphics/render/ModelBatch.hpp"
#include <glm/ext/matrix_transform.hpp>
#include <glm/gtx/matrix_decompose.hpp>
using namespace rigging; using namespace rigging;
void ModelReference::refresh(const Assets& assets) { void ModelReference::refresh(const Assets& assets) {
@ -122,21 +122,26 @@ size_t SkeletonConfig::update(
return count; 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( void SkeletonConfig::update(
Skeleton& skeleton, const glm::mat4& matrix, const glm::vec3& position Skeleton& skeleton, const glm::mat3& rotation, const glm::vec3& position
) const { ) const {
if (skeleton.interpolation.isEnabled()) { if (skeleton.interpolation.isEnabled()) {
const auto& interpolation = skeleton.interpolation; const auto& interpolation = skeleton.interpolation;
glm::vec3 scale, translation, skew; update(
glm::quat rotation; 0,
glm::vec4 perspective; skeleton,
glm::decompose(matrix, scale, rotation, translation, skew, perspective); root.get(),
build_matrix(rotation, interpolation.getCurrent())
auto delta = interpolation.getCurrent() - position; );
auto interpolatedMatrix = glm::translate(matrix, delta);
update(0, skeleton, root.get(), interpolatedMatrix);
} else { } else {
update(0, skeleton, root.get(), matrix); update(0, skeleton, root.get(), rotation);
} }
} }
@ -144,10 +149,10 @@ void SkeletonConfig::render(
const Assets& assets, const Assets& assets,
ModelBatch& batch, ModelBatch& batch,
Skeleton& skeleton, Skeleton& skeleton,
const glm::mat4& matrix, const glm::mat3& rotation,
const glm::vec3& position const glm::vec3& position
) const { ) const {
update(skeleton, matrix, position); update(skeleton, rotation, position);
if (!skeleton.visible) { if (!skeleton.visible) {
return; return;

View File

@ -120,7 +120,7 @@ namespace rigging {
void update( void update(
Skeleton& skeleton, Skeleton& skeleton,
const glm::mat4& matrix, const glm::mat3& rotation,
const glm::vec3& position const glm::vec3& position
) const; ) const;
@ -128,7 +128,7 @@ namespace rigging {
const Assets& assets, const Assets& assets,
ModelBatch& batch, ModelBatch& batch,
Skeleton& skeleton, Skeleton& skeleton,
const glm::mat4& matrix, const glm::mat3& rotation,
const glm::vec3& position const glm::vec3& position
) const; ) const;