QT3D學習筆記——圓臺、圓錐

類名作用
Qt3DWindow3D渲染窗口容器
QEntity場景中的實體(對象或容器)
QCamera控制觀察視角
QPointLight點光源
QConeMesh圓錐幾何網格
QTransform控制實體的位置/旋轉/縮放
QPhongMaterialPhong光照材質(定義顏色、反光等)
QFirstPersonCameraController第一人稱相機控制器(WASD+鼠標控制)

Qt3DWindow(3D 窗口)

├─ RootEntity (QEntity 根實體)
│ ? ├─ Camera (QCamera 相機)
│ ? │ ? ├─ Lens (鏡頭:透視投影參數)
│ ? │ ? └─ Controller (控制器:WASD+鼠標控制)
│ ? │
│ ? ├─ Light (光源)
│ ? │ ? ├─ QPointLight(點光源:顏色/強度)
│ ? │ ? └─ QTransform (變換:光源位置)

│ ? │
│ ? └─ Cone (3d 圓錐實體)

│? ??? ?├─ QConeMesh (網格:幾何圖形)

│? ??? ?├─ QPhongMaterial (材質:顏色/反光)
│ ? ? ? └─ QTransform (變換:位置/旋轉)

│? ?
└─ FrameGraph (渲染管線:背景色/渲染設置)

