이 페이지에서

Qt Quick 3D Physics - 간단한 예제

간단한 물리 장면 설정 방법을 보여줍니다.

세 개의 서로 다른 3D 오브젝트가 나란히 놓여 있는 푸른 풍경의 스크린샷

이 예제는 간단한 예제의 코드를 살펴보며 Quick 3D Physics의 기본 기능에 대한 개요를 제공합니다. 이 소개 내용은 Qt Quick 3D 모듈에 대한 기본 지식을 전제로 합니다.

설정

전체 예제는 main.qml 파일에 포함되어 있으며, 이 파일에서 설정됩니다. 먼저 물리 세계를 생성하는 객체를 살펴보겠습니다. 이 노드는 PhysicsWorld 라고 합니다:

PhysicsWorld {
    scene: viewport.scene
}

scene 속성을 View3D 의 scene으로 설정합니다. scene 속성은 시뮬레이션이 시뮬레이션할 물리 노드를 어디에서 찾을지 정의합니다. scene 노드 외부에 배치된 물리 노드는 시뮬레이션의 일부가 되지 않습니다.

씬

이제 씬을 살펴보겠습니다.

View3D {
    id: viewport
    anchors.fill: parent

    environment: SceneEnvironment {
        clearColor: "#d6dbdf"
        backgroundMode: SceneEnvironment.Color
    }

    PerspectiveCamera {
        position: Qt.vector3d(-200, 100, 500)
        eulerRotation: Qt.vector3d(-20, -20, 0)
        clipFar: 5000
        clipNear: 1
    }

    DirectionalLight {
        eulerRotation.x: -45
        eulerRotation.y: 45
        castsShadow: true
        brightness: 1
        shadowFactor: 50
    }

    StaticRigidBody {
        position: Qt.vector3d(0, -100, 0)
        eulerRotation: Qt.vector3d(-90, 0, 0)
        collisionShapes: PlaneShape {}
        Model {
            source: "#Rectangle"
            scale: Qt.vector3d(10, 10, 1)
            materials: PrincipledMaterial {
                baseColor: "green"
            }
            castsShadows: false
            receivesShadows: true
        }
    }

    DynamicRigidBody {
        position: Qt.vector3d(-100, 100, 0)
        collisionShapes: BoxShape {
            id: boxShape
        }
        Model {
            source: "#Cube"
            materials: PrincipledMaterial {
                baseColor: "yellow"
            }
        }
    }

    DynamicRigidBody {
        position: Qt.vector3d(0, 100, 0)
        collisionShapes: SphereShape {
            id: sphereShape
        }
        Model {
            source: "#Sphere"
            materials: PrincipledMaterial {
                baseColor: "blue"
            }
        }
    }

    DynamicRigidBody {
        position: Qt.vector3d(75, 200, 0)
        collisionShapes: CapsuleShape {
            id: capsuleShape
        }

        Model {
            geometry: CapsuleGeometry {}
            materials: PrincipledMaterial {
                baseColor: "red"
            }
        }
    }
}

물리적 객체를 렌더링하고자 하므로, 이 씬은 단순히 View3D 로 구성되어 있습니다. 여기에는 렌더링을 위한 PerspectiveCamera 와 DirectionalLight 가 포함되어 있지만, 더 중요한 것은 StaticRigidBody 와 세 개의 DynamicRigidBody 노드가 포함되어 있다는 점입니다. 물리학에서 강체(rigid body)는 일정한 밀도를 가진, 변형되지 않는 고체입니다. 사용 가능한 강체에는 두 가지 유형이 있습니다: StaticRigidBody 와 DynamicRigidBody. StaticRigidBody 는 정적(움직일 수 없는) 강체를 포함하는 QML 노드입니다. 기술적으로는 이 강체를 이동시킬 수 있지만, 이 경우 성능 저하가 발생합니다. 반면 DynamicRigidBody 는 이동할 수 있는 객체에 사용됩니다. DynamicRigidBody 에는 isKinematic 속성이 있으며, 이 속성이 true로 설정되면 리지드 바디는 외부 힘의 영향을 받지 않고 스크립트나 애니메이션을 통해 제어할 수 있습니다. 예를 들어, 축구공은 키네마틱이 아니지만 엘리베이터나 이동 플랫폼은 일반적으로 키네마틱입니다. 이는 또한 축구공의 position 속성을 업데이트하더라도 해당 위치로 이동하지 않는 반면, 엘리베이터는 이동한다는 것을 의미합니다.

