optimize vertical terrain raycasts, can stop on first hit
This commit is contained in:
@@ -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))
|
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],
|
(*distance, selected_chunk_type (this, std::make_tuple(indices[i], indices[i + 1],
|
||||||
indices[i + 2]), ray.position (*distance)));
|
indices[i + 2]), ray.position (*distance)));
|
||||||
intersection_found = true;
|
intersection_found = true;
|
||||||
|
|
||||||
|
if (first_result)
|
||||||
|
return intersection_found;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -131,7 +131,7 @@ public:
|
|||||||
);
|
);
|
||||||
//! \todo only this function should be public, all others should be called from it
|
//! \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 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);
|
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);
|
glm::vec3 pickMCCV(glm::vec3 const& pos);
|
||||||
|
|||||||
@@ -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));
|
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
|
// object is below ground
|
||||||
if (results.empty())
|
if (results.empty())
|
||||||
{
|
{
|
||||||
math::ray intersect_ray(rayPos, glm::vec3(0.f, 1.f, 0.f));
|
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));
|
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
|
// object is below ground
|
||||||
if (hits.empty())
|
if (hits.empty())
|
||||||
{
|
{
|
||||||
math::ray intersect_ray(pos, glm::vec3(0.f, 1.f, 0.f));
|
math::ray intersect_ray(pos, glm::vec3(0.f, 1.f, 0.f));
|
||||||
chunk->intersect(intersect_ray, &hits);
|
chunk->intersect(intersect_ray, &hits, true);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user