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

source code of qtquick3dphysics/src/quick3dphysics/qboxshape.cpp