feat: players interpolation & add hud.set_allow_pause(...)
This commit is contained in:
@@ -38,6 +38,18 @@ void Transform::refresh() {
|
||||
dirty = false;
|
||||
}
|
||||
|
||||
void Entity::setInterpolatedPosition(const glm::vec3& position) {
|
||||
getSkeleton().interpolation.refresh(position);
|
||||
}
|
||||
|
||||
glm::vec3 Entity::getInterpolatedPosition() const {
|
||||
const auto& skeleton = getSkeleton();
|
||||
if (skeleton.interpolation.isEnabled()) {
|
||||
return skeleton.interpolation.getCurrent();
|
||||
}
|
||||
return getTransform().pos;
|
||||
}
|
||||
|
||||
void Entity::destroy() {
|
||||
if (isValid()) {
|
||||
entities.despawn(id);
|
||||
@@ -561,11 +573,14 @@ void Entities::render(
|
||||
if (transform.dirty) {
|
||||
transform.refresh();
|
||||
}
|
||||
if (skeleton.interpolation.isEnabled()) {
|
||||
skeleton.interpolation.updateTimer(delta);
|
||||
}
|
||||
const auto& pos = transform.pos;
|
||||
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);
|
||||
rigConfig->render(assets, batch, skeleton, transform.combined, pos);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -170,6 +170,10 @@ public:
|
||||
registry.get<EntityId>(entity).player = id;
|
||||
}
|
||||
|
||||
void setInterpolatedPosition(const glm::vec3& position);
|
||||
|
||||
glm::vec3 getInterpolatedPosition() const;
|
||||
|
||||
void destroy();
|
||||
};
|
||||
|
||||
|
||||
@@ -181,6 +181,7 @@ void Player::teleport(glm::vec3 position) {
|
||||
if (auto entity = level.entities->get(eid)) {
|
||||
entity->getRigidbody().hitbox.position = position;
|
||||
entity->getTransform().setPos(position);
|
||||
entity->setInterpolatedPosition(position);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -296,6 +297,18 @@ glm::vec3 Player::getSpawnPoint() const {
|
||||
return spawnpoint;
|
||||
}
|
||||
|
||||
glm::vec3 Player::getRotation(bool interpolated) const {
|
||||
if (interpolated) {
|
||||
return rotationInterpolation.getCurrent();
|
||||
}
|
||||
return rotation;
|
||||
}
|
||||
|
||||
void Player::setRotation(const glm::vec3& rotation) {
|
||||
this->rotation = rotation;
|
||||
rotationInterpolation.refresh(rotation);
|
||||
}
|
||||
|
||||
dv::value Player::serialize() const {
|
||||
auto root = dv::object();
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include "interfaces/Serializable.hpp"
|
||||
#include "settings.hpp"
|
||||
#include "voxels/voxel.hpp"
|
||||
#include "util/Interpolation.hpp"
|
||||
|
||||
class Chunks;
|
||||
class Camera;
|
||||
@@ -55,11 +56,15 @@ class Player : public Serializable {
|
||||
bool loadingChunks = true;
|
||||
entityid_t eid;
|
||||
entityid_t selectedEid = 0;
|
||||
|
||||
glm::vec3 rotation {};
|
||||
public:
|
||||
util::VecInterpolation<3, float, true> rotationInterpolation {true};
|
||||
|
||||
std::unique_ptr<Chunks> chunks;
|
||||
std::shared_ptr<Camera> fpCamera, spCamera, tpCamera;
|
||||
std::shared_ptr<Camera> currentCamera;
|
||||
glm::vec3 rotation {};
|
||||
|
||||
CursorSelection selection {};
|
||||
|
||||
Player(
|
||||
@@ -123,6 +128,9 @@ public:
|
||||
void setSpawnPoint(glm::vec3 point);
|
||||
glm::vec3 getSpawnPoint() const;
|
||||
|
||||
glm::vec3 getRotation(bool interpolated=false) const;
|
||||
void setRotation(const glm::vec3& rotation);
|
||||
|
||||
dv::value serialize() const override;
|
||||
void deserialize(const dv::value& src) override;
|
||||
|
||||
|
||||
+21
-7
@@ -6,9 +6,8 @@
|
||||
#include "graphics/commons/Model.hpp"
|
||||
#include "graphics/render/ModelBatch.hpp"
|
||||
|
||||
#define GLM_ENABLE_EXPERIMENTAL
|
||||
#include <glm/ext/matrix_transform.hpp>
|
||||
#include <glm/gtx/norm.hpp>
|
||||
#include <glm/gtx/matrix_decompose.hpp>
|
||||
|
||||
using namespace rigging;
|
||||
|
||||
@@ -69,7 +68,7 @@ SkeletonConfig::SkeletonConfig(
|
||||
}
|
||||
|
||||
size_t SkeletonConfig::update(
|
||||
size_t index, Skeleton& skeleton, Bone* node, glm::mat4 matrix
|
||||
size_t index, Skeleton& skeleton, Bone* node, const glm::mat4& matrix
|
||||
) const {
|
||||
auto boneMatrix = skeleton.pose.matrices[index];
|
||||
auto boneOffset = node->getOffset();
|
||||
@@ -90,17 +89,32 @@ size_t SkeletonConfig::update(
|
||||
return count;
|
||||
}
|
||||
|
||||
void SkeletonConfig::update(Skeleton& skeleton, glm::mat4 matrix) const {
|
||||
update(0, skeleton, root.get(), matrix);
|
||||
void SkeletonConfig::update(
|
||||
Skeleton& skeleton, const glm::mat4& matrix, 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);
|
||||
} else {
|
||||
update(0, skeleton, root.get(), matrix);
|
||||
}
|
||||
}
|
||||
|
||||
void SkeletonConfig::render(
|
||||
const Assets& assets,
|
||||
ModelBatch& batch,
|
||||
Skeleton& skeleton,
|
||||
const glm::mat4& matrix
|
||||
const glm::mat4& matrix,
|
||||
const glm::vec3& position
|
||||
) const {
|
||||
update(skeleton, matrix);
|
||||
update(skeleton, matrix, position);
|
||||
|
||||
if (!skeleton.visible) {
|
||||
return;
|
||||
|
||||
+15
-4
@@ -1,12 +1,15 @@
|
||||
#pragma once
|
||||
|
||||
#include <glm/glm.hpp>
|
||||
#define GLM_ENABLE_EXPERIMENTAL
|
||||
#include <glm/gtx/norm.hpp>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <cmath>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
#include "typedefs.hpp"
|
||||
#include "util/Interpolation.hpp"
|
||||
|
||||
class Assets;
|
||||
class ModelBatch;
|
||||
@@ -83,6 +86,8 @@ namespace rigging {
|
||||
bool visible;
|
||||
glm::vec3 tint {1.0f, 1.0f, 1.0f};
|
||||
|
||||
util::VecInterpolation<3, float> interpolation {false};
|
||||
|
||||
Skeleton(const SkeletonConfig* config);
|
||||
};
|
||||
|
||||
@@ -100,7 +105,7 @@ namespace rigging {
|
||||
std::vector<Bone*> nodes;
|
||||
|
||||
size_t update(
|
||||
size_t index, Skeleton& skeleton, Bone* node, glm::mat4 matrix
|
||||
size_t index, Skeleton& skeleton, Bone* node, const glm::mat4& matrix
|
||||
) const;
|
||||
public:
|
||||
SkeletonConfig(
|
||||
@@ -109,12 +114,18 @@ namespace rigging {
|
||||
size_t nodesCount
|
||||
);
|
||||
|
||||
void update(Skeleton& skeleton, glm::mat4 matrix) const;
|
||||
void update(
|
||||
Skeleton& skeleton,
|
||||
const glm::mat4& matrix,
|
||||
const glm::vec3& position
|
||||
) const;
|
||||
|
||||
void render(
|
||||
const Assets& assets,
|
||||
ModelBatch& batch,
|
||||
Skeleton& skeleton,
|
||||
const glm::mat4& matrix
|
||||
const glm::mat4& matrix,
|
||||
const glm::vec3& position
|
||||
) const;
|
||||
|
||||
Skeleton instance() const {
|
||||
|
||||
Reference in New Issue
Block a user