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 View3D, DynamicsWorld, PerspectiveCamera 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; staticFriction, dynamicFriction 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.