다른 물리 객체와 상호작용하려면 ` collisionShapes ` 속성을 설정해야 합니다. ` collisionShapes ` 속성은 하나 이상의 도형을 포함할 수 있는 목록으로, 이 도형들은 하나의 강체로 결합되어 동작합니다. 이러한 도형들은 서로를 기준으로 위치와 회전을 조정할 수 있습니다. 단, 평면, 삼각형 메쉬 및 하이트맵 도형은 해당 강체가 키네마틱인 경우에만 동적 강체와 함께 작동한다는 점에 유의하십시오.

도형

이 씬에는 네 개의 물리 객체(평면, 상자, 공, 캡슐)가 포함되어 있습니다. 하나씩 살펴보겠습니다.

평면
StaticRigidBody {
    position: Qt.vector3d(0, -100, 0)
    eulerRotation: Qt.vector3d(-90, 0, 0)
    collisionShapes: PlaneShape {}
    Model {
        source: "#Rectangle"
        scale: Qt.vector3d(10, 10, 1)
        materials: PrincipledMaterial {
            baseColor: "green"
        }
        castsShadows: false
        receivesShadows: true
    }
}

평면은 ‘ StaticRigidBody ’ 노드를 생성하여 만듭니다. 이 노드에서 ‘ collisionShapes ’ 속성을 ‘ PlaneShape ’를 포함하도록 설정합니다. 평면은 공간을 ‘위’와 ‘아래’로 나눕니다. 평면 ‘아래’에 있는 모든 물체는 평면과 충돌하여 그 위로 밀려나게 됩니다. 평면은 YZ 평면에 위치하며, ‘위’는 양의 X 방향을 가리킵니다. 평면을 렌더링하기 위해 ‘ StaticRigidBody ’ 노드 안에 모델을 배치합니다. 이는 물리적 오브젝트가 씬 내에서 상호작용할 때 모델도 동일한 방식으로 이동하고 회전하도록 보장하는 일반적인 패턴입니다. 평면을 XY 평면에 위치시키고자 하므로 ‘ eulerRotation ’ 속성을 사용하여 회전시킵니다. 모델도 비슷한 방식으로 회전시킵니다.

박스
DynamicRigidBody {
    position: Qt.vector3d(-100, 100, 0)
    collisionShapes: BoxShape {
        id: boxShape
    }
    Model {
        source: "#Cube"
        materials: PrincipledMaterial {
            baseColor: "yellow"
        }
    }
}

‘ DynamicRigidBody ’ 노드와 ‘ collisionShapes ’ 내의 단일 ‘ BoxShape ’을 생성하여 구체를 만듭니다. 이 노드는 동적 노드이므로, 이 상자는 자유 물체처럼 충돌하고 이동하며 장면과 상호작용합니다. 큐브 모델은 단위 큐브보다 100배 더 크기 때문에 그에 맞게 크기를 조정해야 합니다. 이 모델은 동적 물체이므로 물리적 무게가 있으므로 ‘ density ’ 속성을 설정합니다.

구
DynamicRigidBody {
    position: Qt.vector3d(0, 100, 0)
    collisionShapes: SphereShape {
        id: sphereShape
    }
    Model {
        source: "#Sphere"
        materials: PrincipledMaterial {
            baseColor: "blue"
        }
    }
}

collisionShapes 에서 ‘ DynamicRigidBody ’ 노드와 단일 ‘ SphereShape ’ 노드를 생성하여 구체를 만듭니다.

캡슐
DynamicRigidBody {
    position: Qt.vector3d(75, 200, 0)
    collisionShapes: CapsuleShape {
        id: capsuleShape
    }

    Model {
        geometry: CapsuleGeometry {}
        materials: PrincipledMaterial {
            baseColor: "red"
        }
    }
}

DynamicRigidBody 노드와 collisionShapes 내의 단일 CapsuleShape 를 생성하여 캡슐을 만듭니다. Qt Quick 3D 에서 제공하는 내장 CapsuleGeometry를 사용하여 캡슐 모델을 구축합니다.

파일:

© 2026 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.