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
qsphericaljoint.cpp
Go to the documentation of this file.
1// Copyright (C) 2026 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3
5
6#include "physxnode/qphysxactorbody_p.h"
9
10#include <extensions/PxSphericalJoint.h>
11
13
14/*!
15 \qmltype SphericalJoint
16 \inqmlmodule QtQuick3D.Physics
17 \since 6.12
18 \brief A spherical joint.
19
20 A spherical joint, also known as a ball-and-socket joint, keeps the origins
21 together, but allows the orientations to vary freely.
22
23 \sa {DistanceJoint}
24 \sa {FixedJoint}
25 \sa {PrismaticJoint}
26 \sa {RevoluteJoint}
27*/
28
29/*!
30 \qmlproperty real SphericalJoint::coneLimitY
31 \since 6.12
32 \default 0.0
33
34 The y limit (in radians) of the joint's cone constraint.
35
36 Range: \c{(0, pi)}
37
38 \sa coneLimitZ
39*/
40
41/*!
42 \qmlproperty real SphericalJoint::coneLimitZ
43 \since 6.12
44 \default 0.0
45
46 The z limit (in radians) of the joint's cone constraint.
47
48 Range: \c{(0, pi)}
49
50 \sa coneLimitY
51*/
52
53/*!
54 \qmlproperty bool SphericalJoint::enableConeLimit
55 \since 6.12
56 \default false
57
58 Enable the cone limit constraint for the joint.
59*/
60
61float QSphericalJoint::coneLimitY() const
62{
63 return m_coneLimitY;
64}
65
66void QSphericalJoint::setConeLimitY(float newConeLimitY)
67{
68 // PxJointLimitCone::isValid() requires yAngle strictly within (0, PxPi),
69 // so the margin keeps the clamped value off both boundaries.
70 newConeLimitY = qBound(1e-4f, newConeLimitY, physx::PxPi - 1e-4f);
71 if (qFuzzyCompare(m_coneLimitY, newConeLimitY))
72 return;
73 m_coneLimitY = newConeLimitY;
74 m_dirtyProperties = true;
75 emit coneLimitYChanged();
76}
77
78float QSphericalJoint::coneLimitZ() const
79{
80 return m_coneLimitZ;
81}
82
83void QSphericalJoint::setConeLimitZ(float newConeLimitZ)
84{
85 // PxJointLimitCone::isValid() requires zAngle strictly within (0, PxPi),
86 // so the margin keeps the clamped value off both boundaries.
87 newConeLimitZ = qBound(1e-4f, newConeLimitZ, physx::PxPi - 1e-4f);
88 if (qFuzzyCompare(m_coneLimitZ, newConeLimitZ))
89 return;
90 m_coneLimitZ = newConeLimitZ;
91 m_dirtyProperties = true;
92 emit coneLimitZChanged();
93}
94
95bool QSphericalJoint::enableConeLimit() const
96{
97 return m_enableConeLimit;
98}
99
100void QSphericalJoint::setEnableConeLimit(bool newEnableConeLimit)
101{
102 if (m_enableConeLimit == newEnableConeLimit)
103 return;
104 m_enableConeLimit = newEnableConeLimit;
105 m_dirtyProperties = true;
106 emit enableConeLimitChanged();
107}
108
109physx::PxJoint *QSphericalJoint::createPhysxJoint(physx::PxRigidActor *actorA,
110 physx::PxRigidActor *actorB,
111 const physx::PxTransform &trfA,
112 const physx::PxTransform &trfB)
113{
114 return physx::PxSphericalJointCreate(*StaticPhysXObjects::getReference().physics, actorA, trfA,
115 actorB, trfB);
116}
117
118void QSphericalJoint::setJointProperties()
119{
120 physx::PxSphericalJoint *joint = static_cast<physx::PxSphericalJoint *>(m_joint);
121 joint->setLimitCone(physx::PxJointLimitCone(m_coneLimitY, m_coneLimitZ));
122 joint->setSphericalJointFlag(physx::PxSphericalJointFlag::eLIMIT_ENABLED, m_enableConeLimit);
123}
124
#define QT_BEGIN_NAMESPACE
#define QT_END_NAMESPACE
#define emit