summaryrefslogtreecommitdiffstats
path: root/src/gldisc.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/gldisc.cpp')
-rw-r--r--src/gldisc.cpp34
1 files changed, 26 insertions, 8 deletions
diff --git a/src/gldisc.cpp b/src/gldisc.cpp
index 85dd6d4..9315e4c 100644
--- a/src/gldisc.cpp
+++ b/src/gldisc.cpp
@@ -1,6 +1,6 @@
#include "gldisc.h"
-GLDisc::GLDisc(double radius, double height, int sides, GLColorRgba color,
+GLDisc::GLDisc(double radius, double height, QVector3D lowerMiddlePoint, int sides, GLColorRgba color,
QString textureFile)
: GLBody(sqrt(pow(radius, 2) + pow(0.5 * height, 2)), color, textureFile)
{
@@ -10,6 +10,8 @@ GLDisc::GLDisc(double radius, double height, int sides, GLColorRgba color,
m_center = v_Z * 0.5 * m_height;
m_circleRadius = radius;
+
+ m_lowerMiddlePoint = lowerMiddlePoint;
}
void GLDisc::makeSurface(QVector<GLPoint> *pointContainer,
@@ -82,15 +84,19 @@ void GLDisc::makeSurface(QVector<GLPoint> *pointContainer,
bool GLDisc::isHit(QVector3D p1, QVector3D p2)
{
- if (!GLBody::isHit(p1, p2))
+
+ QVector3D p1New = p1 - m_lowerMiddlePoint;
+ QVector3D p2New = p2 - m_lowerMiddlePoint;
+
+ if (!GLBody::isHit(p1New, p2New))
{
return false;
}
- QVector3D lineVector = p2 - p1;
+ QVector3D lineVector = p2New - p1New;
// Calculate intersection point with the xy plane
- QVector3D vecBottom = p1 + lineVector * (-p1.z() / lineVector.z());
+ QVector3D vecBottom = p1New + lineVector * (-p1New.z() / lineVector.z());
if (vecBottom.length() < m_circleRadius)
{
@@ -99,7 +105,7 @@ bool GLDisc::isHit(QVector3D p1, QVector3D p2)
// Calculate intersection point with the xy + m_heigth plane
// Then drop z so that we get a projection onto the xy plane
- QVector3D vecTop = (p1 + lineVector * ((m_height - p1.z()) /
+ QVector3D vecTop = (p1New + lineVector * ((m_height - p1New.z()) /
lineVector.z())).toVector2D();
if (vecTop.length() < m_circleRadius)
@@ -109,7 +115,7 @@ bool GLDisc::isHit(QVector3D p1, QVector3D p2)
// Check if the mouse line is hitting the outer disc side
QVector2D vecXYProjection = lineVector.toVector2D();
- QVector2D vecXYStart = p1.toVector2D();
+ QVector2D vecXYStart = p1New.toVector2D();
// Solved via the "Mitternachtsformel"
float a = QVector2D::dotProduct(vecXYProjection, vecXYProjection);
@@ -125,7 +131,7 @@ bool GLDisc::isHit(QVector3D p1, QVector3D p2)
float lambda1 = (-b - discriminant) / (2*a);
- float z1 = (p1 + lambda1 * lineVector).z();
+ float z1 = (p1New + lambda1 * lineVector).z();
if(z1 >= 0 && z1 <= m_height)
{
@@ -134,7 +140,7 @@ bool GLDisc::isHit(QVector3D p1, QVector3D p2)
float lambda2 = (-b + discriminant) / (2*a);
- float z2 = (p1 + lambda2 * lineVector).z();
+ float z2 = (p1New + lambda2 * lineVector).z();
if(z2 >= 0 && z2 <= m_height)
{
@@ -152,3 +158,15 @@ QVector2D GLDisc::calculatePoint(double sideAngle)
return QVector2D(x, y);
}
+
+
+void GLDisc::draw(GLESRenderer *renderer)
+{
+ renderer->pushMvMatrix();
+
+ renderer->translate(m_lowerMiddlePoint);
+
+ GLBody::draw(renderer);
+
+ renderer->popMvMatrix();
+}