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 (qFuzzyCompare(m_diameter, diameter))
54 return;
55
56 m_diameter = diameter;
57 updatePhysXGeometry();
58
59 emit needsRebuild(this);
60 emit diameterChanged(m_diameter);
61}
62
63void QSphereShape::updatePhysXGeometry()
64{
65 delete m_physXGeometry;
66 auto s = sceneScale();
67 m_physXGeometry = new physx::PxSphereGeometry(m_diameter * 0.5f * s.x());
68 m_scaleDirty = false;
69}
70
71QT_END_NAMESPACE
Combined button and popup list for selecting options.