Entity { // Некий контейнер - большой куб, содержит под-объект - малый куб. components: [ Mesh { source: "qrc:/assets/models/big-cube.obj" }, Transform { // Содержит все 3-д свойства большого куба (матрицы и прочее) }, PhongMaterial { ambient: "green" } ] Entity { // Некий чайлд - малый куб components: [ Mesh { source: "qrc:/assets/models/small-cube.obj" }, Transform { // Содержит все 3-д свойства малого куба (матрицы и прочее) }, PhongMaterial { ambient: "red" } ] }}
C++ (Qt) QMatrix4x4 m = matrix1 * matrix2; QVector3D gravity(0, -1, 0); QVector3D v = m.mapVector(gravity); qDebug() << v;
import Qt3D.Core 2.0import Qt3D.Extras 2.15import Qt3D.Input 2.0import Qt3D.Render 2.15 import QtQuick.Scene3D 2.0 Scene3D { focus: true aspects: ["input", "logic"] cameraAspectRatioMode: Scene3D.AutomaticAspectRatio property alias bigCubeRotationX: bigCuberansform.rotationX property alias bigCubeRotationZ: bigCuberansform.rotationZ property alias smallCubeRotationY: smallCuberansform.rotationY function calculateMatrix(bigMatrix, smallMatrix) { detector.setupObjectMatrix(bigMatrix, smallMatrix); } Entity { components: [ RenderSettings { activeFrameGraph: ForwardRenderer { camera: camera clearColor: "white" } }, InputSettings { } ] Camera { id: camera projectionType: CameraLens.PerspectiveProjection fieldOfView: 45 position: Qt.vector3d(0.0, 1, 3.0) upVector: Qt.vector3d(0.0, 1.0, 0.0) viewCenter: Qt.vector3d(0.0, 0.0, 0.0) } FirstPersonCameraController { camera: camera linearSpeed: 10.0 acceleration: 5.0 deceleration: 5.0 } Entity { components: [ PointLight {}, Transform { translation: camera.position } ] } Entity { components: [ CuboidMesh { xExtent: 1 yExtent: 0.2 zExtent: 0.5 }, Transform { id: bigCuberansform onMatrixChanged: calculateMatrix(bigCuberansform.matrix, smallCuberansform.matrix) }, PhongAlphaMaterial { alpha: 0.8 diffuse: "red" } ] Entity { components: [ CuboidMesh { xExtent: 0.5 yExtent: 0.1 zExtent: 0.2 }, Transform { id: smallCuberansform onMatrixChanged: calculateMatrix(bigCuberansform.matrix, smallCuberansform.matrix) }, PhongAlphaMaterial { alpha: 0.8 diffuse: "green" } ] } } }}
C++ (Qt)void OrientationDetector::setupObjectMatrix(const QMatrix4x4 &matrix1, const QMatrix4x4 &matrix2){ QMatrix4x4 m = matrix1 * matrix2; QVector3D gravity(0, -1, 0); QVector3D v = m.mapVector(gravity); qDebug() << v;}