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
qsphereshape.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#include <QtQuick3D/QQuick3DGeometry>
7
8#include <geometry/PxSphereGeometry.h>
9
11
12/*!
13 \qmltype SphereShape
14 \inqmlmodule QtQuick3D.Physics
15 \inherits CollisionShape
16 \since 6.4
17 \brief Defines a spherical collision shape.
18
19 This type defines a spherical shape. The origin is at the center of the sphere.
20 \note When using a scaling transformation with this shape, the x component will be used to scale the diameter of
21 the sphere. The resulting shape will be perfectly round, even if a non-uniform scaling transformation is used.
22*/
23
24/*!
25 \qmlproperty real SphereShape::diameter
26 This property defines the diameter of the sphere
27
28 Default value: \c{100}
29*/
30
31QSphereShape::QSphereShape() = default;
32
33QSphereShape::~QSphereShape()
34{
35 delete m_physXGeometry;
36}
37
38float QSphereShape::diameter() const
39{
40 return m_diameter;
41}
42
43physx::PxGeometry *QSphereShape::getPhysXGeometry()
44{
45 if (!m_physXGeometry || m_scaleDirty) {
46 updatePhysXGeometry();
47 }
48 return m_physXGeometry;
49}
50
51void QSphereShape::setDiameter(float diameter)
52{
53 if (!qIsFinite(diameter) || diameter <= 0.f) {
54 qWarning() << "SphereShape: diameter must be finite and greater than zero, ignoring"
55 << diameter;
56 return;
57 }
58
59 if (qFuzzyCompare(m_diameter, diameter))
60 return;
61
62 m_diameter = diameter;
63 updatePhysXGeometry();
64
65 emit needsRebuild(this);
66 emit diameterChanged(m_diameter);
67}
68
69void QSphereShape::updatePhysXGeometry()
70{
71 delete m_physXGeometry;
72 m_physXGeometry = nullptr;
73 m_scaleDirty = false;
74
75 const float radius = m_diameter * 0.5f * sceneScale().x();
76 if (!qIsFinite(radius) || radius <= 0.f) {
77 qWarning() << "SphereShape: scaled radius must be finite and greater than zero, "
78 "ignoring.";
79 return;
80 }
81 m_physXGeometry = new physx::PxSphereGeometry(radius);
82}
83
84QT_END_NAMESPACE
Combined button and popup list for selecting options.