summaryrefslogtreecommitdiffstats
path: root/src/render/raycasting
diff options
context:
space:
mode:
authorKevin Ottens <kevin.ottens@kdab.com>2015-12-03 14:49:40 +0100
committerSean Harmer <sean.harmer@kdab.com>2015-12-10 17:44:50 +0000
commit5bab5d2f9023ecda899a2eb5b074e1e91cfb8045 (patch)
treee08d81fe1ef3a58c16714e3fd3f7be1a9c7230fc /src/render/raycasting
parent04da7188665ce6f9550807e5cd9c52e3fa717745 (diff)
Move all raycasting code as private in Qt3DRender
Change-Id: I871cbc57166493f30ea307305d8664e2f8a8873f Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
Diffstat (limited to 'src/render/raycasting')
-rw-r--r--src/render/raycasting/qabstractcollisionqueryservice.cpp67
-rw-r--r--src/render/raycasting/qabstractcollisionqueryservice_p.h107
-rw-r--r--src/render/raycasting/qboundingsphere.cpp53
-rw-r--r--src/render/raycasting/qboundingsphere_p.h72
-rw-r--r--src/render/raycasting/qboundingvolume.cpp53
-rw-r--r--src/render/raycasting/qboundingvolume_p.h85
-rw-r--r--src/render/raycasting/qboundingvolumeprovider.cpp52
-rw-r--r--src/render/raycasting/qboundingvolumeprovider_p.h70
-rw-r--r--src/render/raycasting/qcollisionqueryresult.cpp115
-rw-r--r--src/render/raycasting/qcollisionqueryresult_p.h119
-rw-r--r--src/render/raycasting/qraycastingservice.cpp196
-rw-r--r--src/render/raycasting/qraycastingservice_p.h114
-rw-r--r--src/render/raycasting/raycasting.pri17
13 files changed, 1120 insertions, 0 deletions
diff --git a/src/render/raycasting/qabstractcollisionqueryservice.cpp b/src/render/raycasting/qabstractcollisionqueryservice.cpp
new file mode 100644
index 000000000..e28b3a7ea
--- /dev/null
+++ b/src/render/raycasting/qabstractcollisionqueryservice.cpp
@@ -0,0 +1,67 @@
+/****************************************************************************
+**
+** Copyright (C) 2015 Klaralvdalens Datakonsult AB (KDAB).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the Qt3D module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL3$
+** 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 http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://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.LGPLv3 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.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 later as published by the Free
+** Software Foundation and appearing in the file LICENSE.GPL included in
+** the packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 2.0 requirements will be
+** met: http://www.gnu.org/licenses/gpl-2.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qabstractcollisionqueryservice_p.h"
+
+#include "qcollisionqueryresult_p.h"
+
+QT_BEGIN_NAMESPACE
+
+namespace Qt3DRender {
+
+QAbstractCollisionQueryService::QAbstractCollisionQueryService(const QString &description)
+ : QAbstractServiceProvider(*new QAbstractCollisionQueryServicePrivate(description))
+{
+}
+
+QAbstractCollisionQueryService::QAbstractCollisionQueryService(QAbstractCollisionQueryServicePrivate &dd)
+ : QAbstractServiceProvider(dd)
+{
+}
+
+void QAbstractCollisionQueryService::setResultHandle(QCollisionQueryResult &result, const QQueryHandle &handle)
+{
+ result.d_func()->setHandle(handle);
+}
+
+void QAbstractCollisionQueryService::addEntityHit(QCollisionQueryResult &result, const Qt3DCore::QNodeId &entity)
+{
+ result.d_func()->addEntityHit(entity);
+}
+
+} // Qt3DRender
+
+QT_END_NAMESPACE
diff --git a/src/render/raycasting/qabstractcollisionqueryservice_p.h b/src/render/raycasting/qabstractcollisionqueryservice_p.h
new file mode 100644
index 000000000..286f4f932
--- /dev/null
+++ b/src/render/raycasting/qabstractcollisionqueryservice_p.h
@@ -0,0 +1,107 @@
+/****************************************************************************
+**
+** Copyright (C) 2015 Klaralvdalens Datakonsult AB (KDAB).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the Qt3D module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL3$
+** 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 http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://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.LGPLv3 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.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 later as published by the Free
+** Software Foundation and appearing in the file LICENSE.GPL included in
+** the packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 2.0 requirements will be
+** met: http://www.gnu.org/licenses/gpl-2.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QT3DRENDER_QABSTRACTCOLLISIONQUERYSERVICE_P_H
+#define QT3DRENDER_QABSTRACTCOLLISIONQUERYSERVICE_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 <QVector>
+
+#include <Qt3DRender/qt3drender_global.h>
+#include <Qt3DCore/qservicelocator.h>
+#include <Qt3DCore/qnodeid.h>
+#include <Qt3DCore/private/qabstractserviceprovider_p.h>
+#include <Qt3DRender/private/qcollisionqueryresult_p.h>
+
+QT_BEGIN_NAMESPACE
+
+namespace Qt3DCore {
+class QRay3D;
+}
+
+namespace Qt3DRender {
+
+class QBoundingVolumeProvider;
+
+class QAbstractCollisionQueryServicePrivate : public Qt3DCore::QAbstractServiceProviderPrivate
+{
+public:
+ QAbstractCollisionQueryServicePrivate(const QString &description)
+ : QAbstractServiceProviderPrivate(Qt3DCore::QServiceLocator::CollisionService, description)
+ {}
+};
+
+class QT3DRENDERSHARED_EXPORT QAbstractCollisionQueryService : public Qt3DCore::QAbstractServiceProvider
+{
+public:
+ enum QueryMode {
+ FirstHit,
+ AllHits
+ };
+
+ virtual QQueryHandle query(const Qt3DCore::QRay3D &ray, QueryMode mode, QBoundingVolumeProvider *provider) = 0;
+
+ virtual QCollisionQueryResult fetchResult(const QQueryHandle &handle) = 0;
+ virtual QVector<QCollisionQueryResult> fetchAllResults() const = 0;
+
+protected:
+ QAbstractCollisionQueryService(const QString &description = QString());
+ QAbstractCollisionQueryService(QAbstractCollisionQueryServicePrivate &dd);
+
+ void setResultHandle(QCollisionQueryResult &result, const QQueryHandle &handle);
+ void addEntityHit(QCollisionQueryResult &result, const Qt3DCore::QNodeId &entity);
+
+private:
+ Q_DECLARE_PRIVATE(QAbstractCollisionQueryService)
+};
+
+} // Qt3DRender
+
+QT_END_NAMESPACE
+
+Q_DECLARE_METATYPE(Qt3DRender::QAbstractCollisionQueryService::QueryMode)
+
+#endif // QT3DRENDER_QABSTRACTCOLLISIONQUERYSERVICE_P_H
diff --git a/src/render/raycasting/qboundingsphere.cpp b/src/render/raycasting/qboundingsphere.cpp
new file mode 100644
index 000000000..1c6915cf4
--- /dev/null
+++ b/src/render/raycasting/qboundingsphere.cpp
@@ -0,0 +1,53 @@
+/****************************************************************************
+**
+** Copyright (C) 2015 Klaralvdalens Datakonsult AB (KDAB).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the Qt3D module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL3$
+** 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 http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://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.LGPLv3 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.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 later as published by the Free
+** Software Foundation and appearing in the file LICENSE.GPL included in
+** the packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 2.0 requirements will be
+** met: http://www.gnu.org/licenses/gpl-2.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qboundingsphere_p.h"
+
+QT_BEGIN_NAMESPACE
+
+namespace Qt3DRender {
+
+QBoundingSphere::QBoundingSphere()
+{
+}
+
+QBoundingSphere::~QBoundingSphere()
+{
+}
+
+} // namespace Qt3DRender
+
+QT_END_NAMESPACE
diff --git a/src/render/raycasting/qboundingsphere_p.h b/src/render/raycasting/qboundingsphere_p.h
new file mode 100644
index 000000000..c05fb7613
--- /dev/null
+++ b/src/render/raycasting/qboundingsphere_p.h
@@ -0,0 +1,72 @@
+/****************************************************************************
+**
+** Copyright (C) 2015 Klaralvdalens Datakonsult AB (KDAB).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the Qt3D module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL3$
+** 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 http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://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.LGPLv3 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.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 later as published by the Free
+** Software Foundation and appearing in the file LICENSE.GPL included in
+** the packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 2.0 requirements will be
+** met: http://www.gnu.org/licenses/gpl-2.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QT3DRENDER_QBOUNDINGSPHERE_P_H
+#define QT3DRENDER_QBOUNDINGSPHERE_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 <Qt3DRender/qt3drender_global.h>
+#include <Qt3DRender/private/qboundingvolume_p.h>
+
+QT_BEGIN_NAMESPACE
+
+namespace Qt3DRender {
+
+class QT3DRENDERSHARED_EXPORT QBoundingSphere : public QBoundingVolume
+{
+public:
+ QBoundingSphere();
+ ~QBoundingSphere();
+
+ virtual QVector3D center() const = 0;
+ virtual float radius() const = 0;
+};
+
+} // namespace Qt3DRender
+
+QT_END_NAMESPACE
+
+#endif // QT3DRENDER_QBOUNDINGSPHERE_P_H
diff --git a/src/render/raycasting/qboundingvolume.cpp b/src/render/raycasting/qboundingvolume.cpp
new file mode 100644
index 000000000..414f4f278
--- /dev/null
+++ b/src/render/raycasting/qboundingvolume.cpp
@@ -0,0 +1,53 @@
+/****************************************************************************
+**
+** Copyright (C) 2015 Klaralvdalens Datakonsult AB (KDAB).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the Qt3D module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL3$
+** 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 http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://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.LGPLv3 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.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 later as published by the Free
+** Software Foundation and appearing in the file LICENSE.GPL included in
+** the packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 2.0 requirements will be
+** met: http://www.gnu.org/licenses/gpl-2.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qboundingvolume_p.h"
+
+QT_BEGIN_NAMESPACE
+
+namespace Qt3DRender {
+
+QBoundingVolume::QBoundingVolume()
+{
+}
+
+QBoundingVolume::~QBoundingVolume()
+{
+}
+
+} // namespace Qt3DRender
+
+QT_END_NAMESPACE
diff --git a/src/render/raycasting/qboundingvolume_p.h b/src/render/raycasting/qboundingvolume_p.h
new file mode 100644
index 000000000..b426870a2
--- /dev/null
+++ b/src/render/raycasting/qboundingvolume_p.h
@@ -0,0 +1,85 @@
+/****************************************************************************
+**
+** Copyright (C) 2015 Klaralvdalens Datakonsult AB (KDAB).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the Qt3D module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL3$
+** 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 http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://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.LGPLv3 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.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 later as published by the Free
+** Software Foundation and appearing in the file LICENSE.GPL included in
+** the packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 2.0 requirements will be
+** met: http://www.gnu.org/licenses/gpl-2.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QT3DRENDER_QBOUNDINGVOLUME_P_H
+#define QT3DRENDER_QBOUNDINGVOLUME_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 <Qt3DRender/qt3drender_global.h>
+#include <Qt3DCore/qnodeid.h>
+
+QT_BEGIN_NAMESPACE
+
+namespace Qt3DCore {
+class QRay3D;
+}
+
+namespace Qt3DRender {
+
+class QT3DRENDERSHARED_EXPORT QBoundingVolume
+{
+public:
+ QBoundingVolume();
+ virtual ~QBoundingVolume();
+
+ enum Type {
+ Sphere = 0,
+ Triangle
+ };
+
+ virtual Qt3DCore::QNodeId id() const = 0;
+ virtual bool intersects(const Qt3DCore::QRay3D &ray, QVector3D *q = Q_NULLPTR) const = 0;
+
+ virtual Type type() const = 0;
+};
+
+} // namespace Qt3DRender
+
+QT_END_NAMESPACE
+
+Q_DECLARE_METATYPE(Qt3DRender::QBoundingVolume*)
+
+#endif // QT3DRENDER_QBOUNDINGVOLUME_P_H
diff --git a/src/render/raycasting/qboundingvolumeprovider.cpp b/src/render/raycasting/qboundingvolumeprovider.cpp
new file mode 100644
index 000000000..cff36e906
--- /dev/null
+++ b/src/render/raycasting/qboundingvolumeprovider.cpp
@@ -0,0 +1,52 @@
+/****************************************************************************
+**
+** Copyright (C) 2015 Klaralvdalens Datakonsult AB (KDAB).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the Qt3D module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL3$
+** 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 http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://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.LGPLv3 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.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 later as published by the Free
+** Software Foundation and appearing in the file LICENSE.GPL included in
+** the packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 2.0 requirements will be
+** met: http://www.gnu.org/licenses/gpl-2.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qboundingvolumeprovider_p.h"
+
+
+QT_BEGIN_NAMESPACE
+
+namespace Qt3DRender {
+
+QBoundingVolumeProvider::~QBoundingVolumeProvider()
+{
+
+}
+
+
+} // Qt3DRender
+
+QT_END_NAMESPACE
diff --git a/src/render/raycasting/qboundingvolumeprovider_p.h b/src/render/raycasting/qboundingvolumeprovider_p.h
new file mode 100644
index 000000000..3f38a6f6c
--- /dev/null
+++ b/src/render/raycasting/qboundingvolumeprovider_p.h
@@ -0,0 +1,70 @@
+/****************************************************************************
+**
+** Copyright (C) 2015 Klaralvdalens Datakonsult AB (KDAB).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the Qt3D module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL3$
+** 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 http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://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.LGPLv3 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.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 later as published by the Free
+** Software Foundation and appearing in the file LICENSE.GPL included in
+** the packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 2.0 requirements will be
+** met: http://www.gnu.org/licenses/gpl-2.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QT3DRENDER_QBOUNDINGVOLUMEPROVIDER_P_H
+#define QT3DRENDER_QBOUNDINGVOLUMEPROVIDER_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 <Qt3DRender/qt3drender_global.h>
+
+QT_BEGIN_NAMESPACE
+
+namespace Qt3DRender {
+
+class QBoundingVolume;
+
+class QT3DRENDERSHARED_EXPORT QBoundingVolumeProvider
+{
+public:
+ virtual ~QBoundingVolumeProvider();
+ virtual QVector<QBoundingVolume *> boundingVolumes() const = 0;
+};
+
+} // namespace Qt3DRender
+
+QT_END_NAMESPACE
+
+#endif // QT3DRENDER_QBOUNDINGVOLUMEPROVIDER_P_H
diff --git a/src/render/raycasting/qcollisionqueryresult.cpp b/src/render/raycasting/qcollisionqueryresult.cpp
new file mode 100644
index 000000000..cf2ea0a9a
--- /dev/null
+++ b/src/render/raycasting/qcollisionqueryresult.cpp
@@ -0,0 +1,115 @@
+/****************************************************************************
+**
+** Copyright (C) 2015 Klaralvdalens Datakonsult AB (KDAB).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the Qt3D module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL3$
+** 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 http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://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.LGPLv3 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.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 later as published by the Free
+** Software Foundation and appearing in the file LICENSE.GPL included in
+** the packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 2.0 requirements will be
+** met: http://www.gnu.org/licenses/gpl-2.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qcollisionqueryresult_p.h"
+
+QT_BEGIN_NAMESPACE
+
+namespace Qt3DRender {
+
+QCollisionQueryResultPrivate::QCollisionQueryResultPrivate()
+ : QSharedData()
+{
+}
+
+QCollisionQueryResultPrivate::QCollisionQueryResultPrivate(const QCollisionQueryResultPrivate &copy)
+ : QSharedData(copy)
+ , m_handle(copy.m_handle)
+ , m_entitiesHit(copy.m_entitiesHit)
+{
+}
+
+void QCollisionQueryResultPrivate::addEntityHit(const Qt3DCore::QNodeId &entity)
+{
+ m_entitiesHit.append(entity);
+}
+
+void QCollisionQueryResultPrivate::setHandle(const QQueryHandle &handle)
+{
+ m_handle = handle;
+}
+
+QCollisionQueryResult::QCollisionQueryResult()
+ : d_ptr(new QCollisionQueryResultPrivate())
+{
+}
+
+QCollisionQueryResult::QCollisionQueryResult(const QCollisionQueryResult &result)
+ : d_ptr(result.d_ptr)
+{
+}
+
+QCollisionQueryResult::~QCollisionQueryResult()
+{
+}
+
+QCollisionQueryResult &QCollisionQueryResult::operator=(const QCollisionQueryResult &result)
+{
+ d_ptr = result.d_ptr;
+ return *this;
+}
+
+QVector<Qt3DCore::QNodeId> QCollisionQueryResult::entitiesHit() const
+{
+ Q_D(const QCollisionQueryResult);
+ return d->m_entitiesHit;
+}
+
+/*!
+ \internal
+*/
+QCollisionQueryResult::QCollisionQueryResult(QCollisionQueryResultPrivate &p)
+ : d_ptr(&p)
+{
+}
+
+/*!
+ \internal
+*/
+QCollisionQueryResultPrivate *QCollisionQueryResult::d_func()
+{
+ return d_ptr.data();
+}
+
+QQueryHandle QCollisionQueryResult::handle() const
+{
+ Q_D(const QCollisionQueryResult);
+ return d->m_handle;
+}
+
+} // Qt3DRender
+
+QT_END_NAMESPACE
diff --git a/src/render/raycasting/qcollisionqueryresult_p.h b/src/render/raycasting/qcollisionqueryresult_p.h
new file mode 100644
index 000000000..c4eb164ff
--- /dev/null
+++ b/src/render/raycasting/qcollisionqueryresult_p.h
@@ -0,0 +1,119 @@
+/****************************************************************************
+**
+** Copyright (C) 2015 Klaralvdalens Datakonsult AB (KDAB).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the Qt3D module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL3$
+** 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 http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://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.LGPLv3 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.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 later as published by the Free
+** Software Foundation and appearing in the file LICENSE.GPL included in
+** the packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 2.0 requirements will be
+** met: http://www.gnu.org/licenses/gpl-2.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QT3DRENDER_QCOLLISIONQUERYRESULT_P_H
+#define QT3DRENDER_QCOLLISIONQUERYRESULT_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 <Qt3DRender/qt3drender_global.h>
+#include <Qt3DCore/qnodeid.h>
+#include <QVector>
+#include <QSharedData>
+
+QT_BEGIN_NAMESPACE
+
+namespace Qt3DRender {
+
+typedef int QQueryHandle;
+
+class QCollisionQueryResultPrivate : public QSharedData
+{
+public:
+ explicit QCollisionQueryResultPrivate();
+ explicit QCollisionQueryResultPrivate(const QCollisionQueryResultPrivate &copy);
+
+ void setHandle(const QQueryHandle &handle);
+ void addEntityHit(const Qt3DCore::QNodeId &entity);
+
+ QQueryHandle m_handle;
+ QVector<Qt3DCore::QNodeId> m_entitiesHit;
+};
+
+class QT3DRENDERSHARED_EXPORT QCollisionQueryResult
+{
+public:
+ QCollisionQueryResult();
+ QCollisionQueryResult(const QCollisionQueryResult &);
+ ~QCollisionQueryResult();
+
+ QCollisionQueryResult &operator=(const QCollisionQueryResult &);
+#ifdef Q_COMPILER_RVALUE_REFS
+ QCollisionQueryResult &operator=(QCollisionQueryResult &&other) Q_DECL_NOTHROW
+ {
+ swap(other);
+ return *this;
+ }
+#endif
+
+ void swap(QCollisionQueryResult &other) Q_DECL_NOTHROW
+ {
+ qSwap(d_ptr, other.d_ptr);
+ }
+
+ QQueryHandle handle() const;
+ QVector<Qt3DCore::QNodeId> entitiesHit() const;
+
+private:
+ friend class QAbstractCollisionQueryService;
+
+ explicit QCollisionQueryResult(QCollisionQueryResultPrivate &p);
+
+ QSharedDataPointer<QCollisionQueryResultPrivate> d_ptr;
+ // Q_DECLARE_PRIVATE equivalent for shared data pointers
+ QCollisionQueryResultPrivate *d_func();
+ inline const QCollisionQueryResultPrivate *d_func() const
+ {
+ return d_ptr.constData();
+ }
+};
+
+} // Qt3DRender
+
+Q_DECLARE_SHARED(Qt3DRender::QCollisionQueryResult)
+
+QT_END_NAMESPACE
+
+#endif // QT3DRENDER_QCOLLISIONQUERYRESULT_P_H
diff --git a/src/render/raycasting/qraycastingservice.cpp b/src/render/raycasting/qraycastingservice.cpp
new file mode 100644
index 000000000..8e897ec14
--- /dev/null
+++ b/src/render/raycasting/qraycastingservice.cpp
@@ -0,0 +1,196 @@
+/****************************************************************************
+**
+** Copyright (C) 2015 Klaralvdalens Datakonsult AB (KDAB).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the Qt3D module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL3$
+** 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 http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://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.LGPLv3 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.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 later as published by the Free
+** Software Foundation and appearing in the file LICENSE.GPL included in
+** the packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 2.0 requirements will be
+** met: http://www.gnu.org/licenses/gpl-2.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qraycastingservice_p.h"
+
+#include <Qt3DCore/qray3d.h>
+#include <Qt3DRender/private/sphere_p.h>
+#include <Qt3DRender/private/qboundingvolumeprovider_p.h>
+
+#include <QMap>
+#include <QtConcurrent>
+
+#include "math.h"
+
+QT_BEGIN_NAMESPACE
+
+using namespace Qt3DCore;
+
+namespace Qt3DRender {
+
+namespace {
+
+struct Hit
+{
+ Hit()
+ : intersects(false)
+ , distance(-1.0f)
+ {}
+
+ bool intersects;
+ float distance;
+ Qt3DCore::QNodeId id;
+ QVector3D intersection;
+};
+
+bool compareHitsDistance(const Hit &a, const Hit &b)
+{
+ return a.distance < b.distance;
+}
+
+Hit volumeRayIntersection(const QBoundingVolume *volume, const Qt3DCore::QRay3D &ray)
+{
+ Hit hit;
+ if ((hit.intersects = volume->intersects(ray, &hit.intersection))) {
+ hit.distance = ray.projectedDistance(hit.intersection);
+ hit.id = volume->id();
+ }
+ return hit;
+}
+
+Hit reduceToFirstHit(Hit &result, const Hit &intermediate)
+{
+ if (intermediate.intersects) {
+ if (result.distance == -1.0f ||
+ (intermediate.distance >= 0.0f &&
+ intermediate.distance < result.distance))
+ result = intermediate;
+ }
+ return result;
+}
+
+// Unordered
+QVector<Hit> reduceToAllHits(QVector<Hit> &results, const Hit &intermediate)
+{
+ if (intermediate.intersects)
+ results.push_back(intermediate);
+ return results;
+}
+
+struct CollisionGathererFunctor
+{
+ Qt3DCore::QRay3D ray;
+
+ typedef Hit result_type;
+
+ Hit operator ()(const QBoundingVolume *volume) const
+ {
+ return volumeRayIntersection(volume, ray);
+ }
+};
+
+} // anonymous
+
+
+QCollisionQueryResult QRayCastingServicePrivate::collides(const Qt3DCore::QRay3D &ray, QBoundingVolumeProvider *provider,
+ QAbstractCollisionQueryService::QueryMode mode, const QQueryHandle &handle)
+{
+ Q_Q(QRayCastingService);
+
+ const QVector<QBoundingVolume *> volumes(provider->boundingVolumes());
+ QCollisionQueryResult result;
+ q->setResultHandle(result, handle);
+
+ CollisionGathererFunctor gathererFunctor;
+ gathererFunctor.ray = ray;
+
+ if (mode == QAbstractCollisionQueryService::FirstHit) {
+ Hit firstHit = QtConcurrent::blockingMappedReduced<Hit>(volumes, gathererFunctor, reduceToFirstHit);
+ if (firstHit.intersects)
+ q->addEntityHit(result, firstHit.id);
+ } else {
+ QVector<Hit> hits = QtConcurrent::blockingMappedReduced<QVector<Hit> >(volumes, gathererFunctor, reduceToAllHits);
+ std::sort(hits.begin(), hits.end(), compareHitsDistance);
+ Q_FOREACH (const Hit &hit, hits)
+ q->addEntityHit(result, hit.id);
+ }
+
+ return result;
+}
+
+QRayCastingServicePrivate::QRayCastingServicePrivate(const QString &description)
+ : QAbstractCollisionQueryServicePrivate(description)
+ , m_handlesCount(0)
+{
+}
+
+QRayCastingService::QRayCastingService()
+ : QAbstractCollisionQueryService(*new QRayCastingServicePrivate(QStringLiteral("Collision detection service using Ray Casting")))
+{
+}
+
+QQueryHandle QRayCastingService::query(const Qt3DCore::QRay3D &ray,
+ QAbstractCollisionQueryService::QueryMode mode,
+ QBoundingVolumeProvider *provider)
+{
+ Q_D(QRayCastingService);
+
+ QQueryHandle handle = d->m_handlesCount.fetchAndStoreOrdered(1);
+
+
+ // Blocking mapReduce
+
+ FutureQueryResult future = QtConcurrent::run(d, &QRayCastingServicePrivate::collides,
+ ray, provider, mode, handle);
+ d->m_results.insert(handle, future);
+
+ return handle;
+}
+
+QCollisionQueryResult QRayCastingService::fetchResult(const QQueryHandle &handle)
+{
+ Q_D(QRayCastingService);
+
+ return d->m_results.value(handle).result();
+}
+
+QVector<QCollisionQueryResult> QRayCastingService::fetchAllResults() const
+{
+ Q_D(const QRayCastingService);
+
+ const QList<FutureQueryResult> futureResults = d->m_results.values();
+ QVector<QCollisionQueryResult> results;
+ results.reserve(futureResults.size());
+
+ Q_FOREACH (const FutureQueryResult &future, futureResults)
+ results.append(future.result());
+
+ return results;
+}
+
+} // namespace Qt3DRender
+
+QT_END_NAMESPACE
diff --git a/src/render/raycasting/qraycastingservice_p.h b/src/render/raycasting/qraycastingservice_p.h
new file mode 100644
index 000000000..b4fdc1549
--- /dev/null
+++ b/src/render/raycasting/qraycastingservice_p.h
@@ -0,0 +1,114 @@
+/****************************************************************************
+**
+** Copyright (C) 2015 Klaralvdalens Datakonsult AB (KDAB).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the Qt3D module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL3$
+** 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 http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://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.LGPLv3 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.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 later as published by the Free
+** Software Foundation and appearing in the file LICENSE.GPL included in
+** the packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 2.0 requirements will be
+** met: http://www.gnu.org/licenses/gpl-2.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QT3DRENDER_QRAYCASTINGSERVICE_P_H
+#define QT3DRENDER_QRAYCASTINGSERVICE_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/qt3dcore_global.h>
+#include <Qt3DRender/private/qabstractcollisionqueryservice_p.h>
+#include <Qt3DCore/qray3d.h>
+
+#include <QHash>
+#include <QtConcurrent>
+#include <QAtomicInt>
+
+QT_BEGIN_NAMESPACE
+
+namespace Qt3DRender {
+
+class QBoundingVolume;
+class QBoundingVolumeProvider;
+class QRayCastingServicePrivate;
+
+typedef QFuture<QCollisionQueryResult> FutureQueryResult;
+
+class QT3DRENDERSHARED_EXPORT QRayCastingService : public QAbstractCollisionQueryService
+{
+public:
+ QRayCastingService();
+
+ QQueryHandle query(const Qt3DCore::QRay3D &ray, QueryMode mode, QBoundingVolumeProvider *provider) Q_DECL_OVERRIDE;
+
+ QCollisionQueryResult fetchResult(const QQueryHandle &handle) Q_DECL_OVERRIDE;
+ QVector<QCollisionQueryResult> fetchAllResults() const Q_DECL_OVERRIDE;
+
+protected:
+ QRayCastingService(QRayCastingServicePrivate &dd);
+
+private:
+ Q_DISABLE_COPY(QRayCastingService)
+ Q_DECLARE_PRIVATE(QRayCastingService)
+};
+
+class QRayCastingServicePrivate : public QAbstractCollisionQueryServicePrivate
+{
+public:
+ QRayCastingServicePrivate(const QString &description);
+
+ QCollisionQueryResult collides(const Qt3DCore::QRay3D &ray,
+ QBoundingVolumeProvider *provider,
+ QAbstractCollisionQueryService::QueryMode mode,
+ const QQueryHandle &handle);
+
+ Q_DECLARE_PUBLIC(QRayCastingService)
+
+ struct Query
+ {
+ QQueryHandle handle;
+ Qt3DCore::QRay3D ray;
+ QRayCastingService::QueryMode mode;
+ };
+
+ QHash<QQueryHandle, FutureQueryResult> m_results;
+ QAtomicInt m_handlesCount;
+};
+
+} // namespace Qt3DRender
+
+QT_END_NAMESPACE
+
+#endif // QT3DRENDER_QRAYCASTINGSERVICE_P_H
diff --git a/src/render/raycasting/raycasting.pri b/src/render/raycasting/raycasting.pri
new file mode 100644
index 000000000..fdd4be17f
--- /dev/null
+++ b/src/render/raycasting/raycasting.pri
@@ -0,0 +1,17 @@
+INCLUDEPATH += $$PWD
+
+HEADERS += \
+ $$PWD/qabstractcollisionqueryservice_p.h \
+ $$PWD/qboundingsphere_p.h \
+ $$PWD/qboundingvolume_p.h \
+ $$PWD/qboundingvolumeprovider_p.h \
+ $$PWD/qcollisionqueryresult_p.h \
+ $$PWD/qraycastingservice_p.h
+
+SOURCES += \
+ $$PWD/qabstractcollisionqueryservice.cpp \
+ $$PWD/qboundingsphere.cpp \
+ $$PWD/qboundingvolume.cpp \
+ $$PWD/qboundingvolumeprovider.cpp \
+ $$PWD/qcollisionqueryresult.cpp \
+ $$PWD/qraycastingservice.cpp