fix non-local players interpolation and head direction
This commit is contained in:
parent
e9222976ef
commit
75ef603df0
@ -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
|
||||
|
||||
@ -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());
|
||||
}
|
||||
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,14 +1,14 @@
|
||||
#include "rigging.hpp"
|
||||
|
||||
#include <glm/ext/matrix_transform.hpp>
|
||||
#include <glm/gtx/matrix_decompose.hpp>
|
||||
|
||||
#include "assets/Assets.hpp"
|
||||
#include "coders/json.hpp"
|
||||
#include "data/dv_util.hpp"
|
||||
#include "graphics/commons/Model.hpp"
|
||||
#include "graphics/render/ModelBatch.hpp"
|
||||
|
||||
#include <glm/ext/matrix_transform.hpp>
|
||||
#include <glm/gtx/matrix_decompose.hpp>
|
||||
|
||||
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;
|
||||
|
||||
@ -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;
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user