Implemented tangible.find. Octrees are more or less done! Yay!

This commit is contained in:
2022-07-14 00:57:11 -04:00
parent 69efb12c26
commit 4735c1fd7d
6 changed files with 466 additions and 114 deletions

View File

@@ -97,7 +97,7 @@ private:
eng::string plane_;
// The bounding box of the scan.
util::XYZ lo_, hi_, center_, invradius_;
util::XYZ center_, radius_;
// If you scan a cylinder or SPHERE, it actually
// scans the bounding box first, then clips out
@@ -109,10 +109,10 @@ private:
// nondeterminism. Scans by lua should always be sorted.
bool sorted_;
// The special ID, if nonzero, is either PREPENDED to the
// results, or OMITTED from the results, depending on omit_special.
int64_t special_;
bool omit_special_;
// The near ID, if nonzero, is either PREPENDED to the
// results, or OMITTED from the results, depending on include_near_.
int64_t near_;
bool include_near_;
// If this is true, items on the nowhere plane are not scanned.
bool omit_nowhere_;
@@ -122,44 +122,52 @@ public:
plane_ = "";
shape_ = BOX;
sorted_ = true;
special_ = 0;
omit_special_ = false;
near_ = 0;
include_near_ = false;
omit_nowhere_ = false;
lo_ = hi_ = center_ = util::XYZ();
radius_ = center_ = util::XYZ();
}
PlaneScan() { clear(); }
// Convert a lua table into a scan configuration.
void configure(LuaStack &LS, LuaSlot slot);
//
// If there is an error in the configuration, returns an
// error message, otherwise returns empty string.
//
// Caution: if this detects the configuration flag 'near',
// then it stores the near ID. However, it doesn't fetch
// the center and plane. It is the caller's responsibility
// to check if 'near' has been set, and if so, store a center
// and plane. This is admittedly ugly, but it eliminates
// a dependency on the world module.
//
eng::string configure(const LuaStack &LS, LuaSlot slot);
// Set the bounding box given two corners.
void set_bbox_given_two_corners(const util::XYZ &a, const util::XYZ &b) {
lo_.x = std::min(a.x, b.x);
lo_.y = std::min(a.y, b.y);
lo_.z = std::min(a.z, b.z);
hi_.x = std::max(a.x, b.x);
hi_.y = std::max(a.y, b.y);
hi_.z = std::max(a.z, b.z);
center_ = (lo_ + hi_) * 0.5;
invradius_.x = 2.0 / (hi_.x - lo_.x);
invradius_.y = 2.0 / (hi_.y - lo_.y);
invradius_.z = 2.0 / (hi_.z - lo_.z);
}
// Set the bounding box given a center and a radius.
void set_bbox_given_center_radius(const util::XYZ &center, float r) {
util::XYZ offset(r, r, r);
lo_ = center - offset;
hi_ = center + offset;
center_ = center;
invradius_.x = invradius_.y = invradius_.z = (1.0 / r);
set_center(center);
set_radius(r);
}
void set_whole_plane() {
shape_ = BOX;
center_ = util::XYZ();
radius_.x = std::numeric_limits<float>::infinity();
radius_.y = radius_.z = radius_.x;
}
void set_center(const util::XYZ &center) { center_ = center; }
void set_radius(const util::XYZ &radius) { radius_ = radius; }
void set_radius(float f) { radius_.x = radius_.y = radius_.z = f; }
void set_plane(std::string_view p) { plane_ = p; }
void set_shape(Shape s) { shape_ = s; }
void set_sorted(bool s) { sorted_ = s; }
void set_special(int64_t id, bool omit) { special_ = id; omit_special_ = omit; }
void set_near(int64_t id, bool inc) { near_ = id; include_near_ = inc; }
void set_omit_nowhere(bool b) { omit_nowhere_ = b; }
int64_t near() const { return near_; }
// Reveal the contents of the PlaneScan as a string.
eng::string debug_string() const;
};
class PlaneItem : public eng::nevernew {
@@ -222,9 +230,9 @@ public:
// This is for unit testing.
eng::string tree_debug_string(const eng::string &plane);
eng::string outliers_debug_string(const eng::string &plane);
eng::string search_bboxes_debug_string(const eng::string &plane, const PlaneScan &scan);
eng::string scan_steps_debug_string(const eng::string &plane, const PlaneScan &scan);
eng::string search_bboxes_debug_string(const PlaneScan &scan);
eng::string scan_steps_debug_string(const PlaneScan &scan);
// Untrack all planeitems. This is for unit testing.
void untrack_all();