mirror of
https://github.com/overte-org/overte.git
synced 2025-04-21 06:44:06 +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();
|
||||
glm::vec3 positionToCenter = center - position;
|
||||
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);
|
||||
|
||||
|
@ -417,19 +417,19 @@ bool Circle3DOverlay::findRayIntersection(const glm::vec3& origin,
|
|||
const glm::vec3& direction, float& distance, BoxFace& 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);
|
||||
float innerRadius = maxDimension * getInnerRadius();
|
||||
float outerRadius = maxDimension * getOuterRadius();
|
||||
|
||||
// TODO: this really only works for circles, we should be handling the ellipse case as well...
|
||||
if (distanceToHit < innerRadius || distanceToHit > outerRadius) {
|
||||
intersects = false;
|
||||
}
|
||||
if (intersects) {
|
||||
glm::vec3 hitPosition = origin + (distance * direction);
|
||||
glm::vec3 localHitPosition = glm::inverse(_rotation) * (hitPosition - _position);
|
||||
localHitPosition.y = localHitPosition.y * _dimensions.x / _dimensions.y; // Scale to make circular
|
||||
|
||||
float distanceToHit = glm::length(localHitPosition);
|
||||
float innerRadius = _dimensions.x / 2.0f * _innerRadius;
|
||||
float outerRadius = _dimensions.x / 2.0f * _outerRadius;
|
||||
|
||||
intersects = innerRadius <= distanceToHit && distanceToHit <= outerRadius;
|
||||
}
|
||||
|
||||
return intersects;
|
||||
}
|
||||
|
||||
|
|
|
@ -93,7 +93,6 @@ QScriptValue Planar3DOverlay::getProperty(const QString& property) {
|
|||
|
||||
bool Planar3DOverlay::findRayIntersection(const glm::vec3& origin, const glm::vec3& direction,
|
||||
float& distance, BoxFace& face) {
|
||||
|
||||
RayIntersectionInfo rayInfo;
|
||||
rayInfo._rayStart = origin;
|
||||
rayInfo._rayDirection = direction;
|
||||
|
@ -110,9 +109,13 @@ bool Planar3DOverlay::findRayIntersection(const glm::vec3& origin, const glm::ve
|
|||
|
||||
if (intersects) {
|
||||
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;
|
||||
// _dimensions
|
||||
|
||||
glm::vec3 hitPosition = origin + (distance * direction);
|
||||
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;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue