Qt文档阅读笔记-Qt Quick 3D - Simple Example解析
程序运行截图如下:
还是动的。
官方出这篇博文的目的是如何教我们使用Qt Quick 3D去渲染简单的场景。
首先是设置其场景。
在main.qml文件中设置整个场景,导入QtQuick3D组建,用于使用各种3D数据类型:
import QtQuick3D 1.14Window {id: windowwidth: 1280height: 720visible: trueView3D {id: viewanchors.fill: parent//! [environment]environment: SceneEnvironment {clearColor: "skyblue"backgroundMode: SceneEnvironment.Color}//! [environment]//! [camera]PerspectiveCamera {position: Qt.vector3d(0, 200, -300)rotation: Qt.vector3d(30, 0, 0)}//! [camera]//! [light]DirectionalLight {rotation: Qt.vector3d(30, 70, 0)}//! [light]//! [objects]Model {position: Qt.vector3d(0, -200, 0)source: "#Cylinder"scale: Qt.vector3d(2, 0.2, 1)materials: [ DefaultMaterial {diffuseColor: "red"}]}Model {position: Qt.vector3d(0, 150, 0)source: "#Sphere"materials: [ DefaultMaterial {diffuseColor: "blue"}]SequentialAnimation on y {loops: Animation.InfiniteNumberAnimation {duration: 3000to: -150from: 150easing.type:Easing.InQuad}NumberAnimation {duration: 3000to: 150from: -150easing.type:Easing.OutQuad}}}//! [objects]}}
定义了场景所处的环境。在这个例子中将background的颜色改成了‘skyblue’。
environment: SceneEnvironment {clearColor: "skyblue"backgroundMode: SceneEnvironment.Color}
随后定义了场景中的相机。在此官方实例中使用了PerspectiveCamera充当相机,将相机向后移,这个后是指人倒退向后这个,并且给一个看的角度
PerspectiveCamera {position: Qt.vector3d(0, 200, -300)rotation: Qt.vector3d(30, 0, 0)}
在画物体前,还需要一个光源去照,在物理里面,只有光照到物体上,反射的光进入眼睛才会有颜色,没有光就是一坨黑。
DirectionalLight {rotation: Qt.vector3d(30, 70, 0)}
其次是画简单的物体。
画一个用红色圆柱弄的圆盘,并且画一个球,这个球有一些动态效果
Model {position: Qt.vector3d(0, -200, 0)source: "#Cylinder"scale: Qt.vector3d(2, 0.2, 1)materials: [ DefaultMaterial {diffuseColor: "red"}]}Model {position: Qt.vector3d(0, 150, 0)source: "#Sphere"materials: [ DefaultMaterial {diffuseColor: "blue"}]SequentialAnimation on y {loops: Animation.InfiniteNumberAnimation {duration: 3000to: -150from: 150easing.type:Easing.InQuad}NumberAnimation {duration: 3000to: 150from: -150easing.type:Easing.OutQuad}}}
源码如下:
simple.pro
QT += quick quick3d-privatetarget.path = $$[QT_INSTALL_EXAMPLES]/quick3d/simple
INSTALLS += targetSOURCES += \main.cppRESOURCES += \qml.qrcOTHER_FILES += \doc/src/*.*
main.cpp
#include <QGuiApplication>
#include <QQmlApplicationEngine>#include <QtGui>
#include <QtQuick3D/private/qquick3dviewport_p.h>int main(int argc, char *argv[])
{QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);QGuiApplication app(argc, argv);QSurfaceFormat::setDefaultFormat(QQuick3DViewport::idealSurfaceFormat(4));QQmlApplicationEngine engine;engine.load(QUrl(QStringLiteral("qrc:/main.qml")));if (engine.rootObjects().isEmpty())return -1;return app.exec();
}
main.qml
import QtQuick 2.14
import QtQuick.Window 2.14
import QtQuick3D 1.14Window {id: windowwidth: 1280height: 720visible: trueView3D {id: viewanchors.fill: parent//! [environment]environment: SceneEnvironment {clearColor: "skyblue"backgroundMode: SceneEnvironment.Color}//! [environment]//! [camera]PerspectiveCamera {position: Qt.vector3d(0, 200, -300)rotation: Qt.vector3d(30, 0, 0)}//! [camera]//! [light]DirectionalLight {rotation: Qt.vector3d(30, 70, 0)}//! [light]//! [objects]Model {position: Qt.vector3d(0, -200, 0)source: "#Cylinder"scale: Qt.vector3d(2, 0.2, 1)materials: [ DefaultMaterial {diffuseColor: "red"}]}Model {position: Qt.vector3d(0, 150, 0)source: "#Sphere"materials: [ DefaultMaterial {diffuseColor: "blue"}]SequentialAnimation on y {loops: Animation.InfiniteNumberAnimation {duration: 3000to: -150from: 150easing.type:Easing.InQuad}NumberAnimation {duration: 3000to: 150from: -150easing.type:Easing.OutQuad}}}//! [objects]}
}
Qt文档阅读笔记-Qt Quick 3D - Simple Example解析相关推荐
- Qt文档阅读笔记-Qt跨平台库(Qt基本库)
Qt基本库是所有Qt平台的基础分.他能在所有支持开发的平台和测试平台上跑.这些库在Qt5中已经保持源代码和二进制的兼容. 基本模块(基本库)被其他特殊模块所附加. 下面是Qt基本模块(基本库)的列表: ...
- Qt文档阅读笔记-Qt Core的官方解析
Qt Core 目录 Getting Started Threading and Concurrent Programming Input/Output, Resources, Containers ...
- Qt文档阅读笔记-Qt Quick Controls - Wearable Demo实例解析
程序运行截图如下: 这个实例主要是用qml玩界面. main.qml文件以及wearable.qml分别是由ApplicationWindow和StatckView.这个StackView用于做导航相 ...
- Qt文档阅读笔记-Qt Quick Examples - Text 初步解析
目录 Hello Fonts Available Fonts Banner Img Tag Text Layout Hello Hello展示了改变字间距和动态展示.使用连续的动画,font.Lett ...
- Qt文档阅读笔记-Qt 3D: Simple C++ Example解析
本节官方Demo,使用Qt3D渲染场景 在main.cpp文件中,设置scene. 为了能使用相关的类和函数,需要include.Qt3DCore.Qt3D.Qt3DExtras模块. #includ ...
- Qt文档阅读笔记-Qt对象模型及deleteLater()杂记
最近主要在撸官方的自学包.在此作下简短的笔记: Qt对象模型 Qt包含的1500个类可以分为2类 1. identify types: 2. value types: identify types: ...
- Qt文档阅读笔记-QThread::setPriority(Priority priority)官方解析及实例
目录 官方解析 博主栗子 官方解析 QThread::setPriority(Priority priority) 这个函数为运行的线程设置了优先级.如果这个线程没有运行,那么这么函数啥事都不会做,并 ...
- Qt文档阅读笔记-QtConcurrent Map Example官方实例解析
这个例子对数据处理有很大的用处,在此记录下. 官方对应这个例子解析如下: QtConcurrent Map exapmle展示了使用QtConcurrent API的同步(阻塞)接口对图片进行拉伸.这 ...
- Qt文档阅读笔记-Qt单元测试中模拟GUI事件
这里先提下基本概念 官方的模拟GUI事件,就是调用QTest提供的函数,去模拟用户鼠标点击,用户输入等效果.从而达到模拟的功能,感觉这个功能非常的好. 如: QTest::keyClicks()主要是 ...
最新文章
- ADAS处理器集成功能安全单片机MCU
- pb打印选择页数_要想打印不卡纸,卡纸原因要了解
- 开源的自然语言处理工具
- Delphi 中的字符串函数(6) - StrUtils 中的 Ansi 字符串函数
- 诗与远方:无题(三十四)- 曾经写给妹子的一首诗
- 理解Vue的计算属性
- 五、RabbitMQ管理与高可用集群
- 火山翻译亮相飞书未来无限大会,打造全新翻译体验
- 一种基于DCNN模型的云检测方法介绍
- 2020软件测试报告模板
- fedora mysql gui,fedora 14 启用无线网卡 | 勤奋的小青蛙
- 【Arcgis】Extract by Mask时出错,ERROR 999999
- 央央家政解读:育儿嫂服务内容和标准
- 数字记忆好方法:数字编码
- linux安装frps服务,Debian手动搭建frps服务端
- 虚拟文件系统(无持久存储的文件系统),以proc和sysfs为例
- 阿里巴巴中台战略思想与架构实战笔记
- 03独立按键控制LED移动
- c语言实验作业在dev蜗居的思路,C语言程序设计实验(共5篇)
- 源码奉送:宠物小精灵图鉴