Skip to content

Commit

Permalink
changed omnidirectional to be 180°, reprojected backpoints to fix other
Browse files Browse the repository at this point in the history
issue
  • Loading branch information
FrederikBark committed Oct 4, 2023
1 parent 43ece50 commit 8b7d67f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
9 changes: 5 additions & 4 deletions src/webots/nodes/utils/WbObjectDetection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ WbObjectDetection::WbObjectDetection(WbSolid *device, WbSolid *object, const int
mMaxRange(maxRange),
mOdeGeomData(NULL),
mHorizontalFieldOfView(horizontalFieldOfView),
mIsOmniDirectional(mHorizontalFieldOfView > M_PI_2),
mIsOmniDirectional(mHorizontalFieldOfView > M_PI),
mOcclusion(occlusion) {
if (mOcclusion == ONE_RAY) {
const WbVector3 devicePosition = mDevice->position();
Expand Down Expand Up @@ -322,11 +322,12 @@ bool WbObjectDetection::isWithinBounds(const WbAffinePlane *frustumPlanes, const
return false;
}
}
// add points at the back of the device to ensure the whole object is detected
pointsInFrustum << pointsAtBack;
// move the points in the device referential
for (int i = 0; i < pointsInFrustum.size(); ++i)
pointsInFrustum[i] = deviceInverseRotation * (pointsInFrustum[i] - devicePosition);
// add points at the back of the device to ensure the whole object is detected
pointsInFrustum << pointsAtBack;

double minX = pointsInFrustum[0].x();
double maxX = minX;
double minY = pointsInFrustum[0].y();
Expand Down Expand Up @@ -420,7 +421,7 @@ bool WbObjectDetection::isWithinBounds(const WbAffinePlane *frustumPlanes, const
}

objectRelativePosition = deviceInverseRotation * (objectPosition - devicePosition);
if (!mIsOmniDirectional) {
if (mHorizontalFieldOfView <= M_PI_2) {
// do not recompute the object size and position if partly outside in case of fovX > PI
// (a more complete computation will be needed and currently it seems to work quite well as-is)
objectSize.setY(objectSize.y() - outsidePart[RIGHT] - outsidePart[LEFT]);
Expand Down
2 changes: 1 addition & 1 deletion src/webots/nodes/utils/WbObjectDetection.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ class WbObjectDetection {
QList<double> mRaysCollisionDepth; // rays collision depth
QList<dGeomID> mRayGeoms; // rays that checks collision of this packet
double mHorizontalFieldOfView;
bool mIsOmniDirectional; // is sensor omnidirectional (horizontal FOV > PI/2)
bool mIsOmniDirectional; // is sensor omnidirectional (horizontal FOV > PI)
int mOcclusion;
};

Expand Down

0 comments on commit 8b7d67f

Please sign in to comment.