-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInteractiveItem.qml
73 lines (61 loc) · 2.04 KB
/
InteractiveItem.qml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import QtQuick 2.2
import Box2D 2.0
import Ros 1.0
Item {
id:item
width: 20
height: width
rotation: 0
objectName: "interactive"
property var boundingbox:
Polygon {
id:bbpoly
vertices: [
Qt.point(origin.x, origin.y),
Qt.point(origin.x + width * bbratio, origin.y),
Qt.point(origin.x + width * bbratio, origin.y + height * bbratio),
Qt.point(origin.x, origin.y + height * bbratio),
]
density: 1
friction: 1
restitution: 0.1
}
property alias body: cubeBody
property double bbratio: 1 // set later (cf below) once paintedWidth is known
Body {
id: cubeBody
target: item
world: physicsWorld
bodyType: Body.Dynamic
Component.onCompleted: {
cubeBody.addFixture(item.boundingbox);
}
angularDamping: 5
linearDamping: 5
}
Item {
// this item sticks to the 'visual' origin of the object, taking into account
// possible margins appearing when resizing
id: origin
rotation: parent.rotation
x: parent.x + (parent.width - parent.paintedWidth)/2
y: parent.y + (parent.height - parent.paintedHeight)/2
}
// PinchArea {
// anchors.fill: parent
// pinch.target: parent
// pinch.minimumRotation: -360
// pinch.maximumRotation: 360
// //pinch.minimumScale: 1
// //pinch.maximumScale: 1
// pinch.dragAxis: Pinch.XAndYAxis
// MouseArea {
// anchors.fill: parent
// drag.target: item
// scrollGestureEnabled: false
// }
// }
function isIn(tx, ty) {
return (tx > x) && (tx < x + width) && (ty > y) && (ty < y + height);
}
}