summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Suhren <suhren.stefan@fh-swf.de>2016-01-05 12:37:28 +0100
committerStefan Suhren <suhren.stefan@fh-swf.de>2016-01-05 12:37:28 +0100
commit9e83d173a5995587c208051fdd62420f51ff5378 (patch)
treefcd8e2c78e9f19ab441eb5621c8017080184b972
parent5b10b57badf1b28f3cebed1f045764ba212466e7 (diff)
downloadMultimedia-9e83d173a5995587c208051fdd62420f51ff5378.tar.gz
Multimedia-9e83d173a5995587c208051fdd62420f51ff5378.zip
Add last hit detectionhitDetection
-rw-r--r--src/gldisc.cpp35
1 files changed, 35 insertions, 0 deletions
diff --git a/src/gldisc.cpp b/src/gldisc.cpp
index ee0a06b..85dd6d4 100644
--- a/src/gldisc.cpp
+++ b/src/gldisc.cpp
@@ -107,6 +107,41 @@ bool GLDisc::isHit(QVector3D p1, QVector3D p2)
return true;
}
+ // Check if the mouse line is hitting the outer disc side
+ QVector2D vecXYProjection = lineVector.toVector2D();
+ QVector2D vecXYStart = p1.toVector2D();
+
+ // Solved via the "Mitternachtsformel"
+ float a = QVector2D::dotProduct(vecXYProjection, vecXYProjection);
+ float b = 2 * QVector2D::dotProduct(vecXYStart, vecXYProjection);
+ float c = QVector2D::dotProduct(vecXYStart,
+ vecXYStart) - m_circleRadius * m_circleRadius;
+
+ float discriminant = b * b - 4 * a * c;
+
+ if (discriminant >= 0)
+ {
+ discriminant = sqrt(discriminant);
+
+ float lambda1 = (-b - discriminant) / (2*a);
+
+ float z1 = (p1 + lambda1 * lineVector).z();
+
+ if(z1 >= 0 && z1 <= m_height)
+ {
+ return true;
+ }
+
+ float lambda2 = (-b + discriminant) / (2*a);
+
+ float z2 = (p1 + lambda2 * lineVector).z();
+
+ if(z2 >= 0 && z2 <= m_height)
+ {
+ return true;
+ }
+ }
+
return false;
}