diff options
author | Mike Krus <mike.krus@kdab.com> | 2017-08-08 19:47:20 +0100 |
---|---|---|
committer | Mike Krus <mike.krus@kdab.com> | 2017-08-09 08:54:59 +0000 |
commit | 49e03adc771b5ee471588e5a7e95ba10c86eee90 (patch) | |
tree | 7ef731143529d4cbf2ab804efd437ff56a22aa09 | |
parent | 60ea37949ce746919b32c774320478b856aaee4d (diff) |
Add point picking
Most API was present but not the picking backend.
Also missing was QPickPoint event.
Task-number: QTBUG-58071
Change-Id: I768afaf64507ea4835772d4201be031f9f0a43b4
Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
-rw-r--r-- | src/render/backend/pointsvisitor.cpp | 188 | ||||
-rw-r--r-- | src/render/backend/pointsvisitor_p.h | 92 | ||||
-rw-r--r-- | src/render/backend/render-backend.pri | 6 | ||||
-rw-r--r-- | src/render/jobs/pickboundingvolumejob.cpp | 21 | ||||
-rw-r--r-- | src/render/jobs/pickboundingvolumeutils.cpp | 80 | ||||
-rw-r--r-- | src/render/jobs/pickboundingvolumeutils_p.h | 8 | ||||
-rw-r--r-- | src/render/picking/picking.pri | 2 | ||||
-rw-r--r-- | src/render/picking/qpickpointevent.cpp | 131 | ||||
-rw-r--r-- | src/render/picking/qpickpointevent.h | 71 |
9 files changed, 594 insertions, 5 deletions
diff --git a/src/render/backend/pointsvisitor.cpp b/src/render/backend/pointsvisitor.cpp new file mode 100644 index 000000000..663488357 --- /dev/null +++ b/src/render/backend/pointsvisitor.cpp @@ -0,0 +1,188 @@ +/**************************************************************************** +** +** Copyright (C) 2017 Klaralvdalens Datakonsult AB (KDAB). +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Qt3D module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "pointsvisitor_p.h" +#include <Qt3DCore/qentity.h> +#include <Qt3DRender/qgeometryrenderer.h> +#include <Qt3DRender/private/managers_p.h> +#include <Qt3DRender/private/nodemanagers_p.h> +#include <Qt3DRender/private/buffermanager_p.h> +#include <Qt3DRender/private/geometryrenderer_p.h> +#include <Qt3DRender/private/geometryrenderermanager_p.h> +#include <Qt3DRender/private/geometry_p.h> +#include <Qt3DRender/private/attribute_p.h> +#include <Qt3DRender/private/buffer_p.h> +#include <Qt3DRender/private/trianglesvisitor_p.h> +#include <Qt3DRender/private/visitorutils_p.h> + +QT_BEGIN_NAMESPACE + +namespace Qt3DRender { + +namespace Render { + +namespace { + +// indices, vertices are already offset +template<typename Index, typename Vertex> +void traverseCoordinatesIndexed(Index *indices, + Vertex *vertices, + const BufferInfo &indexInfo, + const BufferInfo &vertexInfo, + PointsVisitor *visitor) +{ + uint i = 0; + const uint verticesStride = vertexInfo.byteStride / sizeof(Vertex); + const uint maxVerticesDataSize = qMin(vertexInfo.dataSize, 3U); + + uint ndx; + QVector3D abc; + while (i < indexInfo.count) { + ndx = indices[i]; + const uint idx = ndx * verticesStride; + for (uint j = 0; j < maxVerticesDataSize; ++j) { + abc[j] = vertices[idx + j]; + } + visitor->visit(ndx, abc); + ++i; + } +} + +// vertices are already offset +template<typename Vertex> +void traverseCoordinates(Vertex *vertices, + const BufferInfo &vertexInfo, + PointsVisitor *visitor) +{ + const uint verticesStride = vertexInfo.byteStride / sizeof(Vertex); + const uint maxVerticesDataSize = qMin(vertexInfo.dataSize, 3U); + + uint ndx = 0; + QVector3D abc; + while (ndx < vertexInfo.count) { + const uint idx = ndx * verticesStride; + for (uint j = 0; j < maxVerticesDataSize; ++j) + abc[j] = vertices[idx + j]; + visitor->visit(ndx, abc); + ++ndx; + } +} + +template<typename Index, typename Visitor> +struct IndexedVertexExecutor +{ + template<typename Vertex> + void operator ()(const BufferInfo &vertexInfo, Vertex * vertices) + { + traverseCoordinatesIndexed(m_indices, vertices, m_indexBufferInfo, vertexInfo, m_visitor); + } + + BufferInfo m_indexBufferInfo; + Index *m_indices; + Qt3DRender::QGeometryRenderer::PrimitiveType m_primitiveType; + Visitor* m_visitor; +}; + +template<typename Visitor> +struct IndexExecutor +{ + template<typename Index> + void operator ()( const BufferInfo &indexInfo, Index *indices) + { + IndexedVertexExecutor<Index, Visitor> exec; + exec.m_primitiveType = m_primitiveType; + exec.m_indices = indices; + exec.m_indexBufferInfo = indexInfo; + exec.m_visitor = m_visitor; + Qt3DRender::Render::Visitor::processBuffer(m_vertexBufferInfo, exec); + } + + BufferInfo m_vertexBufferInfo; + Qt3DRender::QGeometryRenderer::PrimitiveType m_primitiveType; + Visitor* m_visitor; +}; + +template<typename Visitor> +struct VertexExecutor +{ + template<typename Vertex> + void operator ()(const BufferInfo &vertexInfo, Vertex *vertices) + { + switch (m_primitiveType) { + case Qt3DRender::QGeometryRenderer::Points: + traverseCoordinates(vertices, vertexInfo, m_visitor); + return; + default: + Q_UNREACHABLE(); + return; + } + } + + Qt3DRender::QGeometryRenderer::PrimitiveType m_primitiveType; + Visitor* m_visitor; +}; + +} // anonymous + + +PointsVisitor::~PointsVisitor() +{ + +} + +void PointsVisitor::apply(const Qt3DCore::QEntity *entity) +{ + GeometryRenderer *renderer = m_manager->geometryRendererManager()->lookupResource(entity->id()); + apply(renderer, entity->id()); +} + +void PointsVisitor::apply(const GeometryRenderer *renderer, const Qt3DCore::QNodeId id) +{ + m_nodeId = id; + if (renderer && renderer->instanceCount() == 1) { + Visitor::visitPrimitives<VertexExecutor<PointsVisitor>, + IndexExecutor<PointsVisitor>, PointsVisitor>(m_manager, renderer, this); + } +} + +} // namespace Render + +} // namespace Qt3DRender + +QT_END_NAMESPACE diff --git a/src/render/backend/pointsvisitor_p.h b/src/render/backend/pointsvisitor_p.h new file mode 100644 index 000000000..9d44ffec5 --- /dev/null +++ b/src/render/backend/pointsvisitor_p.h @@ -0,0 +1,92 @@ +/**************************************************************************** +** +** Copyright (C) 2017 Klaralvdalens Datakonsult AB (KDAB). +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Qt3D module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QT3DRENDER_RENDER_COORDINATESVISITOR_P_H +#define QT3DRENDER_RENDER_COORDINATESVISITOR_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists for the convenience +// of other Qt classes. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include <Qt3DCore/qnodeid.h> + +QT_BEGIN_NAMESPACE + +namespace Qt3DCore { +class QEntity; +} + +namespace Qt3DRender { + +namespace Render { + +class GeometryRenderer; +class NodeManagers; + +class Q_AUTOTEST_EXPORT PointsVisitor +{ +public: + explicit PointsVisitor(NodeManagers *manager) : m_manager(manager) { } + virtual ~PointsVisitor(); + + void apply(const Qt3DCore::QEntity *entity); + void apply(const GeometryRenderer *renderer, const Qt3DCore::QNodeId id); + + virtual void visit(uint ndx, const QVector3D &c) = 0; + +protected: + NodeManagers *m_manager; + Qt3DCore::QNodeId m_nodeId; +}; + +} // namespace Render + +} // namespace Qt3DRender + +QT_END_NAMESPACE + + +#endif // QT3DRENDER_RENDER_COORDINATESVISITOR_P_H diff --git a/src/render/backend/render-backend.pri b/src/render/backend/render-backend.pri index 3d05b0df4..1d18c8efe 100644 --- a/src/render/backend/render-backend.pri +++ b/src/render/backend/render-backend.pri @@ -43,7 +43,8 @@ HEADERS += \ $$PWD/resourceaccessor_p.h \ $$PWD/commandthread_p.h \ $$PWD/visitorutils_p.h \ - $$PWD/segmentsvisitor_p.h + $$PWD/segmentsvisitor_p.h \ + $$PWD/pointsvisitor_p.h SOURCES += \ $$PWD/renderthread.cpp \ @@ -79,7 +80,8 @@ SOURCES += \ $$PWD/offscreensurfacehelper.cpp \ $$PWD/resourceaccessor.cpp \ $$PWD/segmentsvisitor.cpp \ - $$PWD/commandthread.cpp + $$PWD/commandthread.cpp \ + $$PWD/pointsvisitor.cpp include($$QT3D_BUILD_ROOT/src/core/qt3dcore-config.pri) QT_FOR_CONFIG += 3dcore-private diff --git a/src/render/jobs/pickboundingvolumejob.cpp b/src/render/jobs/pickboundingvolumejob.cpp index d10bcb0bd..2f39c6641 100644 --- a/src/render/jobs/pickboundingvolumejob.cpp +++ b/src/render/jobs/pickboundingvolumejob.cpp @@ -40,6 +40,7 @@ #include "pickboundingvolumejob_p.h" #include "qpicktriangleevent.h" #include "qpicklineevent.h" +#include "qpickpointevent.h" #include <Qt3DRender/qgeometryrenderer.h> #include <Qt3DRender/private/renderer_p.h> #include <Qt3DRender/private/nodemanagers_p.h> @@ -223,9 +224,9 @@ bool PickBoundingVolumeJob::runHelper() // If we have move or hover move events that someone cares about, we try to avoid expensive computations // by compressing them into a single one - const bool trianglePickingRequested = (m_renderSettings->pickMethod() == QPickingSettings::TrianglePicking); - const bool edgePickingRequested = (m_renderSettings->pickMethod() == QPickingSettings::LinePicking); - const bool pointPickingRequested = (m_renderSettings->pickMethod() == QPickingSettings::PointPicking); + const bool trianglePickingRequested = (m_renderSettings->pickMethod() & QPickingSettings::TrianglePicking); + const bool edgePickingRequested = (m_renderSettings->pickMethod() & QPickingSettings::LinePicking); + const bool pointPickingRequested = (m_renderSettings->pickMethod() & QPickingSettings::PointPicking); const bool primitivePickingRequested = pointPickingRequested | edgePickingRequested | trianglePickingRequested; const bool allHitsRequested = (m_renderSettings->pickResultMode() == QPickingSettings::AllPicks); const bool frontFaceRequested = @@ -267,6 +268,14 @@ bool PickBoundingVolumeJob::runHelper() sphereHits << gathererFunctor.computeHits(entityPicker.entities(), allHitsRequested); PickingUtils::AbstractCollisionGathererFunctor::sortHits(sphereHits); } + if (pointPickingRequested) { + PickingUtils::PointCollisionGathererFunctor gathererFunctor; + gathererFunctor.m_manager = m_manager; + gathererFunctor.m_ray = ray; + gathererFunctor.m_pickWorldSpaceTolerance = pickWorldSpaceTolerance; + sphereHits << gathererFunctor.computeHits(entityPicker.entities(), allHitsRequested); + PickingUtils::AbstractCollisionGathererFunctor::sortHits(sphereHits); + } if (!primitivePickingRequested) { sphereHits << entityPicker.hits(); PickingUtils::AbstractCollisionGathererFunctor::sortHits(sphereHits); @@ -365,6 +374,12 @@ void PickBoundingVolumeJob::dispatchPickEvents(const QMouseEvent &event, hit.m_vertexIndex[0], hit.m_vertexIndex[1], eventButton, eventButtons, eventModifiers)); break; + case QCollisionQueryResult::Hit::Point: + pickEvent.reset(new QPickPointEvent(event.localPos(), hit.m_intersection, + localIntersection, hit.m_distance, + hit.m_vertexIndex[0], + eventButton, eventButtons, eventModifiers)); + break; case QCollisionQueryResult::Hit::Entity: pickEvent.reset(new QPickEvent(event.localPos(), hit.m_intersection, localIntersection, hit.m_distance, diff --git a/src/render/jobs/pickboundingvolumeutils.cpp b/src/render/jobs/pickboundingvolumeutils.cpp index 80825e6e1..22b92a3f2 100644 --- a/src/render/jobs/pickboundingvolumeutils.cpp +++ b/src/render/jobs/pickboundingvolumeutils.cpp @@ -38,6 +38,7 @@ ****************************************************************************/ #include "pickboundingvolumeutils_p.h" +#include <Qt3DRender/private/geometryrenderer_p.h> #include <Qt3DRender/private/framegraphnode_p.h> #include <Qt3DRender/private/cameralens_p.h> #include <Qt3DRender/private/cameraselectornode_p.h> @@ -49,6 +50,7 @@ #include <Qt3DRender/private/entity_p.h> #include <Qt3DRender/private/trianglesvisitor_p.h> #include <Qt3DRender/private/segmentsvisitor_p.h> +#include <Qt3DRender/private/pointsvisitor_p.h> QT_BEGIN_NAMESPACE @@ -336,6 +338,57 @@ bool LineCollisionVisitor::rayToLineSegment(const QVector3D& lineStart,const QVe return false; } +class PointCollisionVisitor : public PointsVisitor +{ +public: + HitList hits; + + PointCollisionVisitor(NodeManagers* manager, const Entity *root, const RayCasting::QRay3D& ray, + float pickWorldSpaceTolerance) + : PointsVisitor(manager), m_root(root), m_ray(ray) + , m_pointIndex(0), m_pickWorldSpaceTolerance(pickWorldSpaceTolerance) + { + } + +private: + const Entity *m_root; + RayCasting::QRay3D m_ray; + uint m_pointIndex; + float m_pickWorldSpaceTolerance; + + void visit(uint ndx, const QVector3D &p) Q_DECL_OVERRIDE; + + double pointToRayDistance(const QVector3D &a, QVector3D &p) + { + const QVector3D v = a - m_ray.origin(); + const double t = QVector3D::dotProduct(v, m_ray.direction()); + p = m_ray.origin() + t * m_ray.direction(); + return (p - a).length(); + } +}; + + +void PointCollisionVisitor::visit(uint ndx, const QVector3D &p) +{ + const QMatrix4x4 &mat = *m_root->worldTransform(); + const QVector3D tP = mat * p; + QVector3D intersection; + + float d = pointToRayDistance(tP, intersection); + if (d < m_pickWorldSpaceTolerance) { + QCollisionQueryResult::Hit queryResult; + queryResult.m_type = QCollisionQueryResult::Hit::Point; + queryResult.m_entityId = m_root->peerId(); + queryResult.m_primitiveIndex = m_pointIndex; + queryResult.m_vertexIndex[0] = ndx; + queryResult.m_intersection = intersection; + queryResult.m_distance = d; + hits.push_back(queryResult); + } + + m_pointIndex++; +} + HitList reduceToFirstHit(HitList &result, const HitList &intermediate) { if (!intermediate.empty()) { @@ -473,6 +526,33 @@ HitList LineCollisionGathererFunctor::pick(const Entity *entity) const return result; } +HitList PointCollisionGathererFunctor::computeHits(const QVector<Entity *> &entities, bool allHitsRequested) +{ + const auto reducerOp = allHitsRequested ? PickingUtils::reduceToAllHits : PickingUtils::reduceToFirstHit; + return QtConcurrent::blockingMappedReduced<HitList>(entities, *this, reducerOp); +} + +HitList PointCollisionGathererFunctor::pick(const Entity *entity) const +{ + HitList result; + + GeometryRenderer *gRenderer = entity->renderComponent<GeometryRenderer>(); + if (!gRenderer) + return result; + + if (gRenderer->primitiveType() != Qt3DRender::QGeometryRenderer::Points) + return result; + + if (rayHitsEntity(entity)) { + PointCollisionVisitor visitor(m_manager, entity, m_ray, m_pickWorldSpaceTolerance); + visitor.apply(gRenderer, entity->peerId()); + result = visitor.hits; + sortHits(result); + } + + return result; +} + HierarchicalEntityPicker::HierarchicalEntityPicker(const QRay3D &ray) : m_ray(ray) { diff --git a/src/render/jobs/pickboundingvolumeutils_p.h b/src/render/jobs/pickboundingvolumeutils_p.h index ad149fd09..6e2532ea5 100644 --- a/src/render/jobs/pickboundingvolumeutils_p.h +++ b/src/render/jobs/pickboundingvolumeutils_p.h @@ -167,6 +167,14 @@ struct Q_AUTOTEST_EXPORT LineCollisionGathererFunctor : public AbstractCollision HitList pick(const Entity *entity) const Q_DECL_OVERRIDE; }; +struct Q_AUTOTEST_EXPORT PointCollisionGathererFunctor : public AbstractCollisionGathererFunctor +{ + float m_pickWorldSpaceTolerance; + + HitList computeHits(const QVector<Entity *> &entities, bool allHitsRequested) Q_DECL_OVERRIDE; + HitList pick(const Entity *entity) const Q_DECL_OVERRIDE; +}; + } // PickingUtils } // Render diff --git a/src/render/picking/picking.pri b/src/render/picking/picking.pri index fa8611adf..23d65c6f2 100644 --- a/src/render/picking/picking.pri +++ b/src/render/picking/picking.pri @@ -5,6 +5,7 @@ HEADERS += \ $$PWD/qpickevent.h \ $$PWD/qpickevent_p.h \ $$PWD/qpicklineevent.h \ + $$PWD/qpickpointevent.h \ $$PWD/qpicktriangleevent.h \ $$PWD/objectpicker_p.h \ $$PWD/pickeventfilter_p.h \ @@ -14,6 +15,7 @@ SOURCES += \ $$PWD/qobjectpicker.cpp \ $$PWD/qpickevent.cpp \ $$PWD/qpicklineevent.cpp \ + $$PWD/qpickpointevent.cpp \ $$PWD/qpicktriangleevent.cpp \ $$PWD/objectpicker.cpp \ $$PWD/pickeventfilter.cpp diff --git a/src/render/picking/qpickpointevent.cpp b/src/render/picking/qpickpointevent.cpp new file mode 100644 index 000000000..295860e75 --- /dev/null +++ b/src/render/picking/qpickpointevent.cpp @@ -0,0 +1,131 @@ +/**************************************************************************** +** +** Copyright (C) 2017 Klaralvdalens Datakonsult AB (KDAB). +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Qt3D module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qpickpointevent.h" +#include "qpickevent_p.h" +#include <private/qobject_p.h> + +QT_BEGIN_NAMESPACE + +namespace Qt3DRender { + +class QPickPointEventPrivate : public QPickEventPrivate +{ +public: + QPickPointEventPrivate() + : QPickEventPrivate() + , m_pointIndex(0) + { + } + + uint m_pointIndex; +}; + +/*! + \class Qt3DRender::QPickPointEvent + \inmodule Qt3DRender + + \brief The QPickPointEvent class holds information when a segment of a point cloud is picked + + \sa QPickEvent + \since 5.10 +*/ + +/*! + * \qmltype PickPointEvent + * \instantiates Qt3DRender::QPickPointEvent + * \inqmlmodule Qt3D.Render + * \brief PickPointEvent holds information when a segment of a point cloud is picked. + * \sa ObjectPicker + */ + + +/*! + \fn Qt3DRender::QPickPointEvent::QPickPointEvent() + Constructs a new QPickPointEvent. + */ +QPickPointEvent::QPickPointEvent() + : QPickEvent(*new QPickPointEventPrivate()) +{ +} + +QPickPointEvent::QPickPointEvent(const QPointF &position, const QVector3D &worldIntersection, + const QVector3D &localIntersection, float distance, + uint pointIndex, + QPickEvent::Buttons button, int buttons, int modifiers) + : QPickEvent(*new QPickPointEventPrivate()) +{ + Q_D(QPickPointEvent); + d->m_position = position; + d->m_distance = distance; + d->m_worldIntersection = worldIntersection; + d->m_localIntersection = localIntersection; + d->m_pointIndex = pointIndex; + d->m_button = button; + d->m_buttons = buttons; + d->m_modifiers = modifiers; +} + +/*! \internal */ +QPickPointEvent::~QPickPointEvent() +{ +} + +/*! + \qmlproperty uint Qt3D.Render::PickPointEvent::pointIndex + Specifies the index of the point that was picked +*/ +/*! + \property Qt3DRender::QPickPointEvent::pointIndex + Specifies the index of the point that was picked + */ +/*! + * \brief QPickPointEvent::pointIndex + * Returns the index of the picked point + */ +uint QPickPointEvent::pointIndex() const +{ + Q_D(const QPickPointEvent); + return d->m_pointIndex; +} + +} // Qt3DRender + +QT_END_NAMESPACE + diff --git a/src/render/picking/qpickpointevent.h b/src/render/picking/qpickpointevent.h new file mode 100644 index 000000000..fbfebcedd --- /dev/null +++ b/src/render/picking/qpickpointevent.h @@ -0,0 +1,71 @@ +/**************************************************************************** +** +** Copyright (C) 2015 Klaralvdalens Datakonsult AB (KDAB). +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Qt3D module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QT3DRENDER_QPICKPOINTEVENT_H +#define QT3DRENDER_QPICKPOINTEVENT_H + +#include <Qt3DRender/qpickevent.h> + +QT_BEGIN_NAMESPACE + +namespace Qt3DRender { +class QPickPointEventPrivate; + +class QT3DRENDERSHARED_EXPORT QPickPointEvent : public QPickEvent +{ + Q_OBJECT + Q_PROPERTY(uint pointIndex READ pointIndex CONSTANT) +public: + QPickPointEvent(); + QPickPointEvent(const QPointF &position, const QVector3D& worldIntersection, const QVector3D& localIntersection, float distance, + uint pointIndex, Buttons button, int buttons, int modifiers); + ~QPickPointEvent(); + +public: + uint pointIndex() const; + +private: + Q_DECLARE_PRIVATE(QPickPointEvent) +}; + +} // Qt3DRender + +QT_END_NAMESPACE + +#endif // QT3DRENDER_QPICKPOINTEVENT_H |