Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
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
5
#
include
"qphysicsgravity_p.h"
6
7
#
include
"qcharactercontroller_p.h"
8
#
include
"qdynamicrigidbody_p.h"
9
10
#
include
<
QtCore
/
qdebug
.
h
>
11
12
QT_BEGIN_NAMESPACE
13
14
QPhysicsGravity::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
26
bool
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
44
bool
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
57
bool
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
72
QT_END_NAMESPACE
QT_BEGIN_NAMESPACE
Combined button and popup list for selecting options.
Definition
qsequentialanimationgroup.cpp:47
qtquick3dphysics
src
quick3dphysics
qphysicsgravity.cpp
Generated on
for Qt by
1.18.0