Kinda works, but not raycast
This commit is contained in:
parent
5f551d6888
commit
5c3eafb331
@ -87,6 +87,12 @@ Content* ContentBuilder::build() {
|
|||||||
AABB aabb = hitbox;
|
AABB aabb = hitbox;
|
||||||
def->rotations.variants[i].transform(aabb);
|
def->rotations.variants[i].transform(aabb);
|
||||||
def->rt.hitboxes[i] = aabb;
|
def->rt.hitboxes[i] = aabb;
|
||||||
|
|
||||||
|
def->rt.modelBoxes[i].reserve(def->modelBoxes.size());
|
||||||
|
for (AABB aabb : def->modelBoxes) {
|
||||||
|
def->rotations.variants[i].transform(aabb);
|
||||||
|
def->rt.modelBoxes[i].push_back(aabb);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -105,7 +105,8 @@ public:
|
|||||||
blockid_t id;
|
blockid_t id;
|
||||||
bool solid = true;
|
bool solid = true;
|
||||||
bool emissive = false;
|
bool emissive = false;
|
||||||
AABB hitboxes[BlockRotProfile::MAX_COUNT];
|
AABB hitboxes[BlockRotProfile::MAX_COUNT];
|
||||||
|
std::vector<AABB> modelBoxes[BlockRotProfile::MAX_COUNT];
|
||||||
block_funcs_set funcsset {};
|
block_funcs_set funcsset {};
|
||||||
itemid_t pickingItem = 0;
|
itemid_t pickingItem = 0;
|
||||||
} rt;
|
} rt;
|
||||||
|
|||||||
@ -67,7 +67,10 @@ const AABB* Chunks::isObstacleAt(float x, float y, float z){
|
|||||||
if (hitbox.contains({x - ix, y - iy, z - iz}))
|
if (hitbox.contains({x - ix, y - iy, z - iz}))
|
||||||
return &hitbox;
|
return &hitbox;
|
||||||
} else {
|
} else {
|
||||||
for (const auto& hitbox : def->modelBoxes) {
|
const auto& boxes = def->rotatable
|
||||||
|
? def->rt.modelBoxes[v->rotation()]
|
||||||
|
: def->modelBoxes;
|
||||||
|
for (const auto& hitbox : boxes) {
|
||||||
if (hitbox.contains({x - ix, y - iy, z - iz}))
|
if (hitbox.contains({x - ix, y - iy, z - iz}))
|
||||||
return &hitbox;
|
return &hitbox;
|
||||||
}
|
}
|
||||||
@ -342,16 +345,29 @@ glm::vec3 Chunks::rayCastToObstacle(glm::vec3 start, glm::vec3 dir, float maxDis
|
|||||||
const Block* def = contentIds->getBlockDef(voxel->id);
|
const Block* def = contentIds->getBlockDef(voxel->id);
|
||||||
if (def->obstacle) {
|
if (def->obstacle) {
|
||||||
if (!def->rt.solid) {
|
if (!def->rt.solid) {
|
||||||
const AABB& box = def->rotatable
|
std::vector<AABB> hitboxes;
|
||||||
? def->rt.hitboxes[voxel->rotation()]
|
if (def->hitboxExplicit) {
|
||||||
: def->hitbox;
|
hitboxes = {
|
||||||
scalar_t distance;
|
def->rotatable
|
||||||
glm::ivec3 norm;
|
? def->rt.hitboxes[voxel->rotation()]
|
||||||
Ray ray(start, dir);
|
: def->hitbox
|
||||||
// norm is dummy now, can be inefficient
|
};
|
||||||
if (ray.intersectAABB(glm::ivec3(ix, iy, iz), box, maxDist, norm, distance) > RayRelation::None) {
|
} else {
|
||||||
return start + (dir * glm::vec3(distance));
|
hitboxes = def->rotatable
|
||||||
}
|
? def->rt.modelBoxes[voxel->rotation()]
|
||||||
|
: def->modelBoxes;
|
||||||
|
}
|
||||||
|
|
||||||
|
scalar_t distance;
|
||||||
|
glm::ivec3 norm;
|
||||||
|
Ray ray(start, dir);
|
||||||
|
|
||||||
|
for (const auto& box : hitboxes) {
|
||||||
|
// norm is dummy now, can be inefficient
|
||||||
|
if (ray.intersectAABB(glm::ivec3(ix, iy, iz), box, maxDist, norm, distance) > RayRelation::None) {
|
||||||
|
return start + (dir * glm::vec3(distance));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return glm::vec3(px + t * dx, py + t * dy, pz + t * dz);
|
return glm::vec3(px + t * dx, py + t * dy, pz + t * dz);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user