mirror of
https://github.com/overte-org/overte.git
synced 2025-08-08 14:18:24 +02:00
Octree::findCapsulePenetration() uses meters
This commit is contained in:
parent
ca1c9b4105
commit
d7d25a6509
4 changed files with 10 additions and 22 deletions
|
@ -425,7 +425,7 @@ bool EntityTree::findNearPointOperation(OctreeElement* element, void* extraData)
|
||||||
|
|
||||||
glm::vec3 penetration;
|
glm::vec3 penetration;
|
||||||
AACube cube = entityTreeElement->getAACube();
|
AACube cube = entityTreeElement->getAACube();
|
||||||
cube *= (float)TREE_SCALE;
|
cube.scale((float)TREE_SCALE);
|
||||||
bool sphereIntersection = cube.findSpherePenetration(args->position, args->targetRadius, penetration);
|
bool sphereIntersection = cube.findSpherePenetration(args->position, args->targetRadius, penetration);
|
||||||
|
|
||||||
// If this entityTreeElement contains the point, then search it...
|
// If this entityTreeElement contains the point, then search it...
|
||||||
|
@ -478,7 +478,7 @@ bool EntityTree::findInSphereOperation(OctreeElement* element, void* extraData)
|
||||||
FindAllNearPointArgs* args = static_cast<FindAllNearPointArgs*>(extraData);
|
FindAllNearPointArgs* args = static_cast<FindAllNearPointArgs*>(extraData);
|
||||||
glm::vec3 penetration;
|
glm::vec3 penetration;
|
||||||
AACube cube = element->getAACube();
|
AACube cube = element->getAACube();
|
||||||
cube *= (float)TREE_SCALE;
|
cube.scale((float)TREE_SCALE);
|
||||||
bool sphereIntersection = cube.findSpherePenetration(args->position, args->targetRadius, penetration);
|
bool sphereIntersection = cube.findSpherePenetration(args->position, args->targetRadius, penetration);
|
||||||
|
|
||||||
// If this element contains the point, then search it...
|
// If this element contains the point, then search it...
|
||||||
|
@ -516,7 +516,7 @@ public:
|
||||||
bool EntityTree::findInCubeOperation(OctreeElement* element, void* extraData) {
|
bool EntityTree::findInCubeOperation(OctreeElement* element, void* extraData) {
|
||||||
FindEntitiesInCubeArgs* args = static_cast<FindEntitiesInCubeArgs*>(extraData);
|
FindEntitiesInCubeArgs* args = static_cast<FindEntitiesInCubeArgs*>(extraData);
|
||||||
AACube elementCube = element->getAACube();
|
AACube elementCube = element->getAACube();
|
||||||
elementCube *= (float)TREE_SCALE;
|
elementCube.scale((float)TREE_SCALE);
|
||||||
if (elementCube.touches(args->_cube)) {
|
if (elementCube.touches(args->_cube)) {
|
||||||
EntityTreeElement* entityTreeElement = static_cast<EntityTreeElement*>(element);
|
EntityTreeElement* entityTreeElement = static_cast<EntityTreeElement*>(element);
|
||||||
entityTreeElement->getEntities(args->_cube, args->_foundEntities);
|
entityTreeElement->getEntities(args->_cube, args->_foundEntities);
|
||||||
|
|
|
@ -750,7 +750,7 @@ bool findSpherePenetrationOp(OctreeElement* element, void* extraData) {
|
||||||
|
|
||||||
// the details in args is in meters (world-frame) so we have to scale the element cube up
|
// the details in args is in meters (world-frame) so we have to scale the element cube up
|
||||||
AACube box = element->getAACube();
|
AACube box = element->getAACube();
|
||||||
box *= (float)TREE_SCALE;
|
box.scale((float)TREE_SCALE);
|
||||||
|
|
||||||
// coarse check against bounds
|
// coarse check against bounds
|
||||||
if (!box.expandedContains(args->center, args->radius)) {
|
if (!box.expandedContains(args->center, args->radius)) {
|
||||||
|
@ -837,14 +837,15 @@ bool findCapsulePenetrationOp(OctreeElement* element, void* extraData) {
|
||||||
CapsuleArgs* args = static_cast<CapsuleArgs*>(extraData);
|
CapsuleArgs* args = static_cast<CapsuleArgs*>(extraData);
|
||||||
|
|
||||||
// coarse check against bounds
|
// coarse check against bounds
|
||||||
const AACube& box = element->getAACube();
|
AACube box = element->getAACube();
|
||||||
|
box.scale((float)TREE_SCALE);
|
||||||
if (!box.expandedIntersectsSegment(args->start, args->end, args->radius)) {
|
if (!box.expandedIntersectsSegment(args->start, args->end, args->radius)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (element->hasContent()) {
|
if (element->hasContent()) {
|
||||||
glm::vec3 nodePenetration;
|
glm::vec3 nodePenetration;
|
||||||
if (box.findCapsulePenetration(args->start, args->end, args->radius, nodePenetration)) {
|
if (box.findCapsulePenetration(args->start, args->end, args->radius, nodePenetration)) {
|
||||||
args->penetration = addPenetrations(args->penetration, nodePenetration * (float)(TREE_SCALE));
|
args->penetration = addPenetrations(args->penetration, nodePenetration);
|
||||||
args->found = true;
|
args->found = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -891,12 +892,7 @@ bool findContentInCubeOp(OctreeElement* element, void* extraData) {
|
||||||
bool Octree::findCapsulePenetration(const glm::vec3& start, const glm::vec3& end, float radius,
|
bool Octree::findCapsulePenetration(const glm::vec3& start, const glm::vec3& end, float radius,
|
||||||
glm::vec3& penetration, Octree::lockType lockType, bool* accurateResult) {
|
glm::vec3& penetration, Octree::lockType lockType, bool* accurateResult) {
|
||||||
|
|
||||||
CapsuleArgs args = {
|
CapsuleArgs args = { start, end, radius, penetration, false };
|
||||||
start / (float)(TREE_SCALE),
|
|
||||||
end / (float)(TREE_SCALE),
|
|
||||||
radius / (float)(TREE_SCALE),
|
|
||||||
penetration,
|
|
||||||
false };
|
|
||||||
penetration = glm::vec3(0.0f, 0.0f, 0.0f);
|
penetration = glm::vec3(0.0f, 0.0f, 0.0f);
|
||||||
|
|
||||||
bool gotLock = false;
|
bool gotLock = false;
|
||||||
|
|
|
@ -1338,7 +1338,7 @@ bool OctreeElement::findRayIntersection(const glm::vec3& origin, const glm::vec3
|
||||||
keepSearching = true; // assume that we will continue searching after this.
|
keepSearching = true; // assume that we will continue searching after this.
|
||||||
|
|
||||||
AACube cube = getAACube();
|
AACube cube = getAACube();
|
||||||
cube *= (float)TREE_SCALE;
|
cube.scale((float)TREE_SCALE);
|
||||||
float distanceToElementCube = std::numeric_limits<float>::max();
|
float distanceToElementCube = std::numeric_limits<float>::max();
|
||||||
float distanceToElementDetails = distance;
|
float distanceToElementDetails = distance;
|
||||||
BoxFace localFace;
|
BoxFace localFace;
|
||||||
|
@ -1392,7 +1392,7 @@ bool OctreeElement::findSpherePenetration(const glm::vec3& center, float radius,
|
||||||
glm::vec3& penetration, void** penetratedObject) const {
|
glm::vec3& penetration, void** penetratedObject) const {
|
||||||
// center and radius are in meters, so we have to scale the _cube into world-frame
|
// center and radius are in meters, so we have to scale the _cube into world-frame
|
||||||
AACube cube = _cube;
|
AACube cube = _cube;
|
||||||
cube *= (float)TREE_SCALE;
|
cube.scale((float)TREE_SCALE);
|
||||||
return cube.findSpherePenetration(center, radius, penetration);
|
return cube.findSpherePenetration(center, radius, penetration);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -63,8 +63,6 @@ public:
|
||||||
AABox clamp(const glm::vec3& min, const glm::vec3& max) const;
|
AABox clamp(const glm::vec3& min, const glm::vec3& max) const;
|
||||||
AABox clamp(float min, float max) const;
|
AABox clamp(float min, float max) const;
|
||||||
|
|
||||||
AACube& operator *= (float scale);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
glm::vec3 getClosestPointOnFace(const glm::vec3& point, BoxFace face) const;
|
glm::vec3 getClosestPointOnFace(const glm::vec3& point, BoxFace face) const;
|
||||||
glm::vec3 getClosestPointOnFace(const glm::vec4& origin, const glm::vec4& direction, BoxFace face) const;
|
glm::vec3 getClosestPointOnFace(const glm::vec4& origin, const glm::vec4& direction, BoxFace face) const;
|
||||||
|
@ -76,12 +74,6 @@ private:
|
||||||
float _scale;
|
float _scale;
|
||||||
};
|
};
|
||||||
|
|
||||||
inline AACube& AACube::operator *= (float scale) {
|
|
||||||
_corner *= scale;
|
|
||||||
_scale *= scale;
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline bool operator==(const AACube& a, const AACube& b) {
|
inline bool operator==(const AACube& a, const AACube& b) {
|
||||||
return a.getCorner() == b.getCorner() && a.getScale() == b.getScale();
|
return a.getCorner() == b.getCorner() && a.getScale() == b.getScale();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue