Warning, /education/gcompris/external/qml-box2d/examples/revolute/revolute.qml is written in an unsupported language. File is not indexed.
0001 import QtQuick 2.0
0002 import Box2D 2.0
0003 import "../shared"
0004
0005 Item {
0006 id: screen
0007 width: 800
0008 height: 600
0009 focus: true
0010
0011 Keys.onPressed: {
0012 if (event.key === Qt.Key_Left) {
0013 revolute.motorSpeed -= 10;
0014 }
0015 else if (event.key === Qt.Key_Right) {
0016 revolute.motorSpeed += 10
0017 }
0018 }
0019
0020 Text {
0021 anchors {
0022 right: parent.right
0023 top: parent.top
0024 left: parent.left
0025 }
0026 height: 40
0027 horizontalAlignment: Text.AlignHCenter;
0028 text: "Left/Right buttons to control the speed, Mouse click to activate/deactivate motor"
0029 }
0030
0031 // BOX2D WORLD
0032 World { id: physicsWorld }
0033
0034 PhysicsItem {
0035 id: rod
0036 sleepingAllowed: false
0037 bodyType: Body.Dynamic
0038 x: 350
0039 y: 300
0040
0041 width: 250
0042 height: 40
0043
0044 fixtures: Box {
0045 width: rod.width
0046 height: rod.height
0047 density: 1;
0048 friction: 1;
0049 restitution: 0.3;
0050 }
0051
0052 Rectangle {
0053 color: "green"
0054 radius: 6
0055 anchors.fill: parent
0056 }
0057 }
0058
0059 PhysicsItem {
0060 id: middle
0061
0062 x: 400
0063 y: 300
0064
0065 fixtures: Circle { radius: itemShape.radius }
0066
0067 Rectangle {
0068 id: itemShape
0069 radius: width / 2
0070 width: 40; height: 40
0071 color: "black"
0072 }
0073 }
0074
0075 RevoluteJoint {
0076 id: revolute
0077 maxMotorTorque: 1000
0078 motorSpeed: 0
0079 enableMotor: false
0080 bodyA: middle.body
0081 bodyB: rod.body
0082 localAnchorA: Qt.point(20,20)
0083 }
0084
0085 // Debug
0086 DebugDraw {
0087 id: debugDraw
0088 world: physicsWorld
0089 opacity: 0.5
0090 visible: false
0091 }
0092
0093 MouseArea {
0094 anchors.fill: parent
0095 onClicked: revolute.enableMotor = !revolute.enableMotor
0096 }
0097 }