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
32QBoxShape::QBoxShape() = default;
33QBoxShape::~QBoxShape()
34{
35 delete m_physXGeometry;
36}
37
38QVector3D QBoxShape::extents() const
39{
40 return m_extents;
41}
42
43physx::PxGeometry *QBoxShape::getPhysXGeometry()
44{
45 if (!m_physXGeometry || m_scaleDirty) {
46 updatePhysXGeometry();
47 }
48 return m_physXGeometry;
49}
50
51void QBoxShape::setExtents(QVector3D extents)
52{
53 if (m_extents == extents)
54 return;
55
56 m_extents = extents;
57 updatePhysXGeometry();
58
59 emit needsRebuild(this);
60 emit extentsChanged(extents: m_extents);
61}
62
63void QBoxShape::updatePhysXGeometry()
64{
65 delete m_physXGeometry;
66 const QVector3D half = m_extents * sceneScale() * 0.5f;
67 m_physXGeometry = new physx::PxBoxGeometry(half.x(), half.y(), half.z());
68 m_scaleDirty = false;
69}
70
71QT_END_NAMESPACE
72

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