//#include "mainwindow.h"//#include "FrustumWidget.h"
#include <QApplication>
#include <QtCore/QObject>
#include <QGuiApplication>#include <Qt3DRender/qcamera.h>
#include <Qt3DCore/qentity.h>
#include <Qt3DRender/qcameralens.h>#include <QtWidgets/QApplication>
#include <QtWidgets/QWidget>
#include <QtWidgets/QHBoxLayout>
#include <QtWidgets/QCheckBox>
#include <QtWidgets/QCommandLinkButton>
#include <QtGui/QScreen>#include <Qt3DInput/QInputAspect>#include <Qt3DExtras/qtorusmesh.h>
#include <Qt3DRender/qmesh.h>
#include <Qt3DRender/qtechnique.h>
#include <Qt3DRender/qmaterial.h>
#include <Qt3DRender/qeffect.h>
#include <Qt3DRender/qtexture.h>
#include <Qt3DRender/qrenderpass.h>
#include <Qt3DRender/qsceneloader.h>
#include <Qt3DRender/qpointlight.h>#include <Qt3DCore/qtransform.h>
#include <Qt3DCore/qaspectengine.h>#include <Qt3DRender/qrenderaspect.h>
#include <Qt3DExtras/qforwardrenderer.h>#include <Qt3DExtras/qt3dwindow.h>
#include <Qt3DExtras/qfirstpersoncameracontroller.h>
#include <Qt3DExtras/QPhongMaterial>
#include <Qt3DExtras/QConeMesh>
#include <QText2DEntity>
// 創建坐標軸線
Qt3DCore::QEntity* createAxisLine(Qt3DCore::QEntity* parent,const QVector3D& start,const QVector3D& end,const QColor& color) {Qt3DCore::QEntity* axis = new Qt3DCore::QEntity(parent);// 頂點數據QByteArray vertexData;vertexData.resize(2 * 3 * sizeof(float)); // 2 points xyzfloat* ptr = reinterpret_cast<float*>(vertexData.data());*ptr++ = start.x(); *ptr++ = start.y(); *ptr++ = start.z();*ptr++ = end.x();   *ptr++ = end.y();   *ptr++ = end.z();// 幾何體Qt3DCore::QGeometry* geometry = new Qt3DCore::QGeometry(axis);Qt3DCore::QBuffer* vertexBuffer = new Qt3DCore::QBuffer(geometry);vertexBuffer->setData(vertexData);Qt3DCore::QAttribute* positionAttr = new Qt3DCore::QAttribute(vertexBuffer,  // 直接傳遞緩沖區,不傳遞geometryQt3DCore::QAttribute::defaultPositionAttributeName(),Qt3DCore::QAttribute::Float,3,  // 每個頂點的分量數(xyz=3)2   // 頂點數量(起點+終點=2));geometry->addAttribute(positionAttr);  // 手動添加到geometry// 渲染器Qt3DRender::QGeometryRenderer* line = new Qt3DRender::QGeometryRenderer(axis);line->setGeometry(geometry);line->setPrimitiveType(Qt3DRender::QGeometryRenderer::Lines);// 材質Qt3DExtras::QPhongMaterial* material = new Qt3DExtras::QPhongMaterial(axis);material->setDiffuse(color);material->setAmbient(color);axis->addComponent(line);axis->addComponent(material);return axis;
}// 添加坐標軸標簽(需要Qt3DExtras模塊)
void addAxisLabel(Qt3DCore::QEntity* parent,const QString& text,const QVector3D& position) {Qt3DExtras::QText2DEntity* label = new Qt3DExtras::QText2DEntity(parent);label->setText(text);label->setColor(Qt::black);label->setHeight(20);label->setWidth(30);Qt3DCore::QTransform* transform = new Qt3DCore::QTransform(label);transform->setTranslation(position);label->addComponent(transform);
}
int main(int argc, char *argv[])
{QApplication a(argc, argv);//MainWindow w;//w.show();Qt3DExtras::Qt3DWindow *view = new Qt3DExtras::Qt3DWindow();//3D的渲染窗口,提供3D場景的顯示容器view->defaultFrameGraph()->setClearColor(QColor(Qt::black));//設置視圖背景色QWidget *widget = QWidget::createWindowContainer(view);QSize screenSize = view->screen()->size();widget->setMinimumSize(QSize(200, 100));widget->setMaximumSize(screenSize);widget->setWindowTitle(QStringLiteral("Basic shapes"));//3D中的基本實體類,代表場景中的一個對象或容器。Qt3DCore::QEntity *rootEntity = new Qt3DCore::QEntity();view->setRootEntity(rootEntity);//管理輸入設備的抽象層,啟用輸入處理(如鼠標、鍵盤事件)Qt3DInput::QInputAspect *input = new Qt3DInput::QInputAspect;view->registerAspect(input);//控制3D場景的觀察視角Qt3DRender::QCamera *cameraEntity = view->camera();cameraEntity->lens()->setPerspectiveProjection(45.0f, 16.0f / 9.0f, 0.1f, 1000.0f);cameraEntity->setUpVector(QVector3D(0, 1, 0));//定義相機的“向上”方向(通常為Y軸 (0,1,0))。cameraEntity->setPosition(QVector3D(0, 10.0f, 10.0f));//視點:觀察者所處的位置。cameraEntity->setViewCenter(QVector3D(0, 0, 0));//觀察目標點//高光控制Qt3DCore::QEntity *lightEntity = new Qt3DCore::QEntity(rootEntity);//點光源組件Qt3DRender::QPointLight *light = new Qt3DRender::QPointLight(lightEntity);light->setColor("white");light->setIntensity(1);lightEntity->addComponent(light);//定義3d實體的位置/旋轉/縮放Qt3DCore::QTransform *lightTransform = new Qt3DCore::QTransform(lightEntity);lightTransform->setTranslation(cameraEntity->position());lightEntity->addComponent(lightTransform);//啟用第一人稱相機控制(通過WASD和鼠標移動相機)Qt3DExtras::QFirstPersonCameraController *camController = new Qt3DExtras::QFirstPersonCameraController(rootEntity);camController->setCamera(cameraEntity);// 第一個圓錐(底部圓錐)Qt3DCore::QEntity *m_coneEntity = new Qt3DCore::QEntity(rootEntity);Qt3DExtras::QConeMesh *cone = new Qt3DExtras::QConeMesh();cone->setTopRadius(0.5);cone->setBottomRadius(0.5);cone->setLength(1);  // 高度為1cone->setRings(50);cone->setSlices(20);Qt3DCore::QTransform *coneTransform = new Qt3DCore::QTransform();coneTransform->setScale(1.0);//coneTransform->setRotation(QQuaternion::fromAxisAndAngle(QVector3D(1.0f, 0.0f, 0.0f), 45.0f));coneTransform->setTranslation(QVector3D(0.0f, 0.0f, 0.0f));  // 底部圓錐位于原點Qt3DExtras::QPhongMaterial *coneMaterial = new Qt3DExtras::QPhongMaterial();coneMaterial->setDiffuse(QColor(Qt::white));m_coneEntity->addComponent(cone);m_coneEntity->addComponent(coneMaterial);m_coneEntity->addComponent(coneTransform);// 第二個圓錐(頂部圓錐)Qt3DCore::QEntity *m_coneEntity1 = new Qt3DCore::QEntity(rootEntity);Qt3DExtras::QConeMesh *cone1 = new Qt3DExtras::QConeMesh();cone1->setTopRadius(0.5);cone1->setBottomRadius(0.5);cone1->setLength(1);  // 高度同樣為1cone1->setRings(50);cone1->setSlices(20);Qt3DCore::QTransform *coneTransform1 = new Qt3DCore::QTransform();coneTransform1->setScale(1.0);//coneTransform1->setRotation(QQuaternion::fromAxisAndAngle(QVector3D(1.0f, 0.0f, 0.0f), 45.0f));// 將第二個圓錐放在第一個圓錐的頂部// Y軸偏移 = 第一個圓錐的高度 + 第二個圓錐高度的一半(因為旋轉后中心點在幾何中心)coneTransform1->setTranslation(QVector3D(0.0f, 1.0f, 0.0f));Qt3DExtras::QPhongMaterial *coneMaterial1 = new Qt3DExtras::QPhongMaterial();coneMaterial1->setDiffuse(QColor(Qt::white));m_coneEntity1->addComponent(cone1);m_coneEntity1->addComponent(coneMaterial1);m_coneEntity1->addComponent(coneTransform1);widget->show();widget->resize(500, 500);return a.exec();
}

?

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/bicheng/84371.shtml
繁體地址,請注明出處:http://hk.pswp.cn/bicheng/84371.shtml
英文地址,請注明出處:http://en.pswp.cn/bicheng/84371.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

CSS | transition 和 transform的用處和區別

省流總結&#xff1a; transform用于變換/變形&#xff0c;transition是動畫控制器 transform 用來對元素進行變形&#xff0c;常見的操作如下&#xff0c;它是立即生效的樣式變形屬性。 旋轉 rotate(角度deg)、平移 translateX(像素px)、縮放 scale(倍數)、傾斜 skewX(角度…

夏普比率(Sharpe ratio)?

具有投資常識的人都明白&#xff0c;投資光看收益是不夠的&#xff0c;還要看承受的風險&#xff0c;也就是收益風險比。 夏普比率描述的正是這個概念&#xff0c;即每承受一單位的總風險&#xff0c;會產生多少超額的報酬。 用數學公式描述就是&#xff1a; 其中&#xff1…

C#學習第29天:表達式樹(Expression Trees)

目錄 什么是表達式樹&#xff1f; 核心概念 1.表達式樹的構建 2. 表達式樹與Lambda表達式 3.解析和訪問表達式樹 4.動態條件查詢 表達式樹的優勢 1.動態構建查詢 2.LINQ 提供程序支持&#xff1a; 3.性能優化 4.元數據處理 5.代碼轉換和重寫 適用場景 代碼復雜性…

計算機網絡備忘錄

計算機網絡 - 網絡互聯與互聯網 計算機網絡重點學習本章&#xff0c;屬于核心知識 包含網絡層和傳輸層 的 相關協議 計算機網絡層次重點掌握網絡層與傳輸層。其中網絡層主要是IP協議&#xff0c;解決主機-主機通信&#xff0c;傳輸層主要是TCP/UDP 協議&#xff0c;解決應用-…

跨界破局者魯力:用思辨與創新重塑汽車流通行業標桿

來源&#xff1a;投資家 在汽車流通行業深度變革的浪潮中&#xff0c;東莞東風南方汽車銷售服務有限公司塘廈分公司總經理魯力歷經近二十年行業深耕&#xff0c;構建了一條從汽車銷售顧問到區域運營掌舵者的進階范本。作為東風日產體系內兼具理論建構與實戰穿透力的標桿管理者…

玄機-日志分析-IIS日志分析

1.phpstudy-2018站點日志.(.log文件)所在路徑&#xff0c;提供絕對路徑 2.系統web日志中狀態碼為200請求的數量是多少 3.系統web日志中出現了多少種請求方法 4.存在文件上傳漏洞的路徑是什么(flag{/xxxxx/xxxxx/xxxxxx.xxx} 5.攻擊者上傳并且利用成功的webshell的文件名是什…

微信小程序開發知識點

1. 微信小程序開發知識點 1.1. 公共引用 1.1.1. 公共 wxss 在app.wxss文件下寫入組件樣式&#xff0c;也可使用import方式應用單獨公共樣式&#xff0c;避免了每個頁面單獨引用。 import "./public/wxss/base.wxss";1.1.2. 公共組件 在app.json文件下寫入組件&…

安卓基礎(編譯.Class)

方法安全性維護性開源友好度刪除.java用.class? 極低? 差?代碼混淆 (ProGuard)? 中等? 易?AAR 庫模塊? 高? 易? 對于.class 步驟 1&#xff1a;編譯生成 .class 文件 ??打開終端??&#xff08;Android Studio 底部的 Terminal 標簽頁&#xff09; 導航到你的模塊…

golang常用庫之-go-feature-flag庫(特性開關(Feature Flags))

文章目錄 golang常用庫之-go-feature-flag庫&#xff08;特性開關&#xff08;Feature Flags&#xff09;&#xff09;一、什么是特性開關&#xff08;Feature Flags&#xff09;二、go-feature-flag庫我可以使用 GO Feature Flag 做什么&#xff1f;選擇使用 Open Feature SDK…

微前端 - Module Federation使用完整示例

Angular 框架中 項目結構 main-app/src/app/app.module.tsapp.component.ts micro-app/src/app/app.module.tsapp.component.ts主應用配置 安裝必要依賴&#xff1a; ng add angular-architects/module-federation修改 webpack.config.js&#xff1a; const { share, Shar…

麒麟v10系統的docker重大問題解決-不支持容器名稱解析

今天給客戶在麒麟v10Kylin-Server-V10-SP1下安裝nextcloudonlyoffice的時候出現無法連接onlyoffice的問題,經過分析找到了是docker版本過低的原因,現在把解決思路和步驟分享給大家。 一、問題 用一鍵安裝工具,給客戶裝好了系統,Nextcloud可以正常訪問 但是訪問nextcloud中的o…

PyCharm中運行.py腳本程序

1.最近在弄一個python腳本程序&#xff0c;記錄下運行過程。 2.編寫的python程序如下 # # Copyright 2017 Pixar # # Licensed under the terms set forth in the LICENSE.txt file available at # https://openusd.org/license. # # Check whether this script is being run …

學習資料搜集-ARMv8 cache 操作

【ARM64】【cache/MMU】學習總結_arm64 mmu-CSDN博客 [mmu/cache]-ARMV8的cache的維護指令介紹_data cache set allocation-CSDN博客 https://download.csdn.net/blog/column/12036969/139483584 驗證碼_嗶哩嗶哩 【ARM Cache 與 MMU 系列文章 2 -- Cache Coherence及內存順…

Flutter快速上手,入門教程

目錄 一、參考文檔 二、準備工作 下載Flutter SDK&#xff1a; 配置環境 解決環境報錯 zsh:command not found:flutter 執行【flutter doctor】測試效果 安裝Xcode IOS環境 需要安裝brew&#xff0c;通過brew安裝CocoaPods. 復制命令行&#xff0c;打開終端 分別執行…

八股文——JVM

1. JVM組成 1.1 JVM由哪些部分組成&#xff1f;運行流程&#xff1f; Java Virtual Machine&#xff1a;Java 虛擬機&#xff0c;Java程序的運行環境&#xff08;java二進制字節碼的運行環境&#xff09;好處&#xff1a;一次編寫&#xff0c;到處運行&#xff1b;自動內存管理…

在Pnetlab6上繞過TPM、安全啟動和 RAM 檢查安裝windows 11筆記

筆者本次安裝的windows11的鏡像為: zh-cn_windows_11_enterprise_ltsc_2024_x64_dvd_cff9cd2d.iso 1、創建鏡像目錄并上傳iso文件 mkdir /opt/unetlab/addons/qemu/win-win11x64-2024-LTSC //目錄名稱務必按照官方文檔格式,否則無法識別 目錄創建完成后,將.iso格式鏡像上…

PCL點云庫入門(第18講)——PCL庫點云特征之3DSC特征描述3D shape context descriptor

一、3DSC&#xff08;3D Shape Context&#xff09;特征算法原理 1. 背景 3DSC 是一種描述三維點云局部形狀的特征描述子&#xff0c;受二維 Shape Context 的啟發。它用于捕捉點云某一點局部的幾何分布信息&#xff0c;對點云配準、識別等任務非常有效。 2. 基本思想 3DSC…

SpringBoot+Mysql校園跑腿服務平臺系統源碼

&#x1f497;博主介紹&#x1f497;&#xff1a;?在職Java研發工程師、專注于程序設計、源碼分享、技術交流、專注于Java技術領域和畢業設計? 溫馨提示&#xff1a;文末有 CSDN 平臺官方提供的老師 Wechat / QQ 名片 :) Java精品實戰案例《700套》 2025最新畢業設計選題推薦…

分庫分表的取舍

文章目錄 大數據量下采用**水平分表**的缺點**1. 跨表查詢復雜性與性能下降****2. 數據分布不均衡****3. 分布式事務與一致性問題****4. 擴展性受限****5. 查詢條件限制與索引管理復雜****6. 數據遷移與維護成本高****7. 業務邏輯復雜度增加****總結** shardingJdbc分片策略**1…

Vue3解決“找不到模塊@/components/xxx.vue或其相應的類型聲明ts文件(2307)”

問題 1&#xff1a;如果沒有這個env.d.ts文件&#xff0c;就新建 declare module "*.vue" {import { DefineComponent } from "vue";const component: DefineComponent<{}, {}, any>;export default component; }2&#xff1a;如果有tsconfig.json文…