aboutsummaryrefslogtreecommitdiffstats
path: root/src/quick3dphysics/qabstractcollisionshape.cpp
blob: bfe76f1b9454d566b790837ca883c6330ef0a1a9 (plain)
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
// Copyright (C) 2021 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only

#include "qabstractcollisionshape_p.h"

#include <QtQml/QQmlListReference>

#include "qphysicsworld_p.h"

QT_BEGIN_NAMESPACE

/*!
    \qmltype CollisionShape
    \inherits Node
    \inqmlmodule QtQuick3D.Physics
    \since 6.4
    \brief Base type for collision shapes.

    This is the base type for all collision shapes. A collision shape
    is used to define the physical shape and extent of an object for the
    purposes of the physics simulation.

    \sa {Qt Quick 3D Physics Shapes and Bodies}{Shapes and Bodies overview documentation}
*/

/*!
    \qmlproperty bool CollisionShape::enableDebugDraw
    This property enables drawing the shape's debug view.

    Default value: \c{false}
*/

QAbstractCollisionShape::QAbstractCollisionShape(QQuick3DNode *parent) : QQuick3DNode(parent)
{
    connect(this, &QQuick3DNode::sceneScaleChanged, this,
            &QAbstractCollisionShape::handleScaleChange);
}

QAbstractCollisionShape::~QAbstractCollisionShape() = default;

bool QAbstractCollisionShape::enableDebugDraw() const
{
    return m_enableDebugDraw;
}

void QAbstractCollisionShape::setEnableDebugDraw(bool enableDebugDraw)
{
    if (m_enableDebugDraw == enableDebugDraw)
        return;

    if (auto world = QPhysicsWorld::getWorld(this); world != nullptr && enableDebugDraw)
        world->setHasIndividualDebugDraw();

    m_enableDebugDraw = enableDebugDraw;
    emit enableDebugDrawChanged(m_enableDebugDraw);
}

void QAbstractCollisionShape::handleScaleChange()
{
    auto newScale = sceneScale();
    if (!qFuzzyCompare(newScale, m_prevScale)) {
        m_prevScale = newScale;
        m_scaleDirty = true;
        emit needsRebuild(this); // TODO: remove signal argument?
    }
}

QT_END_NAMESPACE