summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRĂ©mi Benoit <remi.benoit@kdab.com>2015-03-11 11:16:45 +0100
committerPaul Lemire <paul.lemire@kdab.com>2015-08-09 21:08:18 +0000
commit4c5e74986b0e649e4aadbc76022ad18c17ef44dc (patch)
treec9caf570c439b592a651f6d4b8f8ab4690bfb26a
parentc089032f9f86bae15310e43f7941d78f233ee126 (diff)
Collision detection service skeleton
Change-Id: Icefe43edc8faca640ac9e1f6863f503a9fb7af1c Reviewed-by: Paul Lemire <paul.lemire@kdab.com>
-rw-r--r--src/core/services/nullservices_p.h32
-rw-r--r--src/core/services/qabstractcollisionqueryservice.cpp68
-rw-r--r--src/core/services/qabstractcollisionqueryservice.h84
-rw-r--r--src/core/services/qabstractcollisionqueryservice_p.h60
-rw-r--r--src/core/services/qabstractserviceprovider_p.h3
-rw-r--r--src/core/services/qcollisionqueryresult.cpp78
-rw-r--r--src/core/services/qcollisionqueryresult.h71
-rw-r--r--src/core/services/qcollisionqueryresult_p.h66
-rw-r--r--src/core/services/qservicelocator.cpp2
-rw-r--r--src/core/services/qservicelocator.h1
-rw-r--r--src/core/services/services.pri7
11 files changed, 472 insertions, 0 deletions
diff --git a/src/core/services/nullservices_p.h b/src/core/services/nullservices_p.h
index 48792d799..3529791a5 100644
--- a/src/core/services/nullservices_p.h
+++ b/src/core/services/nullservices_p.h
@@ -38,8 +38,10 @@
#define QT3D_NULLSERVICES_P_H
#include <Qt3DCore/qt3dcore_global.h>
+#include <Qt3DCore/qray3d.h>
#include "qopenglinformationservice.h"
#include "qsysteminformationservice.h"
+#include "qabstractcollisionqueryservice.h"
QT_BEGIN_NAMESPACE
@@ -69,6 +71,36 @@ public:
QSurfaceFormat format() const Q_DECL_FINAL { return QSurfaceFormat(); }
};
+class NullCollisionQueryService : public QAbstractCollisionQueryService
+{
+public:
+ NullCollisionQueryService()
+ : QAbstractCollisionQueryService(QStringLiteral("Null Collision Query Service"))
+ {}
+ ~NullCollisionQueryService() {}
+
+ QQueryHandle query(const QRay3D &ray, QueryMode mode) Q_DECL_OVERRIDE
+ {
+ Q_UNUSED(ray);
+ Q_UNUSED(mode);
+
+ return 0;
+ }
+
+ QCollisionQueryResult fetchResult(const QQueryHandle &handle) Q_DECL_OVERRIDE
+ {
+ Q_UNUSED(handle);
+
+ QCollisionQueryResult result;
+ return result;
+ }
+
+ QVector<QCollisionQueryResult> fetchAllResults() const Q_DECL_OVERRIDE
+ {
+ return QVector<QCollisionQueryResult>();
+ }
+};
+
} // namespace Qt3D
QT_END_NAMESPACE
diff --git a/src/core/services/qabstractcollisionqueryservice.cpp b/src/core/services/qabstractcollisionqueryservice.cpp
new file mode 100644
index 000000000..f2731cac5
--- /dev/null
+++ b/src/core/services/qabstractcollisionqueryservice.cpp
@@ -0,0 +1,68 @@
+/****************************************************************************
+**
+** 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.h"
+#include "qabstractcollisionqueryservice_p.h"
+
+#include "qcollisionqueryresult_p.h"
+
+QT_BEGIN_NAMESPACE
+
+namespace Qt3D {
+
+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 QNodeId &entity)
+{
+ result.d_func()->addEntityHit(entity);
+}
+
+} // Qt3D
+
+QT_END_NAMESPACE
diff --git a/src/core/services/qabstractcollisionqueryservice.h b/src/core/services/qabstractcollisionqueryservice.h
new file mode 100644
index 000000000..69afd6d85
--- /dev/null
+++ b/src/core/services/qabstractcollisionqueryservice.h
@@ -0,0 +1,84 @@
+/****************************************************************************
+**
+** 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 QT3D_QABSTRACTCOLLISIONQUERYSERVICE_H
+#define QT3D_QABSTRACTCOLLISIONQUERYSERVICE_H
+
+#include <QVector>
+
+#include <Qt3DCore/qt3dcore_global.h>
+#include <Qt3DCore/qservicelocator.h>
+#include <Qt3DCore/qnodeid.h>
+#include <Qt3DCore/qcollisionqueryresult.h>
+
+QT_BEGIN_NAMESPACE
+
+namespace Qt3D {
+
+class QRay3D;
+class QAbstractCollisionQueryServicePrivate;
+
+class QT3DCORESHARED_EXPORT QAbstractCollisionQueryService : public QAbstractServiceProvider
+{
+public:
+ enum QueryMode {
+ FirstHit,
+ AllHits
+ };
+
+ virtual QQueryHandle query(const QRay3D &ray, QueryMode mode) = 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 QNodeId &entity);
+
+private:
+ Q_DECLARE_PRIVATE(QAbstractCollisionQueryService)
+};
+
+} // Qt3D
+
+QT_END_NAMESPACE
+
+Q_DECLARE_METATYPE(Qt3D::QAbstractCollisionQueryService::QueryMode)
+
+#endif // QT3D_QABSTRACTCOLLISIONQUERYSERVICE_H
diff --git a/src/core/services/qabstractcollisionqueryservice_p.h b/src/core/services/qabstractcollisionqueryservice_p.h
new file mode 100644
index 000000000..458988d0f
--- /dev/null
+++ b/src/core/services/qabstractcollisionqueryservice_p.h
@@ -0,0 +1,60 @@
+/****************************************************************************
+**
+** 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 QT3D_QABSTRACTCOLLISIONQUERYSERVICE_P_H
+#define QT3D_QABSTRACTCOLLISIONQUERYSERVICE_P_H
+
+#include <Qt3DCore/qt3dcore_global.h>
+#include <Qt3DCore/private/qabstractserviceprovider_p.h>
+#include <Qt3DCore/qservicelocator.h>
+
+QT_BEGIN_NAMESPACE
+
+namespace Qt3D {
+
+class QAbstractCollisionQueryServicePrivate : public QAbstractServiceProviderPrivate
+{
+public:
+ QAbstractCollisionQueryServicePrivate(const QString &description)
+ : QAbstractServiceProviderPrivate(QServiceLocator::CollisionService, description)
+ {}
+};
+
+} // Qt3D
+
+QT_END_NAMESPACE
+
+#endif // QT3D_QAbstractCOLLISIONQUERYSERVICE_P_H
diff --git a/src/core/services/qabstractserviceprovider_p.h b/src/core/services/qabstractserviceprovider_p.h
index 05a5107c5..3dc94274c 100644
--- a/src/core/services/qabstractserviceprovider_p.h
+++ b/src/core/services/qabstractserviceprovider_p.h
@@ -52,6 +52,9 @@ public:
, m_description(description)
{}
+ Q_DECLARE_PUBLIC(QAbstractServiceProvider)
+ QAbstractServiceProvider *q_ptr;
+
int m_type;
QString m_description;
};
diff --git a/src/core/services/qcollisionqueryresult.cpp b/src/core/services/qcollisionqueryresult.cpp
new file mode 100644
index 000000000..eac2e92ce
--- /dev/null
+++ b/src/core/services/qcollisionqueryresult.cpp
@@ -0,0 +1,78 @@
+/****************************************************************************
+**
+** 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.h"
+#include "qcollisionqueryresult_p.h"
+
+QT_BEGIN_NAMESPACE
+
+namespace Qt3D {
+
+QCollisionQueryResultPrivate::QCollisionQueryResultPrivate(QCollisionQueryResult *qq)
+ : q_ptr(qq)
+{
+}
+
+void QCollisionQueryResultPrivate::addEntityHit(const QNodeId &entity)
+{
+ m_entitiesHit.append(entity);
+}
+
+void QCollisionQueryResultPrivate::setHandle(const QQueryHandle &handle)
+{
+ m_handle = handle;
+}
+
+QCollisionQueryResult::QCollisionQueryResult()
+ : d_ptr(new QCollisionQueryResultPrivate(this))
+{
+}
+
+QVector<QNodeId> QCollisionQueryResult::entitiesHit() const
+{
+ Q_D(const QCollisionQueryResult);
+ return d->m_entitiesHit;
+}
+
+QQueryHandle QCollisionQueryResult::handle() const
+{
+ Q_D(const QCollisionQueryResult);
+ return d->m_handle;
+}
+
+} // Qt3D
+
+QT_END_NAMESPACE
diff --git a/src/core/services/qcollisionqueryresult.h b/src/core/services/qcollisionqueryresult.h
new file mode 100644
index 000000000..e74a74411
--- /dev/null
+++ b/src/core/services/qcollisionqueryresult.h
@@ -0,0 +1,71 @@
+/****************************************************************************
+**
+** 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 QT3D_QCOLLISIONQUERYRESULT_H
+#define QT3D_QCOLLISIONQUERYRESULT_H
+
+#include <Qt3DCore/qt3dcore_global.h>
+#include <Qt3DCore/qnodeid.h>
+#include <QVector>
+
+QT_BEGIN_NAMESPACE
+
+namespace Qt3D {
+
+typedef int QQueryHandle;
+
+class QCollisionQueryResultPrivate;
+
+class QT3DCORESHARED_EXPORT QCollisionQueryResult
+{
+public:
+ QCollisionQueryResult();
+
+ QQueryHandle handle() const;
+ QVector<QNodeId> entitiesHit() const;
+
+private:
+ Q_DECLARE_PRIVATE(QCollisionQueryResult)
+ QCollisionQueryResultPrivate *d_ptr;
+ friend class QAbstractCollisionQueryService;
+};
+
+} // Qt3D
+
+QT_END_NAMESPACE
+
+#endif // QT3D_QCOLLISIONQUERYRESULT_H
+
diff --git a/src/core/services/qcollisionqueryresult_p.h b/src/core/services/qcollisionqueryresult_p.h
new file mode 100644
index 000000000..e5997242f
--- /dev/null
+++ b/src/core/services/qcollisionqueryresult_p.h
@@ -0,0 +1,66 @@
+/****************************************************************************
+**
+** 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 QT3D_QCOLLISIONQUERYRESULT_P_H
+#define QT3D_QCOLLISIONQUERYRESULT_P_H
+
+#include <Qt3DCore/qt3dcore_global.h>
+#include <Qt3DCore/qcollisionqueryresult.h>
+
+QT_BEGIN_NAMESPACE
+
+namespace Qt3D {
+
+class QCollisionQueryResultPrivate
+{
+public:
+ QCollisionQueryResultPrivate(QCollisionQueryResult *qq);
+
+ void setHandle(const QQueryHandle &handle);
+ void addEntityHit(const QNodeId &entity);
+
+ Q_DECLARE_PUBLIC(QCollisionQueryResult)
+ QCollisionQueryResult *q_ptr;
+
+ QQueryHandle m_handle;
+ QVector<QNodeId> m_entitiesHit;
+};
+
+} // Qt3D
+
+QT_END_NAMESPACE
+
+#endif // QT3D_QCOLLISIONQUERYRESULT_P_H
diff --git a/src/core/services/qservicelocator.cpp b/src/core/services/qservicelocator.cpp
index 7fc369bd5..74a3a713f 100644
--- a/src/core/services/qservicelocator.cpp
+++ b/src/core/services/qservicelocator.cpp
@@ -51,12 +51,14 @@ namespace Qt3D {
QAbstractServiceProvider::QAbstractServiceProvider(int type, const QString &description)
: d_ptr(new QAbstractServiceProviderPrivate(type, description))
{
+ d_ptr->q_ptr = this;
}
/*! \internal */
QAbstractServiceProvider::QAbstractServiceProvider(QAbstractServiceProviderPrivate &dd)
: d_ptr(&dd)
{
+ d_ptr->q_ptr = this;
}
QAbstractServiceProvider::~QAbstractServiceProvider()
diff --git a/src/core/services/qservicelocator.h b/src/core/services/qservicelocator.h
index a3685325e..144154d97 100644
--- a/src/core/services/qservicelocator.h
+++ b/src/core/services/qservicelocator.h
@@ -78,6 +78,7 @@ public:
enum ServiceType {
SystemInformation,
OpenGLInformation,
+ CollisionService,
FrameAdvanceService,
#if !defined(Q_QDOC)
DefaultServiceCount, // Add additional default services before here
diff --git a/src/core/services/services.pri b/src/core/services/services.pri
index 964e1cbd5..59c2ed140 100644
--- a/src/core/services/services.pri
+++ b/src/core/services/services.pri
@@ -3,6 +3,8 @@ SOURCES += \
$$PWD/qservicelocator.cpp \
$$PWD/qsysteminformationservice.cpp \
$$PWD/qopenglinformationservice.cpp \
+ $$PWD/qabstractcollisionqueryservice.cpp \
+ $$PWD/qcollisionqueryresult.cpp \
$$PWD/qtickclockservice.cpp \
$$PWD/qabstractframeadvanceservice.cpp
@@ -15,6 +17,11 @@ HEADERS += \
$$PWD/qsysteminformationservice_p.h \
$$PWD/qopenglinformationservice_p.h \
$$PWD/qtickclockservice_p.h \
+ $$PWD/qabstractcollisionqueryservice.h \
+ $$PWD/qabstractcollisionqueryservice_p.h \
+ $$PWD/qcollisionqueryresult.h \
+ $$PWD/qcollisionqueryresult_p.h \
+ $$PWD/qtickclockservice.h \
$$PWD/qabstractframeadvanceservice.h \
$$PWD/qabstractframeadvanceservice_p.h