| 1 | /**************************************************************************** |
| 2 | ** |
| 3 | ** Copyright (C) 2018 Klaralvdalens Datakonsult AB (KDAB). |
| 4 | ** Contact: https://www.qt.io/licensing/ |
| 5 | ** |
| 6 | ** This file is part of the Qt3D module of the Qt Toolkit. |
| 7 | ** |
| 8 | ** $QT_BEGIN_LICENSE:LGPL$ |
| 9 | ** Commercial License Usage |
| 10 | ** Licensees holding valid commercial Qt licenses may use this file in |
| 11 | ** accordance with the commercial license agreement provided with the |
| 12 | ** Software or, alternatively, in accordance with the terms contained in |
| 13 | ** a written agreement between you and The Qt Company. For licensing terms |
| 14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
| 15 | ** information use the contact form at https://www.qt.io/contact-us. |
| 16 | ** |
| 17 | ** GNU Lesser General Public License Usage |
| 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser |
| 19 | ** General Public License version 3 as published by the Free Software |
| 20 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the |
| 21 | ** packaging of this file. Please review the following information to |
| 22 | ** ensure the GNU Lesser General Public License version 3 requirements |
| 23 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. |
| 24 | ** |
| 25 | ** GNU General Public License Usage |
| 26 | ** Alternatively, this file may be used under the terms of the GNU |
| 27 | ** General Public License version 2.0 or (at your option) the GNU General |
| 28 | ** Public license version 3 or any later version approved by the KDE Free |
| 29 | ** Qt Foundation. The licenses are as published by the Free Software |
| 30 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 |
| 31 | ** included in the packaging of this file. Please review the following |
| 32 | ** information to ensure the GNU General Public License requirements will |
| 33 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and |
| 34 | ** https://www.gnu.org/licenses/gpl-3.0.html. |
| 35 | ** |
| 36 | ** $QT_END_LICENSE$ |
| 37 | ** |
| 38 | ****************************************************************************/ |
| 39 | |
| 40 | #include "qscreenraycaster.h" |
| 41 | #include "qabstractraycaster_p.h" |
| 42 | #include <Qt3DCore/qentity.h> |
| 43 | #include <Qt3DCore/private/qcomponent_p.h> |
| 44 | #include <Qt3DCore/private/qscene_p.h> |
| 45 | |
| 46 | QT_BEGIN_NAMESPACE |
| 47 | |
| 48 | namespace Qt3DRender { |
| 49 | |
| 50 | /*! |
| 51 | \class Qt3DRender::QScreenRayCaster |
| 52 | \brief Performe ray casting test based on screen coordinates. |
| 53 | \inmodule Qt3DRender |
| 54 | \since 5.11 |
| 55 | \inherits QAbstractRayCaster |
| 56 | |
| 57 | QScreenRayCaster can be used to perform ray casting tests by specifying coordinates in |
| 58 | screen space, which will be used to construct an actual 3D ray between the near and |
| 59 | far planes. |
| 60 | |
| 61 | \sa QRayCaster, QNoPicking |
| 62 | */ |
| 63 | /*! |
| 64 | \qmltype ScreenRayCaster |
| 65 | \brief Performe ray casting test based on screen coordinates. |
| 66 | \inqmlmodule Qt3D.Render |
| 67 | \since 5.11 |
| 68 | \instantiates Qt3DRender::QScreenRayCaster |
| 69 | |
| 70 | ScreenRayCaster can be used to perform ray casting tests by specifying coordinates in |
| 71 | screen space, which will be used to construct an actual 3D ray between the near and |
| 72 | far planes. |
| 73 | |
| 74 | \sa RayCaster, NoPicking |
| 75 | */ |
| 76 | |
| 77 | /*! |
| 78 | \property Qt3DRender::QScreenRayCaster::position |
| 79 | |
| 80 | Holds the screen space position used to compute the actual 3D ray for intersection tests. |
| 81 | |
| 82 | Note: the coordinates will be used for every available render surface as long as they are |
| 83 | in the valid range. |
| 84 | */ |
| 85 | /*! |
| 86 | \qmlproperty point Qt3D.Render::ScreenRayCaster::position |
| 87 | |
| 88 | Holds the length of the 3D ray. |
| 89 | |
| 90 | \note The coordinates will be used for every available render surface as long as they are |
| 91 | in the valid range. |
| 92 | */ |
| 93 | QScreenRayCaster::QScreenRayCaster(Qt3DCore::QNode *parent) |
| 94 | : QAbstractRayCaster(parent) |
| 95 | { |
| 96 | QAbstractRayCasterPrivate::get(obj: this)->m_rayCasterType = QAbstractRayCasterPrivate::ScreenScapeRayCaster; |
| 97 | } |
| 98 | |
| 99 | /*! \internal */ |
| 100 | QScreenRayCaster::QScreenRayCaster(QAbstractRayCasterPrivate &dd, Qt3DCore::QNode *parent) |
| 101 | : QAbstractRayCaster(dd, parent) |
| 102 | { |
| 103 | QAbstractRayCasterPrivate::get(obj: this)->m_rayCasterType = QAbstractRayCasterPrivate::ScreenScapeRayCaster; |
| 104 | } |
| 105 | |
| 106 | /*! \internal */ |
| 107 | QScreenRayCaster::~QScreenRayCaster() |
| 108 | { |
| 109 | } |
| 110 | |
| 111 | QPoint QScreenRayCaster::position() const |
| 112 | { |
| 113 | auto d = QAbstractRayCasterPrivate::get(obj: this); |
| 114 | return d->m_position; |
| 115 | } |
| 116 | |
| 117 | void QScreenRayCaster::setPosition(const QPoint &position) |
| 118 | { |
| 119 | auto d = QAbstractRayCasterPrivate::get(obj: this); |
| 120 | if (d->m_position != position) { |
| 121 | d->m_position = position; |
| 122 | emit positionChanged(position: d->m_position); |
| 123 | } |
| 124 | } |
| 125 | |
| 126 | /*! |
| 127 | Convenience method to enable the component and trigger tests using the current coordinate value. |
| 128 | */ |
| 129 | void QScreenRayCaster::trigger() |
| 130 | { |
| 131 | setEnabled(true); |
| 132 | } |
| 133 | |
| 134 | /*! |
| 135 | Convenience method to set the coordinate value \a position and enable the component to trigger tests. |
| 136 | */ |
| 137 | void QScreenRayCaster::trigger(const QPoint &position) |
| 138 | { |
| 139 | setPosition(position); |
| 140 | setEnabled(true); |
| 141 | } |
| 142 | |
| 143 | } // Qt3DRender |
| 144 | |
| 145 | QT_END_NAMESPACE |
| 146 | |