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