1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
|
// Copyright (C) 2022 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#ifndef CHARACTERCONTROLLER_H
#define CHARACTERCONTROLLER_H
//
// W A R N I N G
// -------------
//
// This file is not part of the Qt API. It exists purely as an
// implementation detail. This header file may change from version to
// version without notice, or even be removed.
//
// We mean it.
//
#include <QtQuick3DPhysics/qtquick3dphysicsglobal.h>
#include <QtQuick3DPhysics/private/qabstractphysicsbody_p.h>
#include <QtQml/QQmlEngine>
#include <QVector3D>
QT_BEGIN_NAMESPACE
class Q_QUICK3DPHYSICS_EXPORT QCharacterController : public QAbstractPhysicsBody
{
Q_OBJECT
Q_PROPERTY(QVector3D movement READ movement WRITE setMovement NOTIFY movementChanged)
Q_PROPERTY(QVector3D gravity READ gravity WRITE setGravity NOTIFY gravityChanged)
Q_PROPERTY(bool midAirControl READ midAirControl WRITE setMidAirControl NOTIFY
midAirControlChanged)
Q_PROPERTY(Collisions collisions READ collisions NOTIFY collisionsChanged)
Q_PROPERTY(bool enableShapeHitCallback READ enableShapeHitCallback WRITE
setEnableShapeHitCallback NOTIFY enableShapeHitCallbackChanged)
QML_NAMED_ELEMENT(CharacterController)
public:
QCharacterController();
enum class Collision {
None = 0,
Side = 1 << 0,
Up = 1 << 1,
Down = 1 << 2,
};
Q_DECLARE_FLAGS(Collisions, Collision)
Q_FLAG(Collisions)
const QVector3D &movement() const;
void setMovement(const QVector3D &newMovement);
const QVector3D &gravity() const;
void setGravity(const QVector3D &newGravity);
QVector3D getDisplacement(float deltaTime);
bool getTeleport(QVector3D &position);
bool midAirControl() const;
void setMidAirControl(bool newMidAirControl);
Q_INVOKABLE void teleport(const QVector3D &position);
const Collisions &collisions() const;
void setCollisions(const Collisions &newCollisions);
QAbstractPhysXNode *createPhysXBackend() final;
Q_REVISION(6, 6) bool enableShapeHitCallback() const;
Q_REVISION(6, 6) void setEnableShapeHitCallback(bool newEnableShapeHitCallback);
signals:
void movementChanged();
void gravityChanged();
void midAirControlChanged();
void collisionsChanged();
void enableShapeHitCallbackChanged();
void shapeHit(QAbstractPhysicsNode *body, const QVector3D &position, const QVector3D &impulse,
const QVector3D &normal);
private:
QVector3D m_movement;
QVector3D m_gravity;
bool m_midAirControl = true;
QVector3D m_freeFallVelocity; // actual speed at start of next tick, if free fall
QVector3D m_teleportPosition;
bool m_teleport = false;
Collisions m_collisions;
bool m_enableShapeHitCallback = false;
};
Q_DECLARE_OPERATORS_FOR_FLAGS(QCharacterController::Collisions)
QT_END_NAMESPACE
#endif // CHARACTERCONTROLLER_H
|