Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
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
#
include
"qphysicsutils_p.h"
7
8
#
include
<
QtQuick3D
/
QQuick3DGeometry
>
9
#
include
<
extensions
/
PxExtensionsAPI
.
h
>
10
11
QT_BEGIN_NAMESPACE
12
13
/*!
14
\qmltype BoxShape
15
\inherits CollisionShape
16
\inqmlmodule QtQuick3D.Physics
17
\since 6.4
18
\brief Defines a box collision shape.
19
20
This type defines a box collision shape. The origin is at the center of the box.
21
22
\note A non-uniform scaling transformation will scale the x, y and z directions individually.
23
However, combining non-uniform scale and rotation may lead to shearing, which will not be applied
24
to the BoxShape: it will always be a rectilinear box.
25
26
\sa {Qt Quick 3D Physics Shapes, Bodies and Joints}
27
*/
28
29
/*!
30
\qmlproperty vector3d BoxShape::extents
31
This property defines the extents of the box in the x, y and z directions.
32
33
Default value: \c{(100, 100, 100)}
34
*/
35
36
QBoxShape::QBoxShape() =
default
;
37
QBoxShape::~QBoxShape()
38
{
39
delete
m_physXGeometry;
40
}
41
42
QVector3D QBoxShape::extents()
const
43
{
44
return
m_extents;
45
}
46
47
physx::PxGeometry *QBoxShape::getPhysXGeometry()
48
{
49
if
(!m_physXGeometry || m_scaleDirty) {
50
updatePhysXGeometry();
51
}
52
return
m_physXGeometry;
53
}
54
55
void
QBoxShape::setExtents(QVector3D extents)
56
{
57
if
(!QPhysicsUtils::isFinite(extents) || extents.x() <= 0.f || extents.y() <= 0.f
58
|| extents.z() <= 0.f) {
59
qWarning() <<
"BoxShape: extents must be finite and greater than zero in every "
60
"component, ignoring"
61
<< extents;
62
return
;
63
}
64
65
if
(m_extents == extents)
66
return
;
67
68
m_extents = extents;
69
updatePhysXGeometry();
70
71
emit needsRebuild(
this
);
72
emit extentsChanged(m_extents);
73
}
74
75
void
QBoxShape::updatePhysXGeometry()
76
{
77
delete
m_physXGeometry;
78
m_physXGeometry =
nullptr
;
79
m_scaleDirty =
false
;
80
81
const
QVector3D half = m_extents * sceneScale() * 0.5f;
82
if
(!QPhysicsUtils::isFinite(half) || half.x() <= 0.f || half.y() <= 0.f || half.z() <= 0.f) {
83
qWarning() <<
"BoxShape: extents"
<< m_extents <<
"scaled by"
<< sceneScale()
84
<<
"must be finite and greater than zero in every component, ignoring."
;
85
return
;
86
}
87
m_physXGeometry =
new
physx::PxBoxGeometry(half.x(), half.y(), half.z());
88
}
89
90
QT_END_NAMESPACE
qtquick3dphysics
src
quick3dphysics
qboxshape.cpp
Generated on
for Qt by
1.18.0