| 1 | // Copyright (C) 2018 Klaralvdalens Datakonsult AB (KDAB). |
|---|---|
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
| 3 | |
| 4 | #include "qscreenraycaster.h" |
| 5 | #include "qabstractraycaster_p.h" |
| 6 | #include <Qt3DCore/qentity.h> |
| 7 | #include <Qt3DCore/private/qcomponent_p.h> |
| 8 | #include <Qt3DCore/private/qscene_p.h> |
| 9 | |
| 10 | QT_BEGIN_NAMESPACE |
| 11 | |
| 12 | namespace Qt3DRender { |
| 13 | |
| 14 | /*! |
| 15 | \class Qt3DRender::QScreenRayCaster |
| 16 | \brief Performe ray casting test based on screen coordinates. |
| 17 | \inmodule Qt3DRender |
| 18 | \since 5.11 |
| 19 | \inherits QAbstractRayCaster |
| 20 | |
| 21 | QScreenRayCaster can be used to perform ray casting tests by specifying coordinates in |
| 22 | screen space, which will be used to construct an actual 3D ray between the near and |
| 23 | far planes. |
| 24 | |
| 25 | \sa QRayCaster, QNoPicking |
| 26 | */ |
| 27 | /*! |
| 28 | \qmltype ScreenRayCaster |
| 29 | \brief Performe ray casting test based on screen coordinates. |
| 30 | \inqmlmodule Qt3D.Render |
| 31 | \since 5.11 |
| 32 | \nativetype Qt3DRender::QScreenRayCaster |
| 33 | |
| 34 | ScreenRayCaster can be used to perform ray casting tests by specifying coordinates in |
| 35 | screen space, which will be used to construct an actual 3D ray between the near and |
| 36 | far planes. |
| 37 | |
| 38 | \sa RayCaster, NoPicking |
| 39 | */ |
| 40 | |
| 41 | /*! |
| 42 | \property Qt3DRender::QScreenRayCaster::position |
| 43 | |
| 44 | Holds the screen space position used to compute the actual 3D ray for intersection tests. |
| 45 | |
| 46 | Note: the coordinates will be used for every available render surface as long as they are |
| 47 | in the valid range. |
| 48 | */ |
| 49 | /*! |
| 50 | \qmlproperty point Qt3D.Render::ScreenRayCaster::position |
| 51 | |
| 52 | Holds the length of the 3D ray. |
| 53 | |
| 54 | \note The coordinates will be used for every available render surface as long as they are |
| 55 | in the valid range. |
| 56 | */ |
| 57 | QScreenRayCaster::QScreenRayCaster(Qt3DCore::QNode *parent) |
| 58 | : QAbstractRayCaster(parent) |
| 59 | { |
| 60 | QAbstractRayCasterPrivate::get(obj: this)->m_rayCasterType = QAbstractRayCasterPrivate::ScreenScapeRayCaster; |
| 61 | } |
| 62 | |
| 63 | /*! \internal */ |
| 64 | QScreenRayCaster::QScreenRayCaster(QAbstractRayCasterPrivate &dd, Qt3DCore::QNode *parent) |
| 65 | : QAbstractRayCaster(dd, parent) |
| 66 | { |
| 67 | QAbstractRayCasterPrivate::get(obj: this)->m_rayCasterType = QAbstractRayCasterPrivate::ScreenScapeRayCaster; |
| 68 | } |
| 69 | |
| 70 | /*! \internal */ |
| 71 | QScreenRayCaster::~QScreenRayCaster() |
| 72 | { |
| 73 | } |
| 74 | |
| 75 | QPoint QScreenRayCaster::position() const |
| 76 | { |
| 77 | auto d = QAbstractRayCasterPrivate::get(obj: this); |
| 78 | return d->m_position; |
| 79 | } |
| 80 | |
| 81 | void QScreenRayCaster::setPosition(const QPoint &position) |
| 82 | { |
| 83 | auto d = QAbstractRayCasterPrivate::get(obj: this); |
| 84 | if (d->m_position != position) { |
| 85 | d->m_position = position; |
| 86 | emit positionChanged(position: d->m_position); |
| 87 | } |
| 88 | } |
| 89 | |
| 90 | /*! |
| 91 | Convenience method to enable the component and trigger tests using the current coordinate value. |
| 92 | */ |
| 93 | void QScreenRayCaster::trigger() |
| 94 | { |
| 95 | setEnabled(true); |
| 96 | } |
| 97 | |
| 98 | /*! |
| 99 | Convenience method to set the coordinate value \a position and enable the component to trigger tests. |
| 100 | */ |
| 101 | void QScreenRayCaster::trigger(const QPoint &position) |
| 102 | { |
| 103 | setPosition(position); |
| 104 | setEnabled(true); |
| 105 | } |
| 106 | |
| 107 | QAbstractRayCaster::Hits QScreenRayCaster::pick(const QPoint &position) |
| 108 | { |
| 109 | setPosition(position); |
| 110 | |
| 111 | auto d = QAbstractRayCasterPrivate::get(obj: this); |
| 112 | return d->pick(); |
| 113 | } |
| 114 | |
| 115 | } // Qt3DRender |
| 116 | |
| 117 | QT_END_NAMESPACE |
| 118 | |
| 119 | #include "moc_qscreenraycaster.cpp" |
| 120 |
