Qt 6.x
The Qt SDK
Loading...
Searching...
No Matches
qcharactercontroller_p.h
Go to the documentation of this file.
1// Copyright (C) 2022 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3
4#ifndef CHARACTERCONTROLLER_H
5#define CHARACTERCONTROLLER_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists purely as an
12// implementation detail. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include <QtQuick3DPhysics/qtquick3dphysicsglobal.h>
19#include <QtQuick3DPhysics/private/qabstractphysicsbody_p.h>
20#include <QtQml/QQmlEngine>
21#include <QVector3D>
22
24
26{
28 Q_PROPERTY(QVector3D movement READ movement WRITE setMovement NOTIFY movementChanged)
29 Q_PROPERTY(QVector3D gravity READ gravity WRITE setGravity NOTIFY gravityChanged)
30 Q_PROPERTY(bool midAirControl READ midAirControl WRITE setMidAirControl NOTIFY
31 midAirControlChanged)
32 Q_PROPERTY(Collisions collisions READ collisions NOTIFY collisionsChanged)
33 Q_PROPERTY(bool enableShapeHitCallback READ enableShapeHitCallback WRITE
34 setEnableShapeHitCallback NOTIFY enableShapeHitCallbackChanged)
35 QML_NAMED_ELEMENT(CharacterController)
36public:
38
39 enum class Collision {
40 None = 0,
41 Side = 1 << 0,
42 Up = 1 << 1,
43 Down = 1 << 2,
44 };
45 Q_DECLARE_FLAGS(Collisions, Collision)
46 Q_FLAG(Collisions)
47
48 const QVector3D &movement() const;
49 void setMovement(const QVector3D &newMovement);
50 const QVector3D &gravity() const;
51 void setGravity(const QVector3D &newGravity);
52 QVector3D getDisplacement(float deltaTime);
53 bool getTeleport(QVector3D &position);
54
55 bool midAirControl() const;
56 void setMidAirControl(bool newMidAirControl);
57
58 Q_INVOKABLE void teleport(const QVector3D &position);
59
60 const Collisions &collisions() const;
61 void setCollisions(const Collisions &newCollisions);
62
63 Q_REVISION(6, 5) bool enableShapeHitCallback() const;
64 Q_REVISION(6, 5) void setEnableShapeHitCallback(bool newEnableShapeHitCallback);
65
67 void movementChanged();
68 void gravityChanged();
69
70 void midAirControlChanged();
71
72 void collisionsChanged();
73 void enableShapeHitCallbackChanged();
74 void shapeHit(QAbstractPhysicsNode *body, const QVector3D &position, const QVector3D &impulse,
75 const QVector3D &normal);
76
78 QVector3D m_movement;
79 QVector3D m_gravity;
80 bool m_midAirControl = true;
81
82 QVector3D m_freeFallVelocity; // actual speed at start of next tick, if free fall
83
84 QVector3D m_teleportPosition;
85 bool m_teleport = false;
86 Collisions m_collisions;
87 bool m_enableShapeHitCallback = false;
88};
89
91
93
94#endif // CHARACTERCONTROLLER_H
QCharacterController()
\qmltype CharacterController \inqmlmodule QtQuick3D.Physics \inherits PhysicsBody
Q_REVISION(6, 5) bool enableShapeHitCallback() const
The QVector3D class represents a vector or vertex in 3D space.
Definition qvectornd.h:171
Combined button and popup list for selecting options.
#define Q_DECLARE_FLAGS(Flags, Enum)
Definition qflags.h:174
#define Q_DECLARE_OPERATORS_FOR_FLAGS(Flags)
Definition qflags.h:194
#define QML_NAMED_ELEMENT(NAME)
static qreal position(const QQuickItem *item, QQuickAnchors::Anchor anchorLine)
#define Q_PROPERTY(...)
#define Q_OBJECT
#define Q_REVISION(...)
#define Q_FLAG(x)
#define Q_INVOKABLE
#define signals
#define Q_QUICK3DPHYSICS_EXPORT