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
qrevolutejoint.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/PxRevoluteJoint.h>
11
13
14/*!
15 \qmltype RevoluteJoint
16 \inqmlmodule QtQuick3D.Physics
17 \since 6.12
18 \brief A revolute joint.
19
20 A revolute joint, commonly referred to as a a hinge keeps the origins and x-axes
21 of the frames together, and allows free rotation around this common axis.
22
23 \sa {DistanceJoint}
24 \sa {FixedJoint}
25 \sa {PrismaticJoint}
26 \sa {SphericalJoint}
27*/
28
29/*!
30 \qmlproperty real RevoluteJoint::angularLimitLower
31 \since 6.12
32 \default 0.0
33
34 The lower angular limit (in radians) of the joint constraint.
35
36 Range: \c{[-2*pi, 2*pi]}
37
38 \sa angularLimitUpper
39*/
40
41/*!
42 \qmlproperty real RevoluteJoint::angularLimitUpper
43 \since 6.12
44 \default 0.0
45
46 The Upper angular limit (in radians) of the joint constraint.
47
48 Range: \c{[-2*pi, 2*pi]}
49
50 \sa angularLimitLower
51*/
52
53/*!
54 \qmlproperty bool RevoluteJoint::enableAngularLimit
55 \since 6.12
56 \default false
57
58 Enable the angular limit constraint for the joint.
59*/
60
61float QRevoluteJoint::angularLimitLower() const
62{
63 return m_angularLimitLower;
64}
65
66void QRevoluteJoint::setAngularLimitLower(float newAngularLimitLower)
67{
68 newAngularLimitLower = qBound(-2.0f * physx::PxPi, newAngularLimitLower, 2.0f * physx::PxPi);
69 if (qFuzzyCompare(m_angularLimitLower, newAngularLimitLower))
70 return;
71 m_angularLimitLower = newAngularLimitLower;
72 m_dirtyProperties = true;
73 emit angularLimitLowerChanged();
74}
75
76float QRevoluteJoint::angularLimitUpper() const
77{
78 return m_angularLimitUpper;
79}
80
81void QRevoluteJoint::setAngularLimitUpper(float newAngularLimitUpper)
82{
83 newAngularLimitUpper = qBound(-2.0f * physx::PxPi, newAngularLimitUpper, 2.0f * physx::PxPi);
84 if (qFuzzyCompare(m_angularLimitUpper, newAngularLimitUpper))
85 return;
86 m_angularLimitUpper = newAngularLimitUpper;
87 m_dirtyProperties = true;
88 emit angularLimitUpperChanged();
89}
90
91bool QRevoluteJoint::enableAngularLimit() const
92{
93 return m_enableAngularLimit;
94}
95
96void QRevoluteJoint::setEnableAngularLimit(bool newEnableAngularLimit)
97{
98 if (m_enableAngularLimit == newEnableAngularLimit)
99 return;
100 m_enableAngularLimit = newEnableAngularLimit;
101 m_dirtyProperties = true;
102 emit enableAngularLimitChanged();
103}
104
105physx::PxJoint *QRevoluteJoint::createPhysxJoint(physx::PxRigidActor *actorA,
106 physx::PxRigidActor *actorB,
107 const physx::PxTransform &trfA,
108 const physx::PxTransform &trfB)
109{
110 return physx::PxRevoluteJointCreate(*StaticPhysXObjects::getReference().physics, actorA, trfA,
111 actorB, trfB);
112}
113
114void QRevoluteJoint::setJointProperties()
115{
116 physx::PxRevoluteJoint *joint = static_cast<physx::PxRevoluteJoint *>(m_joint);
117 const float lower = qMin(m_angularLimitLower, m_angularLimitUpper);
118 const float upper = qMax(m_angularLimitLower, m_angularLimitUpper);
119 joint->setLimit(physx::PxJointAngularLimitPair(lower, upper));
120 joint->setRevoluteJointFlag(physx::PxRevoluteJointFlag::eLIMIT_ENABLED, m_enableAngularLimit);
121}
122
#define QT_BEGIN_NAMESPACE
#define QT_END_NAMESPACE
#define emit