Qt Quick 3D物理-材质示例

Qt Quick 3D Physics - Material Example

Qt Quick 3D物理-材质示例

Demonstrates using physical materials.

演示使用物理材质。

The Material example demonstrates how to control the material properties of a physical body. The scene contains the usual boilerplate of a View3DDynamicsWorldPerspectiveCamera and DirectionalLight. In addition to this the scene contains two physical bodies, namely a slightly tilted plane and a box. Every physical body has a physicsMaterial property containing a PhysicsMaterial node. PhysicsMaterial contains these three material properties; staticFrictiondynamicFriction and restitution and these are used to define how the body will act when colliding with and sliding against other bodies. There is a simple user interface that allows to interactively tweak the material of the box so you can see how it interacts depending on its material properties.

​“材质”示例演示了如何控制物体的材质属性。场景包含View3D、DynamicsWorld、PerspectiveCamera和Directional Light的常用样板。除此之外,场景还包含两个实体,即一个略微倾斜的平面和一个长方体。每个物体都有一个包含PhysisMaterial节点的physicsMaterial属性。PhysicsMaterial包含这三种材料属性;静态摩擦力、动态摩擦力和恢复力,这些都用于定义物体在与其他物体碰撞和滑动时的行为。有一个简单的用户界面,允许以交互方式调整长方体的材质,以便根据其材质属性查看其交互方式。​

This is the QML code for the material:

这是材质的QML代码:

PhysicsMaterial {
    id: physicsMaterial
    staticFriction: staticFrictionSlider.value
    dynamicFriction: dynamicFrictionSlider.value
    restitution: restitutionSlider.value
}

The material is simply referencing the values of the user interface's sliders. This same material is then used for both the box and the floor:

材质只是引用用户界面滑块的值。然后将相同的材质用于盒子和地板:

DynamicRigidBody {
    id: box
    physicsMaterial: physicsMaterial
    density: 10
    property var startPosition: Qt.vector3d(700, 300, 0)
    position: startPosition
    Model {
        source: "#Cube"
        materials: PrincipledMaterial {
            baseColor: "red"
        }
    }
    collisionShapes: BoxShape {}
}
StaticRigidBody {
    eulerRotation: Qt.vector3d(-79, -90, 0)
    scale: Qt.vector3d(20, 30, 100)
    physicsMaterial: physicsMaterial
    collisionShapes: PlaneShape {}
    Model {
        source: "#Rectangle"
        materials: DefaultMaterial {
            diffuseColor: "green"
        }
    }
}

Files:

© 2022 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值