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 | Default value: \c{false} |
31 | */ |
32 | |
33 | QAbstractCollisionShape::QAbstractCollisionShape(QQuick3DNode *parent) : QQuick3DNode(parent) |
34 | { |
35 | connect(sender: this, signal: &QQuick3DNode::sceneScaleChanged, context: this, |
36 | slot: &QAbstractCollisionShape::handleScaleChange); |
37 | } |
38 | |
39 | QAbstractCollisionShape::~QAbstractCollisionShape() = default; |
40 | |
41 | bool QAbstractCollisionShape::enableDebugDraw() const |
42 | { |
43 | return m_enableDebugDraw; |
44 | } |
45 | |
46 | void QAbstractCollisionShape::setEnableDebugDraw(bool enableDebugDraw) |
47 | { |
48 | if (m_enableDebugDraw == enableDebugDraw) |
49 | return; |
50 | |
51 | if (auto world = QPhysicsWorld::getWorld(node: this); world != nullptr && enableDebugDraw) |
52 | world->setHasIndividualDebugDraw(); |
53 | |
54 | m_enableDebugDraw = enableDebugDraw; |
55 | emit enableDebugDrawChanged(enableDebugDraw: m_enableDebugDraw); |
56 | } |
57 | |
58 | void QAbstractCollisionShape::handleScaleChange() |
59 | { |
60 | auto newScale = sceneScale(); |
61 | if (!qFuzzyCompare(v1: newScale, v2: m_prevScale)) { |
62 | m_prevScale = newScale; |
63 | m_scaleDirty = true; |
64 | emit needsRebuild(this); // TODO: remove signal argument? |
65 | } |
66 | } |
67 | |
68 | QT_END_NAMESPACE |
69 |