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
qprismaticjoint.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/PxPrismaticJoint.h>
11
12#include <PxPhysics.h>
13
14#include <foundation/PxSimpleTypes.h>
15
17
18/*!
19 \qmltype PrismaticJoint
20 \inqmlmodule QtQuick3D.Physics
21 \since 6.12
22 \brief A prismatic joint.
23
24 A prismatic joint permits relative translational movement between two bodies along an axis, but
25 no relative rotational movement. the axis on each body is defined as the line containing the
26 origin of the joint frame and extending along the x-axis of that frame
27
28 \sa {DistanceJoint}
29 \sa {FixedJoint}
30 \sa {RevoluteJoint}
31 \sa {SphericalJoint}
32*/
33
34/*!
35 \qmlproperty real PrismaticJoint::lowerLimit
36 \since 6.12
37 \default 0.0
38
39 The lower limit of the constraint, i.e. how far along the negative x-axis the joint can extend.
40
41 Range: \c{[-inf, inf]}
42
43 \sa upperLimit
44*/
45
46/*!
47 \qmlproperty real PrismaticJoint::upperLimit
48 \since 6.12
49 \default 0.0
50
51 The upper limit of the constraint, i.e. how far along the positive x-axis the joint can extend.
52
53 Range: \c{[-inf, inf]}
54
55 \sa lowerLimit
56*/
57
58physx::PxJoint *QPrismaticJoint::createPhysxJoint(physx::PxRigidActor *actorA,
59 physx::PxRigidActor *actorB,
60 const physx::PxTransform &trfA,
61 const physx::PxTransform &trfB)
62{
63 return physx::PxPrismaticJointCreate(*StaticPhysXObjects::getReference().physics, actorA, trfA,
64 actorB, trfB);
65}
66
67void QPrismaticJoint::setJointProperties()
68{
69 physx::PxPrismaticJoint *joint = static_cast<physx::PxPrismaticJoint *>(m_joint);
70 const physx::PxTolerancesScale scale =
71 StaticPhysXObjects::getReference().physics->getTolerancesScale();
72 const float lowerLimit = qMin(m_lowerLimit, m_upperLimit);
73 const float upperLimit = qMax(m_lowerLimit, m_upperLimit);
74 joint->setLimit(physx::PxJointLinearLimitPair(scale, lowerLimit, upperLimit));
75 joint->setPrismaticJointFlag(physx::PxPrismaticJointFlag::eLIMIT_ENABLED, true);
76}
77
78float QPrismaticJoint::lowerLimit() const
79{
80 return m_lowerLimit;
81}
82
83void QPrismaticJoint::setLowerLimit(float newLowerLimit)
84{
85 newLowerLimit = qBound(-PX_MAX_F32, newLowerLimit, PX_MAX_F32);
86 if (qFuzzyCompare(m_lowerLimit, newLowerLimit))
87 return;
88 m_lowerLimit = newLowerLimit;
89 m_dirtyProperties = true;
90 emit lowerLimitChanged();
91}
92
93float QPrismaticJoint::upperLimit() const
94{
95 return m_upperLimit;
96}
97
98void QPrismaticJoint::setUpperLimit(float newUpperLimit)
99{
100 newUpperLimit = qBound(-PX_MAX_F32, newUpperLimit, PX_MAX_F32);
101 if (qFuzzyCompare(m_upperLimit, newUpperLimit))
102 return;
103 m_upperLimit = newUpperLimit;
104 m_dirtyProperties = true;
105 emit upperLimitChanged();
106}
107
#define QT_BEGIN_NAMESPACE
#define QT_END_NAMESPACE
#define emit