From 942e786f66f610469bbda89f53cabb98185772d1 Mon Sep 17 00:00:00 2001 From: Stefan Suhren Date: Mon, 7 Dec 2015 23:10:20 +0100 Subject: Add first steps for isHit detection --- qml/MainForm.ui.qml | 8 ++++++++ src/gldisc.cpp | 5 +++++ src/mmscene.cpp | 6 ++++++ src/mmscene.h | 23 +++++++++++++++++++++++ 4 files changed, 42 insertions(+) diff --git a/qml/MainForm.ui.qml b/qml/MainForm.ui.qml index 19cc165..981a38f 100644 --- a/qml/MainForm.ui.qml +++ b/qml/MainForm.ui.qml @@ -19,6 +19,14 @@ MMScene { color: "lightgrey" } + MouseArea{ + id: mouseArea + anchors.fill: parent + onPressed: { + //console.log("Scene clicked at X: " + mouse.x + " y" + mouse.y) + mousePressed(mouse.x, mouse.y); + } + } RowLayout { diff --git a/src/gldisc.cpp b/src/gldisc.cpp index 601ef25..48cd8be 100644 --- a/src/gldisc.cpp +++ b/src/gldisc.cpp @@ -73,6 +73,11 @@ void GLDisc::makeSurface(QVector *pointContainer, QVector *ind bool GLDisc::isHit(QVector3D p1, QVector3D p2) { + if(!GLBody::isHit(p1, p2)) + { + return false; + } + } diff --git a/src/mmscene.cpp b/src/mmscene.cpp index 45b913f..2bd7536 100644 --- a/src/mmscene.cpp +++ b/src/mmscene.cpp @@ -72,6 +72,12 @@ void MMScene::setupGeometry() m_geometryIsValid = true; } +void MMScene::mousePressed(int x, int y) +{ + renderer()->calculateMousePoints(&m_MouseNear, &m_mouseFar, QPoint(x, y)); + renderer()->mouseIntersection(&m_lastIntersection, v_Y, 0.0, QPoint(x, y)); //get starting point +} + void MMScene::drawTriangles() { renderer()->setLightingEnabled(m_lightingEnabled); diff --git a/src/mmscene.h b/src/mmscene.h index d68af98..78df57a 100644 --- a/src/mmscene.h +++ b/src/mmscene.h @@ -14,6 +14,9 @@ public: MMScene(QQuickItem *parent = 0); ~MMScene(); +public slots: + void mousePressed(int x, int y); + protected: /** * @brief paintUnderQmlScene @@ -75,6 +78,26 @@ private: GLSphere *m_sphere; GLDisc *m_disc; + + /** + * @brief m_MouseNear + * The near point of a mouse click or movement. + * Needed in synchronizeThreads(). + */ + QVector3D m_MouseNear; + + /** + * @brief m_MouseNear + * The far point of a mouse click or movement. + * Needed in synchronizeThreads(). + */ + QVector3D m_mouseFar; + + /** + * @brief m_lastIntersection + * The last intersection of the mouse line with the chessboard. + */ + QVector3D m_lastIntersection; }; #endif // MMSCENE_H -- cgit v1.2.3-70-g09d2