diff options
author | Sean Harmer <sean.harmer@kdab.com> | 2015-08-09 00:17:02 +0100 |
---|---|---|
committer | Sean Harmer <sean.harmer@kdab.com> | 2015-08-10 01:24:12 +0000 |
commit | e98640c14d7b5ed800c7c16afc062a71a33fe813 (patch) | |
tree | f6ae808e97537733a258a874a3688ccc4146c221 | |
parent | 0c6e8e1dbf40c27ef85ed421a90807370781c7ed (diff) |
Add QCapsuleCollider C++ and QML types
Change-Id: Ifc9110db4b235a53b2744c8f426ac693af5a2883
Reviewed-by: Paul Lemire <paul.lemire@kdab.com>
-rw-r--r-- | src/collision/collision.pri | 7 | ||||
-rw-r--r-- | src/collision/qcapsulecollider.cpp | 158 | ||||
-rw-r--r-- | src/collision/qcapsulecollider.h | 98 | ||||
-rw-r--r-- | src/collision/qcapsulecollider_p.h | 66 | ||||
-rw-r--r-- | src/quick3d/imports/collision/qt3dquick3dcollisionplugin.cpp | 2 |
5 files changed, 329 insertions, 2 deletions
diff --git a/src/collision/collision.pri b/src/collision/collision.pri index aa783a971..4d5f8a35e 100644 --- a/src/collision/collision.pri +++ b/src/collision/collision.pri @@ -7,9 +7,12 @@ HEADERS += \ $$PWD/qspherecollider.h \ $$PWD/qspherecollider_p.h \ $$PWD/qboxcollider.h \ - $$PWD/qboxcollider_p.h + $$PWD/qboxcollider_p.h \ + $$PWD/qcapsulecollider.h \ + $$PWD/qcapsulecollider_p.h SOURCES += \ $$PWD/qcollisionaspect.cpp \ $$PWD/qspherecollider.cpp \ - $$PWD/qboxcollider.cpp + $$PWD/qboxcollider.cpp \ + $$PWD/qcapsulecollider.cpp diff --git a/src/collision/qcapsulecollider.cpp b/src/collision/qcapsulecollider.cpp new file mode 100644 index 000000000..411c2c863 --- /dev/null +++ b/src/collision/qcapsulecollider.cpp @@ -0,0 +1,158 @@ +/**************************************************************************** +** +** 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 "qcapsulecollider.h" +#include "qcapsulecollider_p.h" + +QT_BEGIN_NAMESPACE + +namespace Qt3D { + +/*! + \class Qt3D::QCapsuleColliderPrivate + \internal +*/ +QCapsuleColliderPrivate::QCapsuleColliderPrivate() + : QComponentPrivate() + , m_center() + , m_radius(1.0f) + , m_length(1.0f) + , m_axisDirection(QCapsuleCollider::YAxis) +{ +} + +/*! + \class Qt3D::QCapsuleCollider + \inmodule Qt3DCollision + \since 5.5 + \brief Represents a capsule used for collision detection +*/ + +/*! + \qmltype CapsuleCollider + \inqmlmodule Qt3D.Collision + \instantiates Qt3D::QCapsuleCollider + \inherits Component3D + \since 5.5 +*/ + +/*! + Constructs a new QCapsuleCollider instance with parent \a parent. + */ +QCapsuleCollider::QCapsuleCollider(QNode *parent) + : QComponent(*new QCapsuleColliderPrivate, parent) +{ +} + +/*! \internal */ +QCapsuleCollider::QCapsuleCollider(QCapsuleColliderPrivate &dd, QNode *parent) + : QComponent(dd, parent) +{ +} + +QCapsuleCollider::~QCapsuleCollider() +{ + QNode::cleanup(); +} + +QVector3D QCapsuleCollider::center() const +{ + Q_D(const QCapsuleCollider); + return d->m_center; +} + +float QCapsuleCollider::radius() const +{ + Q_D(const QCapsuleCollider); + return d->m_radius; +} + +float QCapsuleCollider::length() const +{ + Q_D(const QCapsuleCollider); + return d->m_length; +} + +QCapsuleCollider::Direction QCapsuleCollider::axisDirection() const +{ + Q_D(const QCapsuleCollider); + return d->m_axisDirection; +} + +void QCapsuleCollider::setCenter(const QVector3D ¢er) +{ + Q_D(QCapsuleCollider); + if (d->m_center == center) + return; + + d->m_center = center; + emit centerChanged(center); +} + +void QCapsuleCollider::setRadius(float radius) +{ + Q_D(QCapsuleCollider); + if (d->m_radius == radius) + return; + + d->m_radius = radius; + emit radiusChanged(radius); +} + +void QCapsuleCollider::setLength(float length) +{ + Q_D(QCapsuleCollider); + if (d->m_length == length) + return; + + d->m_length = length; + emit lengthChanged(length); +} + +void QCapsuleCollider::setAxisDirection(Qt3D::QCapsuleCollider::Direction axisDirection) +{ + Q_D(QCapsuleCollider); + if (d->m_axisDirection == axisDirection) + return; + + d->m_axisDirection = axisDirection; + emit axisDirectionChanged(axisDirection); +} + +QT_END_NAMESPACE + +} // namespace Qt3D + diff --git a/src/collision/qcapsulecollider.h b/src/collision/qcapsulecollider.h new file mode 100644 index 000000000..6c61f182a --- /dev/null +++ b/src/collision/qcapsulecollider.h @@ -0,0 +1,98 @@ +/**************************************************************************** +** +** 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_QCAPSULECOLLIDER_H +#define QT3D_QCAPSULECOLLIDER_H + +#include <QComponent> +#include <Qt3DCollision/qt3dcollision_global.h> +#include <QtGui/qvector3d.h> + +QT_BEGIN_NAMESPACE + +namespace Qt3D { + +class QCapsuleColliderPrivate; + +class QT3DCOLLISIONSHARED_EXPORT QCapsuleCollider : public QComponent +{ + Q_OBJECT + Q_PROPERTY(QVector3D center READ center WRITE setCenter NOTIFY centerChanged) + Q_PROPERTY(float radius READ radius WRITE setRadius NOTIFY radiusChanged) + Q_PROPERTY(float length READ length WRITE setLength NOTIFY lengthChanged) + Q_PROPERTY(Direction axisDirection READ axisDirection WRITE setAxisDirection NOTIFY axisDirectionChanged) + +public: + explicit QCapsuleCollider(QNode *parent = 0); + ~QCapsuleCollider(); + + enum Direction { + XAxis, + YAxis, + ZAxis + }; + Q_ENUM(Direction) + + QVector3D center() const; + float radius() const; + float length() const; + Direction axisDirection() const; + +public Q_SLOTS: + void setCenter(const QVector3D ¢er); + void setRadius(float radius); + void setLength(float length); + void setAxisDirection(Qt3D::QCapsuleCollider::Direction axisDirection); + +Q_SIGNALS: + void centerChanged(QVector3D center); + void radiusChanged(float radius); + void lengthChanged(float length); + void axisDirectionChanged(Qt3D::QCapsuleCollider::Direction axisDirection); + +protected: + QCapsuleCollider(QCapsuleColliderPrivate &dd, QNode *parent = 0); + +private: + Q_DECLARE_PRIVATE(QCapsuleCollider) + QT3D_CLONEABLE(QCapsuleCollider) +}; + +} // namespace Qt3D + +QT_END_NAMESPACE + +#endif // QT3D_QCAPSULECOLLIDER_H diff --git a/src/collision/qcapsulecollider_p.h b/src/collision/qcapsulecollider_p.h new file mode 100644 index 000000000..d2b29d035 --- /dev/null +++ b/src/collision/qcapsulecollider_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_QCAPSULECOLLIDER_P_H +#define QT3D_QCAPSULECOLLIDER_P_H + +#include <Qt3DCore/private/qcomponent_p.h> +#include <QtGui/QVector3D> + +QT_BEGIN_NAMESPACE + +namespace Qt3D { + +class QCapsuleCollider; + +class QCapsuleColliderPrivate : public QComponentPrivate +{ + QCapsuleColliderPrivate(); + + Q_DECLARE_PUBLIC(QCapsuleCollider) + + QVector3D m_center; + float m_radius; + float m_length; + QCapsuleCollider::Direction m_axisDirection; +}; + +} // namespace Qt3D + +QT_END_NAMESPACE + +#endif // QT3D_QCAPSULECOLLIDER_P_H + diff --git a/src/quick3d/imports/collision/qt3dquick3dcollisionplugin.cpp b/src/quick3d/imports/collision/qt3dquick3dcollisionplugin.cpp index cc4d2ebd2..931a3db3e 100644 --- a/src/quick3d/imports/collision/qt3dquick3dcollisionplugin.cpp +++ b/src/quick3d/imports/collision/qt3dquick3dcollisionplugin.cpp @@ -36,6 +36,7 @@ #include <QtQml> #include <Qt3DCollision/qboxcollider.h> +#include <Qt3DCollision/qcapsulecollider.h> #include <Qt3DCollision/qspherecollider.h> #include "qt3dquick3dcollisionplugin.h" @@ -44,6 +45,7 @@ QT_BEGIN_NAMESPACE void Qt3DQuick3DCollisionPlugin::registerTypes(const char *uri) { qmlRegisterType<Qt3D::QBoxCollider>(uri, 2, 0, "BoxCollider"); + qmlRegisterType<Qt3D::QCapsuleCollider>(uri, 2, 0, "CapsuleCollider"); qmlRegisterType<Qt3D::QSphereCollider>(uri, 2, 0, "SphereCollider"); } |