MCPcopy
hub / github.com/lo-th/Oimo.js / demo

Function demo

examples/demos/jewel.js:1–50  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1function demo() {
2
3 cam ( 90, 20, 100 );
4
5 world = new OIMO.World({
6 timestep: 1/60,
7 iterations: 8,
8 broadphase: 2, // 1: brute force, 2: sweep & prune, 3: volume tree
9 worldscale: 1,
10 random: true,
11 info:true // display statistique
12 });
13
14 var i, x, y, z, s, b;
15
16 var mx = 150;
17 var r = 50;
18 var a = (360/mx) * Math.torad;
19 var spring = [2, 0.3];// soften the joint ex: 100, 0.2
20
21 for( i = 0; i < mx; i++){
22
23 x = Math.sin(i*a) * r;
24 y = 60 + Math.sin(i*0.5) * 2;
25 z = Math.cos(i*a) * r;
26
27 add({ type:'sphere', size:[1], pos:[x, y, z], move:1 });
28
29 if( i > 0 ) world.add({ type:'jointHinge', body1:(i-1), body2:i, pos1:[0,-1,0], pos2:[0,1,0], collision:true, spring:spring });
30 if( i === mx-1 ) world.add({ type:'jointHinge', body1:mx-1, body2:0, pos1:[0,-1,0], pos2:[0,1,0], collision:true, spring:spring });
31
32 }
33
34 var ground = world.add({size:[1000, 10, 1000], pos:[0,-5,0], density:1 });
35
36
37
38 for( i = 0; i<40; i++ ){
39 x = rand(-50, 50);
40 z = rand(-50, 50);
41 s = rand(5, 15);
42 add({ type:'box', geometry:geo.dice, size:[s,s,s], pos:[x,s*0.5,z], move:true });
43 }
44
45 // world internal loop
46
47 world.postLoop = postLoop;
48 world.play();
49
50};
51
52function postLoop () {
53

Callers

nothing calls this directly

Calls 2

camFunction · 0.50
addFunction · 0.50

Tested by

no test coverage detected