1 | // Copyright (C) 2021 The Qt Company Ltd. |
---|---|
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only |
3 | |
4 | #include "qabstractcollisionshape_p.h" |
5 | |
6 | #include <QtQml/QQmlListReference> |
7 | |
8 | #include "qphysicsworld_p.h" |
9 | |
10 | QT_BEGIN_NAMESPACE |
11 | |
12 | /*! |
13 | \qmltype CollisionShape |
14 | \inherits Node |
15 | \inqmlmodule QtQuick3D.Physics |
16 | \since 6.4 |
17 | \brief Base type for collision shapes. |
18 | |
19 | This is the base type for all collision shapes. A collision shape |
20 | is used to define the physical shape and extent of an object for the |
21 | purposes of the physics simulation. |
22 | |
23 | \sa {Qt Quick 3D Physics Shapes and Bodies}{Shapes and Bodies overview documentation} |
24 | */ |
25 | |
26 | /*! |
27 | \qmlproperty bool CollisionShape::enableDebugDraw |
28 | This property enables drawing the shape's debug view. |
29 | */ |
30 | |
31 | QAbstractCollisionShape::QAbstractCollisionShape(QQuick3DNode *parent) : QQuick3DNode(parent) |
32 | { |
33 | connect(sender: this, signal: &QQuick3DNode::sceneScaleChanged, context: this, |
34 | slot: &QAbstractCollisionShape::handleScaleChange); |
35 | } |
36 | |
37 | QAbstractCollisionShape::~QAbstractCollisionShape() = default; |
38 | |
39 | bool QAbstractCollisionShape::enableDebugDraw() const |
40 | { |
41 | return m_enableDebugDraw; |
42 | } |
43 | |
44 | void QAbstractCollisionShape::setEnableDebugDraw(bool enableDebugDraw) |
45 | { |
46 | if (m_enableDebugDraw == enableDebugDraw) |
47 | return; |
48 | |
49 | if (auto world = QPhysicsWorld::getWorld(node: this); world != nullptr && enableDebugDraw) |
50 | world->setHasIndividualDebugDraw(); |
51 | |
52 | m_enableDebugDraw = enableDebugDraw; |
53 | emit enableDebugDrawChanged(enableDebugDraw: m_enableDebugDraw); |
54 | } |
55 | |
56 | void QAbstractCollisionShape::handleScaleChange() |
57 | { |
58 | auto newScale = sceneScale(); |
59 | if (!qFuzzyCompare(v1: newScale, v2: m_prevScale)) { |
60 | m_prevScale = newScale; |
61 | m_scaleDirty = true; |
62 | emit needsRebuild(this); // TODO: remove signal argument? |
63 | } |
64 | } |
65 | |
66 | QT_END_NAMESPACE |
67 |