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