Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qboxshape.cpp
Go to the documentation of this file.
1// Copyright (C) 2021 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3// Qt-Security score:significant reason:default
4
5#include "qboxshape_p.h"
6
7#include <QtQuick3D/QQuick3DGeometry>
8#include <extensions/PxExtensionsAPI.h>
9
11
12/*!
13 \qmltype BoxShape
14 \inherits CollisionShape
15 \inqmlmodule QtQuick3D.Physics
16 \since 6.4
17 \brief Defines a box collision shape.
18
19 This type defines a box collision shape. The origin is at the center of the box.
20
21 \note A non-uniform scaling transformation will scale the x, y and z directions individually.
22 However, combining non-uniform scale and rotation may lead to shearing, which will not be applied
23 to the BoxShape: it will always be a rectilinear box.
24
25 \sa {Qt Quick 3D Physics Shapes and Bodies}{Shapes and Bodies overview documentation}
26*/
27
28/*!
29 \qmlproperty vector3d BoxShape::extents
30 This property defines the extents of the box in the x, y and z directions.
31
32 Default value: \c{(100, 100, 100)}
33*/
34
35QBoxShape::QBoxShape() = default;
36QBoxShape::~QBoxShape()
37{
38 delete m_physXGeometry;
39}
40
41QVector3D QBoxShape::extents() const
42{
43 return m_extents;
44}
45
46physx::PxGeometry *QBoxShape::getPhysXGeometry()
47{
48 if (!m_physXGeometry || m_scaleDirty) {
49 updatePhysXGeometry();
50 }
51 return m_physXGeometry;
52}
53
54void QBoxShape::setExtents(QVector3D extents)
55{
56 if (m_extents == extents)
57 return;
58
59 m_extents = extents;
60 updatePhysXGeometry();
61
62 emit needsRebuild(this);
63 emit extentsChanged(m_extents);
64}
65
66void QBoxShape::updatePhysXGeometry()
67{
68 delete m_physXGeometry;
69 const QVector3D half = m_extents * sceneScale() * 0.5f;
70 m_physXGeometry = new physx::PxBoxGeometry(half.x(), half.y(), half.z());
71 m_scaleDirty = false;
72}
73
74QT_END_NAMESPACE
Combined button and popup list for selecting options.