mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-05 19:11:50 +00:00
optimize collisions calculations (remove the stupid)
This commit is contained in:
parent
49aa7cdfba
commit
b0d231c927
9 changed files with 134 additions and 103 deletions
|
|
@ -1,11 +1,5 @@
|
|||
#include "Chunks.hpp"
|
||||
|
||||
#include <math.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <stdexcept>
|
||||
#include <vector>
|
||||
|
||||
#include "data/StructLayout.hpp"
|
||||
#include "coders/byte_utils.hpp"
|
||||
#include "content/Content.hpp"
|
||||
|
|
@ -20,6 +14,11 @@
|
|||
#include "VoxelsVolume.hpp"
|
||||
#include "blocks_agent.hpp"
|
||||
|
||||
#include <math.h>
|
||||
#include <algorithm>
|
||||
#include <stdexcept>
|
||||
#include <vector>
|
||||
|
||||
Chunks::Chunks(
|
||||
int32_t w,
|
||||
int32_t d,
|
||||
|
|
@ -67,20 +66,21 @@ const AABB* Chunks::isObstacleAt(float x, float y, float z) const {
|
|||
}
|
||||
}
|
||||
const auto& def = indices.blocks.require(v->id);
|
||||
if (def.obstacle) {
|
||||
glm::ivec3 offset {};
|
||||
if (v->state.segment) {
|
||||
glm::ivec3 point(ix, iy, iz);
|
||||
offset = seekOrigin(point, def, v->state) - point;
|
||||
}
|
||||
const auto& boxes =
|
||||
def.rotatable ? def.rt.hitboxes[v->state.rotation] : def.hitboxes;
|
||||
for (const auto& hitbox : boxes) {
|
||||
if (hitbox.contains(
|
||||
{x - ix - offset.x, y - iy - offset.y, z - iz - offset.z}
|
||||
)) {
|
||||
return &hitbox;
|
||||
}
|
||||
if (!def.obstacle) {
|
||||
return nullptr;
|
||||
}
|
||||
glm::ivec3 offset {};
|
||||
if (v->state.segment) {
|
||||
glm::ivec3 point(ix, iy, iz);
|
||||
offset = seekOrigin(point, def, v->state) - point;
|
||||
}
|
||||
const auto& boxes =
|
||||
def.rotatable ? def.rt.hitboxes[v->state.rotation] : def.hitboxes;
|
||||
for (const auto& hitbox : boxes) {
|
||||
if (hitbox.contains(
|
||||
{x - ix - offset.x, y - iy - offset.y, z - iz - offset.z}
|
||||
)) {
|
||||
return &hitbox;
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue