add skeleton:is_visible(...), skeleton:set_visible(...)
This commit is contained in:
+13
-3
@@ -9,6 +9,7 @@
|
||||
#include "../window/Camera.hpp"
|
||||
#include "../items/Inventory.hpp"
|
||||
#include "../objects/Entities.hpp"
|
||||
#include "../objects/rigging.hpp"
|
||||
|
||||
#include <glm/glm.hpp>
|
||||
#include <utility>
|
||||
@@ -66,9 +67,18 @@ void Player::updateInput(PlayerInput& input, float delta) {
|
||||
return;
|
||||
}
|
||||
auto& hitbox = entity->getRigidbody().hitbox;
|
||||
auto& transform = entity->getTransform();
|
||||
transform.setRot(
|
||||
glm::rotate(glm::mat4(1.0f), glm::radians(cam.x), glm::vec3(0, 1, 0)));
|
||||
auto& skeleton = entity->getSkeleton();
|
||||
|
||||
skeleton.visible = currentCamera != camera;
|
||||
|
||||
size_t bodyIndex = skeleton.config->find("body")->getIndex();
|
||||
size_t headIndex = skeleton.config->find("head")->getIndex();
|
||||
|
||||
skeleton.pose.matrices[bodyIndex] =
|
||||
glm::rotate(glm::mat4(1.0f), glm::radians(cam.x-90), glm::vec3(0, 1, 0));
|
||||
skeleton.pose.matrices[headIndex] = glm::rotate(glm::rotate(
|
||||
glm::translate(glm::mat4(1.0f), glm::vec3(0.0f, 0.6f, 0.0f)),
|
||||
glm::radians(-cam.y), glm::vec3(0, 0, 1)), glm::radians(90.0f), glm::vec3(0, 1, 0));
|
||||
|
||||
bool crouch = input.shift && hitbox.grounded && !input.sprint;
|
||||
float speed = this->speed;
|
||||
|
||||
@@ -70,9 +70,16 @@ void SkeletonConfig::render(
|
||||
const glm::mat4& matrix) const
|
||||
{
|
||||
update(skeleton, matrix);
|
||||
|
||||
if (!skeleton.visible) {
|
||||
return;
|
||||
}
|
||||
for (size_t i = 0; i < nodes.size(); i++) {
|
||||
auto* node = nodes[i];
|
||||
node->refreshModel(assets);
|
||||
if (!skeleton.flags[i].visible) {
|
||||
continue;
|
||||
}
|
||||
if (auto model = node->getModel()) {
|
||||
batch.pushMatrix(skeleton.calculated.matrices[i]);
|
||||
batch.draw(model, &skeleton.textures);
|
||||
|
||||
+12
-2
@@ -67,11 +67,17 @@ namespace rigging {
|
||||
}
|
||||
};
|
||||
|
||||
struct BoneFlags {
|
||||
bool visible: 1;
|
||||
};
|
||||
|
||||
struct Skeleton {
|
||||
const SkeletonConfig* config;
|
||||
Pose pose;
|
||||
Pose calculated;
|
||||
std::vector<BoneFlags> flags;
|
||||
std::unordered_map<std::string, std::string> textures;
|
||||
bool visible;
|
||||
};
|
||||
|
||||
class SkeletonConfig {
|
||||
@@ -104,9 +110,13 @@ namespace rigging {
|
||||
const glm::mat4& matrix) const;
|
||||
|
||||
Skeleton instance() const {
|
||||
return Skeleton {
|
||||
this, Pose(nodes.size()), Pose(nodes.size()), {}
|
||||
auto rig = Skeleton {
|
||||
this, Pose(nodes.size()), Pose(nodes.size()), {}, {}, true
|
||||
};
|
||||
for (size_t i = 0; i < nodes.size(); i++) {
|
||||
rig.flags.push_back({true});
|
||||
}
|
||||
return rig;
|
||||
}
|
||||
|
||||
Bone* find(std::string_view str) const;
|
||||
|
||||
Reference in New Issue
Block a user