mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-05 11:01:49 +00:00
fix: incomplete size transform support by entities
This commit is contained in:
parent
1d56d83b72
commit
fefc975832
7 changed files with 53 additions and 26 deletions
|
|
@ -302,6 +302,7 @@ void Entities::updatePhysics(float delta) {
|
|||
hitbox.friction = glm::abs(hitbox.gravityScale <= 1e-7f)
|
||||
? 8.0f
|
||||
: (!grounded ? 2.0f : 10.0f);
|
||||
hitbox.scale = transform.size;
|
||||
transform.setPos(hitbox.position);
|
||||
if (hitbox.grounded && !grounded) {
|
||||
scripting::on_entity_grounded(
|
||||
|
|
@ -358,7 +359,9 @@ void Entities::renderDebug(
|
|||
if (frustum && !frustum->isBoxVisible(pos - size, pos + size)) {
|
||||
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) {
|
||||
if (sensor.type != SensorType::AABB) continue;
|
||||
|
|
@ -410,10 +413,14 @@ void Entities::render(
|
|||
}
|
||||
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.rot, pos);
|
||||
if (frustum && !frustum->isBoxVisible(pos - size, pos + size)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const auto* rigConfig = skeleton.config;
|
||||
rigConfig->render(
|
||||
assets, batch, skeleton, transform.rot, pos, size
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -23,19 +23,19 @@ struct Transform {
|
|||
|
||||
void refresh();
|
||||
|
||||
inline void setRot(glm::mat3 m) {
|
||||
inline void setRot(const glm::mat3& m) {
|
||||
rot = m;
|
||||
dirty = true;
|
||||
}
|
||||
|
||||
inline void setSize(glm::vec3 v) {
|
||||
inline void setSize(const glm::vec3& v) {
|
||||
if (glm::distance2(displaySize, v) >= EPSILON) {
|
||||
dirty = true;
|
||||
}
|
||||
size = v;
|
||||
}
|
||||
|
||||
inline void setPos(glm::vec3 v) {
|
||||
inline void setPos(const glm::vec3& v) {
|
||||
if (glm::distance2(displayPos, v) >= EPSILON) {
|
||||
dirty = true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -122,15 +122,21 @@ size_t SkeletonConfig::update(
|
|||
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);
|
||||
combined = glm::translate(combined, pos);
|
||||
combined = combined * glm::mat4(rot);
|
||||
combined = glm::scale(combined, scale);
|
||||
return combined;
|
||||
}
|
||||
|
||||
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 {
|
||||
if (skeleton.interpolation.isEnabled()) {
|
||||
const auto& interpolation = skeleton.interpolation;
|
||||
|
|
@ -138,10 +144,10 @@ void SkeletonConfig::update(
|
|||
0,
|
||||
skeleton,
|
||||
root.get(),
|
||||
build_matrix(rotation, interpolation.getCurrent())
|
||||
build_matrix(rotation, interpolation.getCurrent(), scale)
|
||||
);
|
||||
} 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,
|
||||
Skeleton& skeleton,
|
||||
const glm::mat3& rotation,
|
||||
const glm::vec3& position
|
||||
const glm::vec3& position,
|
||||
const glm::vec3& scale
|
||||
) const {
|
||||
update(skeleton, rotation, position);
|
||||
update(skeleton, rotation, position, scale);
|
||||
|
||||
if (!skeleton.visible) {
|
||||
return;
|
||||
|
|
|
|||
|
|
@ -121,7 +121,8 @@ namespace rigging {
|
|||
void update(
|
||||
Skeleton& skeleton,
|
||||
const glm::mat3& rotation,
|
||||
const glm::vec3& position
|
||||
const glm::vec3& position,
|
||||
const glm::vec3& scale
|
||||
) const;
|
||||
|
||||
void render(
|
||||
|
|
@ -129,7 +130,8 @@ namespace rigging {
|
|||
ModelBatch& batch,
|
||||
Skeleton& skeleton,
|
||||
const glm::mat3& rotation,
|
||||
const glm::vec3& position
|
||||
const glm::vec3& position,
|
||||
const glm::vec3& scale
|
||||
) const;
|
||||
|
||||
Skeleton instance() const {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue