이 페이지에서

Qt 3D: C++ 기본 도형 예제

Qt 3D 가 제공하는 네 가지 기본 도형을 보여주고, 각 도형에 대한 메쉬를 생성합니다.

토러스, 원통, 직육면체, 구 등 4개의 3D 객체가 표시된 스크린샷

'기본 도형' 예제는 Qt 3D 에서 제공하는 네 가지 기본 도형, 즉 토러스, 원기둥, 정육면체 및 구체를 보여줍니다. 또한 이 예제는 Qt 3D 장면을 위젯에 삽입하고 다른 위젯과 연결하는 방법도 보여줍니다.

예제 실행

다음 경로에서 예제를 실행할 수 있습니다:

토러스 메쉬 설정

예시로 토러스 메쉬를 설정하는 방법을 살펴보겠습니다. 먼저 QTorusMesh 를 인스턴스화한 다음, 메쉬 관련 매개변수(토러스의 경우 반지름, 소반지름, 링 수 및 슬라이스 수)를 설정합니다.

m_torus = new Qt3DExtras::QTorusMesh();
m_torus->setRadius(1.0f);
m_torus->setMinorRadius(0.4f);
m_torus->setRings(100);
m_torus->setSlices(20);

토러스의 크기와 위치는 변환 컴포넌트를 사용하여 조정할 수 있습니다. 스케일, 평행 이동, 회전 컴포넌트를 생성하여 ‘ QTransform ’ 컴포넌트에 추가합니다.

Qt3DCore::QTransform *torusTransform = new Qt3DCore::QTransform();
torusTransform->setScale(2.0f);
torusTransform->setRotation(QQuaternion::fromAxisAndAngle(QVector3D(0.0f, 1.0f, 0.0f), 25.0f));
torusTransform->setTranslation(QVector3D(5.0f, 4.0f, 0.0f));

메시의 디퓨즈 색상을 변경하려면 QPhongMaterial 를 생성하고 디퓨즈 색상을 설정합니다.

Qt3DExtras::QPhongMaterial *torusMaterial = new Qt3DExtras::QPhongMaterial();
torusMaterial->setDiffuse(QColor(QRgb(0xbeb32b)));

마지막 단계는 토러스를 엔티티 트리에 추가하는 것이며, 이를 위해 부모 엔티티가 지정된 ` QEntity `를 생성하고, 앞서 생성한 메쉬, 머티리얼 및 변환 컴포넌트를 여기에 추가합니다.

m_torusEntity = new Qt3DCore::QEntity(m_rootEntity);
m_torusEntity->addComponent(m_torus);
m_torusEntity->addComponent(torusMaterial);
m_torusEntity->addComponent(torusTransform);

엔티티에 부모가 있는지 여부를 정의하여 엔티티의 표시 여부를 제어할 수 있습니다. 즉, 엔티티가 엔티티 트리의 일부인지 여부를 제어하는 것입니다.

void SceneModifier::enableTorus(bool enabled)
{
    m_torusEntity->setEnabled(enabled);
}

예제 프로젝트 @ code.qt.io

© 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.