Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extend bindings for OBB and misc fixes. #493

Merged
merged 2 commits into from
Feb 20, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion habitat_sim/geo.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,17 @@
LEFT,
RIGHT,
UP,
compute_gravity_aligned_MOBB,
)

__all__ = ["BBox", "OBB", "UP", "GRAVITY", "FRONT", "BACK", "LEFT", "RIGHT"]
__all__ = [
"BBox",
"OBB",
"UP",
"GRAVITY",
"FRONT",
"BACK",
"LEFT",
"RIGHT",
"compute_gravity_aligned_MOBB",
]
15 changes: 14 additions & 1 deletion src/esp/bindings/geoBindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,24 @@ void initGeoBindings(py::module& m) {

// ==== OBB ====
py::class_<OBB>(m, "OBB")
.def(py::init<box3f&>())
.def("contains", &OBB::contains)
.def("closest_point", &OBB::closestPoint)
.def("distance", &OBB::distance)
.def("to_aabb", &OBB::toAABB)
.def_property_readonly("center", &OBB::center)
.def_property_readonly("sizes", &OBB::sizes)
.def_property_readonly("half_extents", &OBB::halfExtents)
.def_property_readonly(
"rotation", [](const OBB& self) { return self.rotation().coeffs(); });
"rotation", [](const OBB& self) { return self.rotation().coeffs(); })
.def_property_readonly(
"local_to_world",
[](const OBB& self) { return self.localToWorld().matrix(); })
.def_property_readonly("world_to_local", [](const OBB& self) {
return self.worldToLocal().matrix();
});

geo.def("compute_gravity_aligned_MOBB", &geo::computeGravityAlignedMOBB);
}

} // namespace geo
Expand Down
4 changes: 2 additions & 2 deletions src/esp/geo/OBB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ OBB computeGravityAlignedMOBB(const vec3f& gravity,
const float dd = d0[0] * d1[1] - d0[1] * d1[0];

const float dx = s1[0] - s0[0];
const float dy = s1[1] - s0[0];
const float dy = s1[1] - s0[1];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Skylion007, can you remind me what was the bug here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dy was not actually calculating a delta y.

const float t = (dx * d1[1] - dy * d1[0]) / dd;

return s0 + t * d0;
Expand Down Expand Up @@ -240,7 +240,7 @@ OBB computeGravityAlignedMOBB(const vec3f& gravity,
aabb.extend(T_w2b * pt);
}

return OBB{aabb.center(), aabb.sizes(), T_w2b.inverse()};
return OBB{T_w2b.inverse() * aabb.center(), aabb.sizes(), T_w2b.inverse()};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The center was not in world coordinates

}

} // namespace geo
Expand Down
7 changes: 3 additions & 4 deletions src/esp/geo/geo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,12 @@ std::vector<vec2f> convexHull2D(const std::vector<vec2f>& points) {
}

// Build upper hull
for (size_t i = idx.size() - 2, t = k + 1; i >= 0; i--) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And here, just to have a history record for all this deep changes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolves a segfault that occurs on Linux due to undefined behavior of unsigned integer underflows.

for (size_t i = idx.size() - 1, t = k + 1; i > 0; i--) {
while (k >= t && cross(points[hullIdx[k - 2]], points[hullIdx[k - 1]],
points[idx[i]]) <= 0) {
points[idx[i - 1]]) <= 0) {
k--;
}

hullIdx[k++] = idx[i];
hullIdx[k++] = idx[i - 1];
}

hullIdx.resize(k - 1);
Expand Down
3 changes: 2 additions & 1 deletion src/esp/nav/PathFinder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -854,7 +854,8 @@ static float frand() {

vec3f PathFinder::Impl::getRandomNavigablePoint() {
dtPolyRef ref;
vec3f pt;
float inf = std::numeric_limits<float>::infinity();
Skylion007 marked this conversation as resolved.
Show resolved Hide resolved
vec3f pt(inf, inf, inf);
dtStatus status =
navQuery_->findRandomPoint(filter_.get(), frand, &ref, pt.data());
if (!dtStatusSucceed(status)) {
Expand Down