fix: incomplete size transform support by entities
This commit is contained in:
parent
98a3971e13
commit
bc1ff634a3
@ -28,6 +28,13 @@ void HandsRenderer::renderHands(
|
|||||||
const auto& config = *skeleton.config;
|
const auto& config = *skeleton.config;
|
||||||
|
|
||||||
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(), glm::vec3(1.0f));
|
||||||
config.render(assets, modelBatch, skeleton, glm::mat3(1.0f), glm::vec3());
|
config.render(
|
||||||
|
assets,
|
||||||
|
modelBatch,
|
||||||
|
skeleton,
|
||||||
|
glm::mat3(1.0f),
|
||||||
|
glm::vec3(),
|
||||||
|
glm::vec3(1.0f)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -302,6 +302,7 @@ void Entities::updatePhysics(float delta) {
|
|||||||
hitbox.friction = glm::abs(hitbox.gravityScale <= 1e-7f)
|
hitbox.friction = glm::abs(hitbox.gravityScale <= 1e-7f)
|
||||||
? 8.0f
|
? 8.0f
|
||||||
: (!grounded ? 2.0f : 10.0f);
|
: (!grounded ? 2.0f : 10.0f);
|
||||||
|
hitbox.scale = transform.size;
|
||||||
transform.setPos(hitbox.position);
|
transform.setPos(hitbox.position);
|
||||||
if (hitbox.grounded && !grounded) {
|
if (hitbox.grounded && !grounded) {
|
||||||
scripting::on_entity_grounded(
|
scripting::on_entity_grounded(
|
||||||
@ -358,7 +359,9 @@ void Entities::renderDebug(
|
|||||||
if (frustum && !frustum->isBoxVisible(pos - size, pos + size)) {
|
if (frustum && !frustum->isBoxVisible(pos - size, pos + size)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
batch.box(hitbox.position, hitbox.halfsize * 2.0f, glm::vec4(1.0f));
|
batch.box(
|
||||||
|
hitbox.position, hitbox.getHalfSize() * 2.0f, glm::vec4(1.0f)
|
||||||
|
);
|
||||||
|
|
||||||
for (auto& sensor : rigidbody.sensors) {
|
for (auto& sensor : rigidbody.sensors) {
|
||||||
if (sensor.type != SensorType::AABB) continue;
|
if (sensor.type != SensorType::AABB) continue;
|
||||||
@ -410,10 +413,14 @@ void Entities::render(
|
|||||||
}
|
}
|
||||||
const auto& pos = transform.pos;
|
const auto& pos = transform.pos;
|
||||||
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;
|
continue;
|
||||||
rigConfig->render(assets, batch, skeleton, transform.rot, pos);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const auto* rigConfig = skeleton.config;
|
||||||
|
rigConfig->render(
|
||||||
|
assets, batch, skeleton, transform.rot, pos, size
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -23,19 +23,19 @@ struct Transform {
|
|||||||
|
|
||||||
void refresh();
|
void refresh();
|
||||||
|
|
||||||
inline void setRot(glm::mat3 m) {
|
inline void setRot(const glm::mat3& m) {
|
||||||
rot = m;
|
rot = m;
|
||||||
dirty = true;
|
dirty = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void setSize(glm::vec3 v) {
|
inline void setSize(const glm::vec3& v) {
|
||||||
if (glm::distance2(displaySize, v) >= EPSILON) {
|
if (glm::distance2(displaySize, v) >= EPSILON) {
|
||||||
dirty = true;
|
dirty = true;
|
||||||
}
|
}
|
||||||
size = v;
|
size = v;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void setPos(glm::vec3 v) {
|
inline void setPos(const glm::vec3& v) {
|
||||||
if (glm::distance2(displayPos, v) >= EPSILON) {
|
if (glm::distance2(displayPos, v) >= EPSILON) {
|
||||||
dirty = true;
|
dirty = true;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -122,15 +122,21 @@ size_t SkeletonConfig::update(
|
|||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
static glm::mat4 build_matrix(const glm::mat3& rot, const glm::vec3& pos) {
|
static glm::mat4 build_matrix(
|
||||||
|
const glm::mat3& rot, const glm::vec3& pos, const glm::vec3& scale
|
||||||
|
) {
|
||||||
glm::mat4 combined(1.0f);
|
glm::mat4 combined(1.0f);
|
||||||
combined = glm::translate(combined, pos);
|
combined = glm::translate(combined, pos);
|
||||||
combined = combined * glm::mat4(rot);
|
combined = combined * glm::mat4(rot);
|
||||||
|
combined = glm::scale(combined, scale);
|
||||||
return combined;
|
return combined;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SkeletonConfig::update(
|
void SkeletonConfig::update(
|
||||||
Skeleton& skeleton, const glm::mat3& rotation, const glm::vec3& position
|
Skeleton& skeleton,
|
||||||
|
const glm::mat3& rotation,
|
||||||
|
const glm::vec3& position,
|
||||||
|
const glm::vec3& scale
|
||||||
) const {
|
) const {
|
||||||
if (skeleton.interpolation.isEnabled()) {
|
if (skeleton.interpolation.isEnabled()) {
|
||||||
const auto& interpolation = skeleton.interpolation;
|
const auto& interpolation = skeleton.interpolation;
|
||||||
@ -138,10 +144,10 @@ void SkeletonConfig::update(
|
|||||||
0,
|
0,
|
||||||
skeleton,
|
skeleton,
|
||||||
root.get(),
|
root.get(),
|
||||||
build_matrix(rotation, interpolation.getCurrent())
|
build_matrix(rotation, interpolation.getCurrent(), scale)
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
update(0, skeleton, root.get(), build_matrix(rotation, position));
|
update(0, skeleton, root.get(), build_matrix(rotation, position, scale));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -150,9 +156,10 @@ void SkeletonConfig::render(
|
|||||||
ModelBatch& batch,
|
ModelBatch& batch,
|
||||||
Skeleton& skeleton,
|
Skeleton& skeleton,
|
||||||
const glm::mat3& rotation,
|
const glm::mat3& rotation,
|
||||||
const glm::vec3& position
|
const glm::vec3& position,
|
||||||
|
const glm::vec3& scale
|
||||||
) const {
|
) const {
|
||||||
update(skeleton, rotation, position);
|
update(skeleton, rotation, position, scale);
|
||||||
|
|
||||||
if (!skeleton.visible) {
|
if (!skeleton.visible) {
|
||||||
return;
|
return;
|
||||||
|
|||||||
@ -121,7 +121,8 @@ namespace rigging {
|
|||||||
void update(
|
void update(
|
||||||
Skeleton& skeleton,
|
Skeleton& skeleton,
|
||||||
const glm::mat3& rotation,
|
const glm::mat3& rotation,
|
||||||
const glm::vec3& position
|
const glm::vec3& position,
|
||||||
|
const glm::vec3& scale
|
||||||
) const;
|
) const;
|
||||||
|
|
||||||
void render(
|
void render(
|
||||||
@ -129,7 +130,8 @@ namespace rigging {
|
|||||||
ModelBatch& batch,
|
ModelBatch& batch,
|
||||||
Skeleton& skeleton,
|
Skeleton& skeleton,
|
||||||
const glm::mat3& rotation,
|
const glm::mat3& rotation,
|
||||||
const glm::vec3& position
|
const glm::vec3& position,
|
||||||
|
const glm::vec3& scale
|
||||||
) const;
|
) const;
|
||||||
|
|
||||||
Skeleton instance() const {
|
Skeleton instance() const {
|
||||||
|
|||||||
@ -52,6 +52,7 @@ struct Hitbox {
|
|||||||
glm::vec3 position;
|
glm::vec3 position;
|
||||||
glm::vec3 halfsize;
|
glm::vec3 halfsize;
|
||||||
glm::vec3 velocity;
|
glm::vec3 velocity;
|
||||||
|
glm::vec3 scale {1.0f, 1.0f, 1.0f};
|
||||||
float linearDamping = 0.5;
|
float linearDamping = 0.5;
|
||||||
float friction = 1.0f;
|
float friction = 1.0f;
|
||||||
float verticalDamping = 1.0f;
|
float verticalDamping = 1.0f;
|
||||||
@ -64,4 +65,8 @@ struct Hitbox {
|
|||||||
AABB getAABB() const {
|
AABB getAABB() const {
|
||||||
return AABB(position-halfsize, position+halfsize);
|
return AABB(position-halfsize, position+halfsize);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
glm::vec3 getHalfSize() const {
|
||||||
|
return halfsize * scale;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@ -11,11 +11,10 @@
|
|||||||
#define GLM_ENABLE_EXPERIMENTAL
|
#define GLM_ENABLE_EXPERIMENTAL
|
||||||
#include <glm/gtx/norm.hpp>
|
#include <glm/gtx/norm.hpp>
|
||||||
|
|
||||||
const float E = 0.03f;
|
inline const float E = 0.03f;
|
||||||
const float MAX_FIX = 0.1f;
|
inline const float MAX_FIX = 0.1f;
|
||||||
|
|
||||||
PhysicsSolver::PhysicsSolver(glm::vec3 gravity) : gravity(gravity) {
|
PhysicsSolver::PhysicsSolver(glm::vec3 gravity) : gravity(gravity) {}
|
||||||
}
|
|
||||||
|
|
||||||
void PhysicsSolver::step(
|
void PhysicsSolver::step(
|
||||||
const GlobalChunks& chunks,
|
const GlobalChunks& chunks,
|
||||||
@ -28,7 +27,7 @@ void PhysicsSolver::step(
|
|||||||
float linearDamping = hitbox.linearDamping * hitbox.friction;
|
float linearDamping = hitbox.linearDamping * hitbox.friction;
|
||||||
float s = 2.0f/BLOCK_AABB_GRID;
|
float s = 2.0f/BLOCK_AABB_GRID;
|
||||||
|
|
||||||
const glm::vec3& half = hitbox.halfsize;
|
auto half = hitbox.getHalfSize();
|
||||||
glm::vec3& pos = hitbox.position;
|
glm::vec3& pos = hitbox.position;
|
||||||
glm::vec3& vel = hitbox.velocity;
|
glm::vec3& vel = hitbox.velocity;
|
||||||
float gravityScale = hitbox.gravityScale;
|
float gravityScale = hitbox.gravityScale;
|
||||||
@ -91,8 +90,8 @@ void PhysicsSolver::step(
|
|||||||
}
|
}
|
||||||
|
|
||||||
AABB aabb;
|
AABB aabb;
|
||||||
aabb.a = hitbox.position - hitbox.halfsize;
|
aabb.a = hitbox.position - hitbox.getHalfSize();
|
||||||
aabb.b = hitbox.position + hitbox.halfsize;
|
aabb.b = hitbox.position + hitbox.getHalfSize();
|
||||||
for (size_t i = 0; i < sensors.size(); i++) {
|
for (size_t i = 0; i < sensors.size(); i++) {
|
||||||
auto& sensor = *sensors[i];
|
auto& sensor = *sensors[i];
|
||||||
if (sensor.entity == entity) {
|
if (sensor.entity == entity) {
|
||||||
@ -267,7 +266,7 @@ void PhysicsSolver::colisionCalc(
|
|||||||
|
|
||||||
bool PhysicsSolver::isBlockInside(int x, int y, int z, Hitbox* hitbox) {
|
bool PhysicsSolver::isBlockInside(int x, int y, int z, Hitbox* hitbox) {
|
||||||
const glm::vec3& pos = hitbox->position;
|
const glm::vec3& pos = hitbox->position;
|
||||||
const glm::vec3& half = hitbox->halfsize;
|
auto half = hitbox->getHalfSize();
|
||||||
return x >= floor(pos.x-half.x) && x <= floor(pos.x+half.x) &&
|
return x >= floor(pos.x-half.x) && x <= floor(pos.x+half.x) &&
|
||||||
z >= floor(pos.z-half.z) && z <= floor(pos.z+half.z) &&
|
z >= floor(pos.z-half.z) && z <= floor(pos.z+half.z) &&
|
||||||
y >= floor(pos.y-half.y) && y <= floor(pos.y+half.y);
|
y >= floor(pos.y-half.y) && y <= floor(pos.y+half.y);
|
||||||
@ -276,7 +275,7 @@ bool PhysicsSolver::isBlockInside(int x, int y, int z, Hitbox* hitbox) {
|
|||||||
bool PhysicsSolver::isBlockInside(int x, int y, int z, Block* def, blockstate state, Hitbox* hitbox) {
|
bool PhysicsSolver::isBlockInside(int x, int y, int z, Block* def, blockstate state, Hitbox* hitbox) {
|
||||||
const float e = 0.001f; // inaccuracy
|
const float e = 0.001f; // inaccuracy
|
||||||
const glm::vec3& pos = hitbox->position;
|
const glm::vec3& pos = hitbox->position;
|
||||||
const glm::vec3& half = hitbox->halfsize;
|
auto half = hitbox->getHalfSize();
|
||||||
const auto& boxes = def->rotatable
|
const auto& boxes = def->rotatable
|
||||||
? def->rt.hitboxes[state.rotation]
|
? def->rt.hitboxes[state.rotation]
|
||||||
: def->hitboxes;
|
: def->hitboxes;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user