1 | // Copyright (C) 2021 The Qt Company Ltd. |
---|---|
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only |
3 | |
4 | #include "qsphereshape_p.h" |
5 | #include <QtQuick3D/QQuick3DGeometry> |
6 | |
7 | #include <geometry/PxSphereGeometry.h> |
8 | |
9 | QT_BEGIN_NAMESPACE |
10 | |
11 | /*! |
12 | \qmltype SphereShape |
13 | \inqmlmodule QtQuick3D.Physics |
14 | \inherits CollisionShape |
15 | \since 6.4 |
16 | \brief Defines a spherical collision shape. |
17 | |
18 | This type defines a spherical shape. The origin is at the center of the sphere. |
19 | \note When using a scaling transformation with this shape, the x component will be used to scale the diameter of |
20 | the sphere. The resulting shape will be perfectly round, even if a non-uniform scaling transformation is used. |
21 | */ |
22 | |
23 | /*! |
24 | \qmlproperty float SphereShape::diameter |
25 | This property defines the diameter of the sphere |
26 | |
27 | Default value: \c{100} |
28 | */ |
29 | |
30 | QSphereShape::QSphereShape() = default; |
31 | |
32 | QSphereShape::~QSphereShape() |
33 | { |
34 | delete m_physXGeometry; |
35 | } |
36 | |
37 | float QSphereShape::diameter() const |
38 | { |
39 | return m_diameter; |
40 | } |
41 | |
42 | physx::PxGeometry *QSphereShape::getPhysXGeometry() |
43 | { |
44 | if (!m_physXGeometry || m_scaleDirty) { |
45 | updatePhysXGeometry(); |
46 | } |
47 | return m_physXGeometry; |
48 | } |
49 | |
50 | void QSphereShape::setDiameter(float diameter) |
51 | { |
52 | if (qFuzzyCompare(p1: m_diameter, p2: diameter)) |
53 | return; |
54 | |
55 | m_diameter = diameter; |
56 | updatePhysXGeometry(); |
57 | |
58 | emit needsRebuild(this); |
59 | emit diameterChanged(diameter: m_diameter); |
60 | } |
61 | |
62 | void QSphereShape::updatePhysXGeometry() |
63 | { |
64 | delete m_physXGeometry; |
65 | auto s = sceneScale(); |
66 | m_physXGeometry = new physx::PxSphereGeometry(m_diameter * 0.5f * s.x()); |
67 | m_scaleDirty = false; |
68 | } |
69 | |
70 | QT_END_NAMESPACE |
71 |