mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 17:49:27 +02:00
special handling of SPHERE case in EntityItem::contains()
This commit is contained in:
parent
65e920039c
commit
a656ea723e
1 changed files with 13 additions and 2 deletions
|
@ -1680,13 +1680,24 @@ void EntityItem::adjustShapeInfoByRegistration(ShapeInfo& info) const {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool EntityItem::contains(const glm::vec3& point) const {
|
bool EntityItem::contains(const glm::vec3& point) const {
|
||||||
|
ShapeType shapeType = getShapeType();
|
||||||
|
|
||||||
|
if (shapeType == SHAPE_TYPE_SPHERE) {
|
||||||
|
// SPHERE case is special:
|
||||||
|
// anything with shapeType == SPHERE must collide as a bounding sphere in the world-frame regardless of dimensions
|
||||||
|
// therefore we must do math using an unscaled localPoint relative to sphere center
|
||||||
|
glm::vec3 dimensions = getScaledDimensions();
|
||||||
|
glm::vec3 localPoint = point - (getWorldPosition() + getWorldOrientation() * (dimensions * (ENTITY_ITEM_DEFAULT_REGISTRATION_POINT - getRegistrationPoint())));
|
||||||
|
const float HALF_SQUARED = 0.25f;
|
||||||
|
return glm::length2(localPoint) < HALF_SQUARED * glm::length2(dimensions);
|
||||||
|
}
|
||||||
|
|
||||||
// we transform into the "normalized entity-frame" where the bounding box is centered on the origin
|
// we transform into the "normalized entity-frame" where the bounding box is centered on the origin
|
||||||
// and has dimensions <1,1,1>
|
// and has dimensions <1,1,1>
|
||||||
glm::vec3 localPoint = glm::vec3(glm::inverse(getEntityToWorldMatrix()) * glm::vec4(point, 1.0f));
|
glm::vec3 localPoint = glm::vec3(glm::inverse(getEntityToWorldMatrix()) * glm::vec4(point, 1.0f));
|
||||||
|
|
||||||
const float NORMALIZED_HALF_SIDE = 0.5f;
|
const float NORMALIZED_HALF_SIDE = 0.5f;
|
||||||
const float NORMALIZED_RADIUS_SQUARED = NORMALIZED_HALF_SIDE * NORMALIZED_HALF_SIDE;
|
const float NORMALIZED_RADIUS_SQUARED = NORMALIZED_HALF_SIDE * NORMALIZED_HALF_SIDE;
|
||||||
ShapeType shapeType = getShapeType();
|
|
||||||
switch(shapeType) {
|
switch(shapeType) {
|
||||||
case SHAPE_TYPE_NONE:
|
case SHAPE_TYPE_NONE:
|
||||||
return false;
|
return false;
|
||||||
|
@ -1707,8 +1718,8 @@ bool EntityItem::contains(const glm::vec3& point) const {
|
||||||
localPoint.y <= NORMALIZED_HALF_SIDE &&
|
localPoint.y <= NORMALIZED_HALF_SIDE &&
|
||||||
localPoint.z <= NORMALIZED_HALF_SIDE;
|
localPoint.z <= NORMALIZED_HALF_SIDE;
|
||||||
}
|
}
|
||||||
case SHAPE_TYPE_SPHERE:
|
|
||||||
case SHAPE_TYPE_ELLIPSOID: {
|
case SHAPE_TYPE_ELLIPSOID: {
|
||||||
|
// since we've transformed into the normalized space this is just a sphere-point intersection test
|
||||||
return glm::length2(localPoint) <= NORMALIZED_RADIUS_SQUARED;
|
return glm::length2(localPoint) <= NORMALIZED_RADIUS_SQUARED;
|
||||||
}
|
}
|
||||||
case SHAPE_TYPE_CYLINDER_X:
|
case SHAPE_TYPE_CYLINDER_X:
|
||||||
|
|
Loading…
Reference in a new issue