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

'기본 도형' 예제는 Qt 3D 에서 제공하는 네 가지 기본 도형, 즉 토러스, 원기둥, 정육면체 및 구체를 보여줍니다. 또한 이 예제는 Qt 3D 장면을 위젯에 삽입하고 다른 위젯과 연결하는 방법도 보여줍니다.
예제 실행
다음 경로에서 예제를 실행할 수 있습니다:
- Qt Creator
Welcome 모드를 열고 Examples 에서 예제를 선택하십시오. 자세한 내용은 Qt Creator 의 ‘튜토리얼: 빌드 및 실행’을 참조하십시오.
- Qt Extension for Visual Studio Code
Command Palette 에서 ‘ Qt: Open Qt examples ’ 명령을 실행하고 목록에서 예제를 선택합니다. 자세한 내용은 Qt Extension for Visual Studio Code: 튜토리얼: 빌드 및 실행을 참조하십시오.
토러스 메쉬 설정
예시로 토러스 메쉬를 설정하는 방법을 살펴보겠습니다. 먼저 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);
}© 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.