mirror of
https://github.com/overte-org/overte.git
synced 2025-08-06 17:00:13 +02:00
Merge pull request #4246 from ctrlaltdavid/20282
CR for Job #20282 - Finish implementing Planar3DOverlay intersection code
This commit is contained in:
commit
b3fb1b2403
2 changed files with 19 additions and 16 deletions
|
@ -119,7 +119,7 @@ void Circle3DOverlay::render(RenderArgs* args) {
|
||||||
glPushMatrix();
|
glPushMatrix();
|
||||||
glm::vec3 positionToCenter = center - position;
|
glm::vec3 positionToCenter = center - position;
|
||||||
glTranslatef(positionToCenter.x, positionToCenter.y, positionToCenter.z);
|
glTranslatef(positionToCenter.x, positionToCenter.y, positionToCenter.z);
|
||||||
glScalef(dimensions.x, dimensions.y, 1.0f);
|
glScalef(dimensions.x / 2.0f, dimensions.y / 2.0f, 1.0f);
|
||||||
|
|
||||||
glLineWidth(_lineWidth);
|
glLineWidth(_lineWidth);
|
||||||
|
|
||||||
|
@ -417,19 +417,19 @@ bool Circle3DOverlay::findRayIntersection(const glm::vec3& origin,
|
||||||
const glm::vec3& direction, float& distance, BoxFace& face) {
|
const glm::vec3& direction, float& distance, BoxFace& face) {
|
||||||
|
|
||||||
bool intersects = Planar3DOverlay::findRayIntersection(origin, direction, distance, face);
|
bool intersects = Planar3DOverlay::findRayIntersection(origin, direction, distance, face);
|
||||||
if (intersects) {
|
|
||||||
glm::vec3 hitAt = origin + (direction * distance);
|
|
||||||
float distanceToHit = glm::distance(hitAt, _position);
|
|
||||||
|
|
||||||
float maxDimension = glm::max(_dimensions.x, _dimensions.y);
|
if (intersects) {
|
||||||
float innerRadius = maxDimension * getInnerRadius();
|
glm::vec3 hitPosition = origin + (distance * direction);
|
||||||
float outerRadius = maxDimension * getOuterRadius();
|
glm::vec3 localHitPosition = glm::inverse(_rotation) * (hitPosition - _position);
|
||||||
|
localHitPosition.y = localHitPosition.y * _dimensions.x / _dimensions.y; // Scale to make circular
|
||||||
// TODO: this really only works for circles, we should be handling the ellipse case as well...
|
|
||||||
if (distanceToHit < innerRadius || distanceToHit > outerRadius) {
|
float distanceToHit = glm::length(localHitPosition);
|
||||||
intersects = false;
|
float innerRadius = _dimensions.x / 2.0f * _innerRadius;
|
||||||
}
|
float outerRadius = _dimensions.x / 2.0f * _outerRadius;
|
||||||
|
|
||||||
|
intersects = innerRadius <= distanceToHit && distanceToHit <= outerRadius;
|
||||||
}
|
}
|
||||||
|
|
||||||
return intersects;
|
return intersects;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -93,7 +93,6 @@ QScriptValue Planar3DOverlay::getProperty(const QString& property) {
|
||||||
|
|
||||||
bool Planar3DOverlay::findRayIntersection(const glm::vec3& origin, const glm::vec3& direction,
|
bool Planar3DOverlay::findRayIntersection(const glm::vec3& origin, const glm::vec3& direction,
|
||||||
float& distance, BoxFace& face) {
|
float& distance, BoxFace& face) {
|
||||||
|
|
||||||
RayIntersectionInfo rayInfo;
|
RayIntersectionInfo rayInfo;
|
||||||
rayInfo._rayStart = origin;
|
rayInfo._rayStart = origin;
|
||||||
rayInfo._rayDirection = direction;
|
rayInfo._rayDirection = direction;
|
||||||
|
@ -110,9 +109,13 @@ bool Planar3DOverlay::findRayIntersection(const glm::vec3& origin, const glm::ve
|
||||||
|
|
||||||
if (intersects) {
|
if (intersects) {
|
||||||
distance = rayInfo._hitDistance;
|
distance = rayInfo._hitDistance;
|
||||||
// TODO: if it intersects, we want to check to see if the intersection point is within our dimensions
|
|
||||||
// glm::vec3 hitAt = origin + direction * distance;
|
glm::vec3 hitPosition = origin + (distance * direction);
|
||||||
// _dimensions
|
glm::vec3 localHitPosition = glm::inverse(_rotation) * (hitPosition - _position);
|
||||||
|
glm::vec2 halfDimensions = _dimensions / 2.0f;
|
||||||
|
|
||||||
|
intersects = -halfDimensions.x <= localHitPosition.x && localHitPosition.x <= halfDimensions.x
|
||||||
|
&& -halfDimensions.y <= localHitPosition.y && localHitPosition.y <= halfDimensions.y;
|
||||||
}
|
}
|
||||||
return intersects;
|
return intersects;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue