mirror of
https://github.com/overte-org/overte.git
synced 2025-04-16 21:02:17 +02:00
Merge pull request #7065 from zzmp/fix/circle3d-click
Fix circle3d FindRayIntersection
This commit is contained in:
commit
d14b9ab9b6
1 changed files with 7 additions and 6 deletions
|
@ -10,6 +10,7 @@
|
|||
|
||||
#include "Circle3DOverlay.h"
|
||||
|
||||
#include <GeometryUtil.h>
|
||||
#include <GeometryCache.h>
|
||||
#include <RegisteredMetaTypes.h>
|
||||
|
||||
|
@ -400,18 +401,18 @@ QScriptValue Circle3DOverlay::getProperty(const QString& property) {
|
|||
bool Circle3DOverlay::findRayIntersection(const glm::vec3& origin, const glm::vec3& direction, float& distance,
|
||||
BoxFace& face, glm::vec3& surfaceNormal) {
|
||||
|
||||
bool intersects = Planar3DOverlay::findRayIntersection(origin, direction, distance, face, surfaceNormal);
|
||||
// Scale the dimensions by the diameter
|
||||
glm::vec2 dimensions = getOuterRadius() * 2.0f * getDimensions();
|
||||
bool intersects = findRayRectangleIntersection(origin, direction, getRotation(), getPosition(), dimensions, distance);
|
||||
|
||||
if (intersects) {
|
||||
glm::vec3 hitPosition = origin + (distance * direction);
|
||||
glm::vec3 localHitPosition = glm::inverse(getRotation()) * (hitPosition - getPosition());
|
||||
localHitPosition.y = localHitPosition.y * getDimensions().x / getDimensions().y; // Scale to make circular
|
||||
|
||||
localHitPosition.x /= getDimensions().x;
|
||||
localHitPosition.y /= getDimensions().y;
|
||||
float distanceToHit = glm::length(localHitPosition);
|
||||
float innerRadius = getDimensions().x / 2.0f * _innerRadius;
|
||||
float outerRadius = getDimensions().x / 2.0f * _outerRadius;
|
||||
|
||||
intersects = innerRadius <= distanceToHit && distanceToHit <= outerRadius;
|
||||
intersects = getInnerRadius() <= distanceToHit && distanceToHit <= getOuterRadius();
|
||||
}
|
||||
|
||||
return intersects;
|
||||
|
|
Loading…
Reference in a new issue