optimize vertical terrain raycasts, can stop on first hit

This commit is contained in:
T1ti
2024-12-22 04:39:01 +01:00
parent 044db21bb7
commit 9831b5c04a
3 changed files with 9 additions and 6 deletions

View File

@@ -530,7 +530,7 @@ void MapChunk::draw ( math::frustum const& frustum
}
bool MapChunk::intersect (math::ray const& ray, selection_result* results)
bool MapChunk::intersect (math::ray const& ray, selection_result* results, bool first_result)
{
if (!ray.intersect_bounds (vmin, vmax))
{
@@ -602,6 +602,9 @@ bool MapChunk::intersect (math::ray const& ray, selection_result* results)
(*distance, selected_chunk_type (this, std::make_tuple(indices[i], indices[i + 1],
indices[i + 2]), ray.position (*distance)));
intersection_found = true;
if (first_result)
return intersection_found;
}
}

View File

@@ -131,7 +131,7 @@ public:
);
//! \todo only this function should be public, all others should be called from it
bool intersect (math::ray const&, selection_result*);
bool intersect (math::ray const&, selection_result*, bool first_result = false);
bool ChangeMCCV(glm::vec3 const& pos, glm::vec4 const& color, float change, float radius, bool editMode);
bool stampMCCV(glm::vec3 const& pos, glm::vec4 const& color, float change, float radius, bool editMode, QImage* img, bool paint, bool use_image_colors);
glm::vec3 pickMCCV(glm::vec3 const& pos);

View File

@@ -416,13 +416,13 @@ void World::rotate_model_to_ground_normal(SceneObject* obj, bool smoothNormals)
{
{
math::ray intersect_ray(rayPos, glm::vec3(0.f, -1.f, 0.f));
chunk->intersect(intersect_ray, &results);
chunk->intersect(intersect_ray, &results, true);
}
// object is below ground
if (results.empty())
{
math::ray intersect_ray(rayPos, glm::vec3(0.f, 1.f, 0.f));
chunk->intersect(intersect_ray, &results);
chunk->intersect(intersect_ray, &results, true);
}
});
@@ -724,13 +724,13 @@ glm::vec3 World::get_ground_height(glm::vec3 pos)
{
{
math::ray intersect_ray(pos, glm::vec3(0.f, -1.f, 0.f));
chunk->intersect(intersect_ray, &hits);
chunk->intersect(intersect_ray, &hits, true);
}
// object is below ground
if (hits.empty())
{
math::ray intersect_ray(pos, glm::vec3(0.f, 1.f, 0.f));
chunk->intersect(intersect_ray, &hits);
chunk->intersect(intersect_ray, &hits, true);
}
});