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
qphysicsgravity.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// Qt-Security score:significant reason:default
4
6
9
10#include <QtCore/qdebug.h>
11
13
14QPhysicsGravity::Target QPhysicsGravity::targetOf(const QAbstractPhysicsNode *node)
15{
16 // By type and not by state: a body that is kinematic, out of the
17 // simulation or asleep can stop being so at any time, so those are
18 // skipped when the gravity is applied instead.
19 if (qobject_cast<const QDynamicRigidBody *>(node))
20 return Target::DynamicBody;
21 if (qobject_cast<const QCharacterController *>(node))
22 return Target::Character;
23 return Target::None;
24}
25
26bool QPhysicsGravity::setDirection(const QVector3D &newDirection, const char *owner)
27{
28 // It is used normalized, and QVector3D::normalized() gives a null vector
29 // for anything shorter than about 1e-6.
30 if (!qIsFinite(newDirection.x()) || !qIsFinite(newDirection.y())
31 || !qIsFinite(newDirection.z()) || newDirection.normalized().isNull()) {
32 qWarning().nospace() << owner
33 << ": direction must be finite and non-zero, ignoring "
34 << newDirection;
35 return false;
36 }
37
38 if (qFuzzyCompare(direction, newDirection))
39 return false;
40 direction = newDirection;
41 return true;
42}
43
44bool QPhysicsGravity::setGravity(float newGravity, const char *owner)
45{
46 if (!qIsFinite(newGravity)) {
47 qWarning().nospace() << owner << ": gravity must be finite, ignoring " << newGravity;
48 return false;
49 }
50
51 if (qFuzzyCompare(gravity, newGravity))
52 return false;
53 gravity = newGravity;
54 return true;
55}
56
57bool QPhysicsGravity::setUnitDistance(float newUnitDistance, const char *owner)
58{
59 if (!qIsFinite(newUnitDistance) || newUnitDistance < 0.0f) {
60 qWarning().nospace() << owner
61 << ": unitDistance must be finite and non-negative, ignoring "
62 << newUnitDistance;
63 return false;
64 }
65
66 if (qFuzzyCompare(unitDistance, newUnitDistance))
67 return false;
68 unitDistance = newUnitDistance;
69 return true;
70}
71
72QT_END_NAMESPACE
Combined button and popup list for selecting options.