move player animation to base:player_animator component

This commit is contained in:
MihailRis 2025-01-16 06:58:53 +03:00
parent 9cd3f3e4c8
commit 43dc88c6b5
3 changed files with 15 additions and 22 deletions

View File

@ -3,7 +3,9 @@ local body = entity.rigidbody
local rig = entity.skeleton local rig = entity.skeleton
local itemid = 0 local itemid = 0
local headIndex = rig:index("head")
local itemIndex = rig:index("item") local itemIndex = rig:index("item")
local bodyIndex = rig:index("body")
local function refresh_model(id) local function refresh_model(id)
itemid = id itemid = id
@ -16,6 +18,11 @@ function on_render()
if pid == -1 then if pid == -1 then
return return
end end
local rx, ry, rz = player.get_rot(pid)
rig:set_matrix(headIndex, mat4.rotate({1, 0, 0}, ry))
rig:set_matrix(bodyIndex, mat4.rotate({0, 1, 0}, rx))
local invid, slotid = player.get_inventory(pid) local invid, slotid = player.get_inventory(pid)
local id, _ = inventory.get(invid, slotid) local id, _ = inventory.get(invid, slotid)
if id ~= itemid then if id ~= itemid then

View File

@ -170,8 +170,8 @@ void CameraControl::update(
switchCamera(); switchCamera();
} }
auto& spCamera = player.spCamera; const auto& spCamera = player.spCamera;
auto& tpCamera = player.tpCamera; const auto& tpCamera = player.tpCamera;
refresh(); refresh();
@ -316,15 +316,15 @@ static int determine_rotation(
if (name == "pipe") { if (name == "pipe") {
if (norm.x < 0.0f) if (norm.x < 0.0f)
return BLOCK_DIR_WEST; return BLOCK_DIR_WEST;
else if (norm.x > 0.0f) if (norm.x > 0.0f)
return BLOCK_DIR_EAST; return BLOCK_DIR_EAST;
else if (norm.y > 0.0f) if (norm.y > 0.0f)
return BLOCK_DIR_UP; return BLOCK_DIR_UP;
else if (norm.y < 0.0f) if (norm.y < 0.0f)
return BLOCK_DIR_DOWN; return BLOCK_DIR_DOWN;
else if (norm.z > 0.0f) if (norm.z > 0.0f)
return BLOCK_DIR_NORTH; return BLOCK_DIR_NORTH;
else if (norm.z < 0.0f) if (norm.z < 0.0f)
return BLOCK_DIR_SOUTH; return BLOCK_DIR_SOUTH;
} else if (name == "pane") { } else if (name == "pane") {
if (abs(camDir.x) > abs(camDir.z)) { if (abs(camDir.x) > abs(camDir.z)) {

View File

@ -170,23 +170,9 @@ void Player::postUpdate() {
} }
} }
// TODO: ERASE & FORGET
auto& skeleton = entity->getSkeleton(); auto& skeleton = entity->getSkeleton();
skeleton.visible = currentCamera != fpCamera; skeleton.visible = currentCamera != fpCamera;
auto body = skeleton.config->find("body");
auto head = skeleton.config->find("head");
if (body) {
skeleton.pose.matrices[body->getIndex()] = glm::rotate(
glm::mat4(1.0f), glm::radians(rotation.x), glm::vec3(0, 1, 0)
);
}
if (head) {
skeleton.pose.matrices[head->getIndex()] = glm::rotate(
glm::mat4(1.0f), glm::radians(rotation.y), glm::vec3(1, 0, 0)
);
}
} }
void Player::teleport(glm::vec3 position) { void Player::teleport(glm::vec3 position) {