-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathexample.js
58 lines (48 loc) · 1.19 KB
/
example.js
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
const Antikyth = require('.');
const FRAME_RATE = 60;
const TICK_TIME = 1000 / FRAME_RATE;
const SET_TIME = 1000 * 2;
const antikyth = new Antikyth();
const world = (() => {
const result = new Antikyth.World();
const floor = new Antikyth.Plane({
position: [0, 0, 0],
dimensions: [0, 1, 0],
mass: 0,
});
result.add(floor);
result.floor = floor;
const box = new Antikyth.Box({
position: [0, 2, 0],
rotation: [Math.PI / 8, 0, 0, 1],
dimensions: [1, 1, 1],
mass: 1,
});
box.on('update', ({position: [px, py, pz], rotation: [rx, ry, rz, rw]}) => {
console.log('box', px, py, pz);
});
result.add(box);
result.box = box;
const sphere = new Antikyth.Sphere({
position: [10, 2, 10],
size: 1,
mass: 1,
});
sphere.on('update', ({position: [px, py, pz], rotation: [rx, ry, rz, rw]}) => {
console.log('sphere', px, py, pz);
});
result.add(sphere);
result.sphere = sphere;
return result;
})();
antikyth.add(world);
// main loop
setInterval(() => {
antikyth.requestUpdate();
}, TICK_TIME);
setInterval(() => {
const {box} = world;
box.setPosition(0, 2, 0);
box.setRotation(Math.PI / 8, 0, 0, 1);
}, SET_TIME);
antikyth.start();