轉(zhuǎn)帖|使用教程|編輯:鮑佳佳|2021-08-06 10:49:34.150|閱讀 109 次
概述:Qt是一個跨平臺框架,通常用作圖形工具包,它不僅創(chuàng)建CLI應用程序中非常有用。演示結(jié)合 Qt 3D 渲染和 Qt Quick 2 元素。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關鏈接:
Qt是一個跨平臺框架,通常用作圖形工具包,它不僅創(chuàng)建CLI應用程序中非常有用。而且它也可以在三種主要的臺式機操作系統(tǒng)以及移動操作系統(tǒng)(如Symbian,Nokia Belle,Meego Harmattan,MeeGo或BB10)以及嵌入式設備,Android(Necessitas)和iOS的端口上運行。現(xiàn)在我們?yōu)槟闾峁┝嗣赓M的試用版。
Qt組件推薦:
演示結(jié)合 Qt 3D 渲染和 Qt Quick 2 元素。
Audio Visualizer 演示了如何實現(xiàn)將 Qt 3D 渲染與 Qt Quick 2D 元素結(jié)合使用的應用程序。該示例使用媒體播放器播放音樂,并將音樂的大小可視化為動畫條。
要從Qt Creator運行示例,請打開歡迎模式并從示例中選擇示例。有關更多信息,請訪問構建和運行示例。
audio-visualizer-qml/main.qml示例中的 Qt Quick ImplementationMediaPlayer用于播放音頻內(nèi)容。
MediaPlayer { id: mediaPlayer autoPlay: true volume: 0.5 source: "qrc:/music/tiltshifted_lost_neon_sun.mp3"
播放器由playButton和 c{stopButton} 控制?;趩螕舻?按鈕state的mainview更改。
3D 內(nèi)容是使用Scene3D類型呈現(xiàn)的。Audio Visualizer 的狀態(tài)保持在mainview. 它被傳遞給visualizer酒吧動畫所需要的。
Scene3D { anchors.fill: parent Visualizer { id: visualizer animationState: mainview.state numberOfBars: 120 barRotationTimeMs: 8160 // 68 ms per bar } }
該示例的 3D 元素是在audio-visualizer-qml/Visualizer.qml. 相機設置在固定位置,以從正確的角度顯示可視化條。
Camera { id: camera projectionType: CameraLens.PerspectiveProjection fieldOfView: 45 aspectRatio: 1820 / 1080 nearPlane: 0.1 farPlane: 1000.0 position: Qt.vector3d(0.014, 0.956, 2.178) upVector: Qt.vector3d(0.0, 1.0, 0.0) viewCenter: Qt.vector3d(0.0, 0.7, 0.0) }
ANodeInstantiator用于創(chuàng)建可視化音樂幅度的條形。
// Bars CuboidMesh { id: barMesh xExtent: 0.1 yExtent: 0.1 zExtent: 0.1 } NodeInstantiator { id: collection property int maxCount: parent.numberOfBars model: maxCount delegate: BarEntity { id: cubicEntity entityMesh: barMesh rotationTimeMs: sceneRoot.barRotationTimeMs entityIndex: index entityCount: sceneRoot.numberOfBars entityAnimationsState: animationState magnitude: 0 } }
該visualizer還包含一個Entity顯示進度。這個元素有一個曲線形狀的網(wǎng)格,它在一個級別上旋轉(zhuǎn)以顯示基于播放曲目的持續(xù)時間的進度。
// Progress Mesh { id: progressMesh source: "qrc:/meshes/progressbar.obj" } Transform { id: progressTransform property real defaultStartAngle: -90 property real progressAngle: defaultStartAngle rotationY: progressAngle } Entity { property Material progressMaterial: PhongMaterial { ambient: "#80C342" diffuse: "black" } components: [progressMesh, progressMaterial, progressTransform] }
在audio-visualizer-qml/BarEntity.qml有旋轉(zhuǎn)酒吧和更改欄顏色動畫。鋼筋按照環(huán)形形式在水平面上旋轉(zhuǎn)。同時,條的顏色是動畫的。
QQ2.NumberAnimation { id: angleAnimation target: angleTransform property: "barAngle" duration: rotationTimeMs loops: QQ2.Animation.Infinite running: true from: startAngle to: 360 + startAngle } QQ2.SequentialAnimation on barColor { id: barColorAnimations running: false QQ2.ColorAnimation { from: lowColor to: highColor duration: animationDuration } QQ2.PauseAnimation { duration: animationDuration } QQ2.ColorAnimation { from: highColor to: lowColor duration: animationDuration } }
每個小節(jié)的大小是從基于正在播放的曲目的單獨 .raw 文件中讀取的。當條形圍繞環(huán)旋轉(zhuǎn)時,高度會縮放以突出顯示當前播放的位置。一整輪旋轉(zhuǎn)后,將為該條獲取一個新值。
====================================================
想要了解或購買Qt正版授權的朋友,歡迎
Qt技術交流群現(xiàn)已開通,QQ搜索群號“765444821”或者掃描下方二維碼即可加入
本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請務必注明出處、不得修改原文相關鏈接,如果存在內(nèi)容上的異議請郵件反饋至chenjj@fc6vip.cn
文章轉(zhuǎn)載自: