C 语言
Qt Quick Ultralite 视图变换示例
/****************************************************************************** ** ** Copyright (C) 2020 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the Qt Quick Ultralite module. ** ** $QT_BEGIN_LICENSE:COMM$ ** ** Commercial License Usage ** Licensees holding valid commercial Qt licenses may use this file in ** accordance with the commercial license agreement provided with the ** Software or, alternatively, in accordance with the terms contained in ** a written agreement between you and The Qt Company. For licensing terms ** and conditions see http://www.qt.io/terms-conditions. For further ** information use the contact form at http://www.qt.io/contact-us. ** ** $QT_END_LICENSE$ ** ******************************************************************************/import QtQuick 2.12 Item { id: root property CoverFlowState currentState property matrix4x4 globalPreMatrix: calcPreMatrix(currentState.coverSize) property matrix4x4 globalPostMatrix: calcPostMatrix(currentState.coverFlowX, currentState.coverFlowY, currentState.coverFlowW, currentState.coverFlowH, currentState.fov, currentState.viewDistance) property matrix4x4 reflectionTransform: Qt.matrix4x4(1, 0, 0, 0, 0, -1, 0, currentState.reflectionDistance, 0, 0, 1, 0, 0, 0, 0, 1) // Calc camera transform matrix function calcPostMatrix(x : real, y : real, w : real, h : real, fov : real, viewDist : real) : matrix4x4 { var t1 = mtxTranslate(x, y, 0) var s2 = mtxScale(w / 2, h / 2, 1) var t3 = mtxTranslate(1, 1, 0) var p4 = mtxPerspective(fov, w / h, 0.1, 100) var t5 = mtxTranslate(0, 0, -viewDist) return t1.times(s2.times(t3.times(p4.times(t5)))) } function calcPreMatrix(coverSize : real) : matrix4x4 { var t1 = mtxTranslate(-1, -1, 0) var s2 = mtxScale(2 / coverSize, 2 / coverSize, 1) return t1.times(s2) } function mtxTranslate(x : real, y : real, z : real) : matrix4x4 { return Qt.matrix4x4(1, 0, 0, x, 0, 1, 0, y, 0, 0, 1, z, 0, 0, 0, 1) } function mtxScale(x : real, y : real, z : real) : matrix4x4 { return Qt.matrix4x4(x, 0, 0, 0, 0, y, 0, 0, 0, 0, z, 0, 0, 0, 0, 1) } function mtxPerspective(fov : real, aspectRatio : real, near : real, far : real) : matrix4x4 { var fovRadians = (fov * Math.PI / 180) / 2 var fovCotan = Math.cos(fovRadians) / Math.sin(fovRadians) var s = 1.0 / (near - far) return Qt.matrix4x4(fovCotan / aspectRatio, 0, 0, 0, 0, fovCotan, 0, 0, 0, 0, (near + far) * s, (2 * near * far) * s, 0, 0, -1, 1) } Repeater { model: root.currentState.numberOfCovers delegate: Cover { required property int index texture: "cover" + index + ".jpg" coverIndex: index state: root.currentState postMatrix: root.globalPostMatrix preMatrix: root.globalPreMatrix reflectionTransform: root.reflectionTransform } } }