mirror of
https://github.com/overte-org/overte.git
synced 2025-04-20 18:23:54 +02:00
make sphere entities pick off their actual sphere, fix bug in ray picking multiple items with different distances
This commit is contained in:
parent
958b37dead
commit
11f10f9512
3 changed files with 39 additions and 6 deletions
|
@ -516,17 +516,22 @@ bool EntityTreeElement::findDetailedRayIntersection(const glm::vec3& origin, con
|
|||
|
||||
if (entity->findDetailedRayIntersection(origin, direction, keepSearching, element, localDistance,
|
||||
localFace, intersectedObject)) {
|
||||
|
||||
if (localDistance < distance) {
|
||||
distance = localDistance;
|
||||
face = localFace;
|
||||
*intersectedObject = (void*)entity;
|
||||
somethingIntersected = true;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// if the entity type doesn't support a detailed intersection, then just return the non-AABox results
|
||||
if (localDistance < distance) {
|
||||
distance = localDistance;
|
||||
face = localFace;
|
||||
*intersectedObject = (void*)entity;
|
||||
somethingIntersected = true;
|
||||
}
|
||||
} else {
|
||||
// if the entity type doesn't support a detailed intersection, then just return the non-AABox results
|
||||
distance = localDistance;
|
||||
face = localFace;
|
||||
*intersectedObject = (void*)entity;
|
||||
somethingIntersected = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -93,3 +93,26 @@ void SphereEntityItem::recalculateCollisionShape() {
|
|||
float largestDiameter = glm::max(dimensionsInMeters.x, dimensionsInMeters.y, dimensionsInMeters.z);
|
||||
_sphereShape.setRadius(largestDiameter / 2.0f);
|
||||
}
|
||||
|
||||
bool SphereEntityItem::findDetailedRayIntersection(const glm::vec3& origin, const glm::vec3& direction,
|
||||
bool& keepSearching, OctreeElement*& element, float& distance, BoxFace& face,
|
||||
void** intersectedObject) const {
|
||||
|
||||
// NOTE: origin and direction are in tree units. But our _sphereShape is in meters, so we need to
|
||||
// do a little math to make these match each other.
|
||||
RayIntersectionInfo rayInfo;
|
||||
rayInfo._rayStart = origin * (float)TREE_SCALE;
|
||||
rayInfo._rayDirection = direction;
|
||||
|
||||
// TODO: Note this is really doing ray intersections against a sphere, which is fine except in cases
|
||||
// where our dimensions actually make us an ellipsoid. But we'll live with this for now until we
|
||||
// get a more full fledged physics library
|
||||
if (_sphereShape.findRayIntersection(rayInfo)) {
|
||||
distance = rayInfo._hitDistance / (float)TREE_SCALE;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -56,6 +56,11 @@ public:
|
|||
// TODO: implement proper contains for 3D ellipsoid
|
||||
//virtual bool contains(const glm::vec3& point) const;
|
||||
|
||||
virtual bool supportsDetailedRayIntersection() const { return true; }
|
||||
virtual bool findDetailedRayIntersection(const glm::vec3& origin, const glm::vec3& direction,
|
||||
bool& keepSearching, OctreeElement*& element, float& distance, BoxFace& face,
|
||||
void** intersectedObject) const;
|
||||
|
||||
protected:
|
||||
virtual void recalculateCollisionShape();
|
||||
|
||||
|
|
Loading…
Reference in a new issue