diff --git a/src/noggit/MapChunk.cpp b/src/noggit/MapChunk.cpp index 21fb32ed..71e2a489 100644 --- a/src/noggit/MapChunk.cpp +++ b/src/noggit/MapChunk.cpp @@ -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; } } diff --git a/src/noggit/MapChunk.h b/src/noggit/MapChunk.h index f674b3bb..49e156b7 100755 --- a/src/noggit/MapChunk.h +++ b/src/noggit/MapChunk.h @@ -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); diff --git a/src/noggit/World.cpp b/src/noggit/World.cpp index 6a119e68..9b0dee2c 100644 --- a/src/noggit/World.cpp +++ b/src/noggit/World.cpp @@ -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); } });