-
Notifications
You must be signed in to change notification settings - Fork 2
/
McCurdyPhysicsExample2.html
128 lines (115 loc) · 3.78 KB
/
McCurdyPhysicsExample2.html
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<meta
name="viewport"
content="width=device-width,initial-scale=1,shrink-to-fit=no,user-scalable=no,maximum-scale=1"
/>
<title>Examples Physics</title>
<script src="https://aframe.io/releases/1.0.4/aframe.min.js"></script>
<script src="//cdn.rawgit.com/donmccurdy/aframe-physics-system/v4.0.1/dist/aframe-physics-system.min.js"></script>
</head>
<body>
<script>
AFRAME.registerComponent("boxgenerator", {
init: function () {
this.el.addEventListener("click", function () {
console.log("go");
let scene = document.querySelector("#scene");
let box = document.createElement("a-box");
box.setAttribute("dynamic-body", "shape:sphere;sphereRadius:0.15");
let x = Math.random() * 2.0 - 1;
box.setAttribute("position", `${x} 3 -3`);
box.setAttribute("scale", `0.2 0.2 0.2`);
box.setAttribute("color", "#F00");
scene.appendChild(box);
});
},
});
AFRAME.registerComponent("toel", {
init: function () {
let el = document.querySelector("#pendulum");
this.el.addEventListener('click',function() {
console.log(el.body);
el.body.applyImpulse(
new CANNON.Vec3(15,15,0),
new CANNON.Vec3().copy(el.getAttribute('position'))
)
});
},
});
</script>
<a-scene physics="debug:true;" id="scene">
<a-camera>
<a-cursor></a-cursor>
</a-camera>
<!-- <a-entity position="-2 0 -1">
<a-text value="Hinge" position="0 1.5 0" align="center"></a-text>
<a-box id="hinge-target" position="-0.25 1 0.0" color="#777" static-body scale="0.25 0.25 0.25"></a-box>
<a-box depth="0.1"
color="#F00"
position="0.0 1 0.0"
scale="0.25 0.25 0.25"
dynamic-body
constraint="type: hinge;
target: #hinge-target;
axis: 0 1 0;
targetAxis: 0 1 0;
pivot: -0.125 0 0;
targetPivot: 0.125 0 0.125;">
</a-box>
<a-box position="0.26 1 0" scale="0.25 0.25 0.25" color="#777" static-body></a-box>
</a-entity> -->
<a-plane
scale="10 10 10"
rotation="-90 0 0 "
color="gray"
static-body
></a-plane>
<a-box
wireframe="true"
color="red"
scale="0.2 0.2 0.2"
position="1 5 -3"
id="dsphere"
dynamic-body="shape:sphere;"
></a-box>
<a-box
wireframe="true"
color="blue"
scale="0.4 0.2 0.2"
position="0 2 -3"
id="dAnchor"
static-body="shape:box;"
></a-box>
<!-- <a-box
id="dbox"
wireframe="true"
color="red"
scale="4 0.2 0.2"
position="0 3 -3"
constraint="target:#dAnchor; type:hinge; targetPivot:0 0.3 0"
dynamic-body
></a-box> -->
<a-box
id="dbox"
wireframe="true"
color="red"
scale="4 0.2 0.2"
position="0 3 -3"
constraint="target:#dAnchor; type:coneTwist; pivot:0 -0.3 0"
dynamic-body
></a-box>
<!-- <a-box
id="dbox"
wireframe="true"
color="red"
scale="4 0.2 0.2"
position="0.01 1 -3"
static-body
></a-box> -->
<a-box rotation="0 0 0 " color="yellow" position="0 1.5 -3" scale="0.4 0.4 0.4" boxgenerator></a-box>
</a-scene>
</body>
</html>