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
qcapsuleshape.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
6
7#include <QtQuick3D/QQuick3DGeometry>
8#include <geometry/PxCapsuleGeometry.h>
9
11
12/*!
13 \qmltype CapsuleShape
14 \inherits CollisionShape
15 \inqmlmodule QtQuick3D.Physics
16 \since 6.4
17 \brief Defines a pill-like shape.
18
19 This type defines a capsule shape. This is a cylinder with a hemisphere at each end.
20 The origin is at the center of the capsule. The capsule is specified by \l diameter, which
21 determines the diameter of the cylinder and the hemispheres; and \l height, which
22 determines the height of the cylinder.
23
24 \note When using scaling transformations with this shape, the x component will be used to scale the height and
25 the y component will be used to scale the diameter. The cylinder will always be perfectly circular even if the
26 scaling transformation is non-uniform.
27
28 \sa {Qt Quick 3D Physics Shapes and Bodies}{Shapes and Bodies overview documentation}
29*/
30
31/*!
32 \qmlproperty real CapsuleShape::diameter
33 This property defines the diameter of the capsule
34
35 Default value: \c{100}
36*/
37
38/*!
39 \qmlproperty real CapsuleShape::height
40 This property defines the height of the capsule
41
42 Default value: \c{100}
43*/
44
45QCapsuleShape::QCapsuleShape() = default;
46
47QCapsuleShape::~QCapsuleShape()
48{
49 delete m_physXGeometry;
50}
51
52physx::PxGeometry *QCapsuleShape::getPhysXGeometry()
53{
54 if (!m_physXGeometry || m_scaleDirty) {
55 updatePhysXGeometry();
56 }
57
58 return m_physXGeometry;
59}
60
61float QCapsuleShape::diameter() const
62{
63 return m_diameter;
64}
65
66void QCapsuleShape::setDiameter(float newDiameter)
67{
68 if (qFuzzyCompare(m_diameter, newDiameter))
69 return;
70 m_diameter = newDiameter;
71 updatePhysXGeometry();
72
73 emit needsRebuild(this);
74 emit diameterChanged();
75}
76
77float QCapsuleShape::height() const
78{
79 return m_height;
80}
81
82void QCapsuleShape::setHeight(float newHeight)
83{
84 if (qFuzzyCompare(m_height, newHeight))
85 return;
86 m_height = newHeight;
87 updatePhysXGeometry();
88
89 emit needsRebuild(this);
90 emit heightChanged();
91}
92
93void QCapsuleShape::updatePhysXGeometry()
94{
95 delete m_physXGeometry;
96 QVector3D s = sceneScale();
97 qreal rs = s.y();
98 qreal hs = s.x();
99 m_physXGeometry = new physx::PxCapsuleGeometry(rs * m_diameter * 0.5f, hs * m_height * 0.5f);
100 m_scaleDirty = false;
101}
102
103QT_END_NAMESPACE
Combined button and popup list for selecting options.