| 1 | function demo() { |
| 2 | |
| 3 | cam ( 0, 10, 40 ); |
| 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 | |
| 15 | // just a try !! |
| 16 | // plane is only with sphere |
| 17 | |
| 18 | var ground = world.add({type:'plane', pos:[0,0,0], density:1, friction:0.9, restitution:0.1 }); |
| 19 | //var ground = world.add({type:'box', pos:[0,-5,0], size:[50, 10, 50], density:1 }) |
| 20 | |
| 21 | // basic geometry body |
| 22 | |
| 23 | var i = 500, d, h, w, o; |
| 24 | |
| 25 | while( i-- ) { |
| 26 | |
| 27 | w = Math.rand(0.5,3); |
| 28 | h = Math.rand(0.1,4); |
| 29 | d = Math.rand(0.1,1); |
| 30 | |
| 31 | o = { |
| 32 | |
| 33 | move:true, |
| 34 | density:1, |
| 35 | pos : [ |
| 36 | Math.rand(-5,5), |
| 37 | Math.rand(2,20) + ( i*(w*2) ), |
| 38 | Math.rand(-5,5), |
| 39 | ], |
| 40 | rot : [ |
| 41 | Math.randInt(0,360), |
| 42 | Math.randInt(0,360), |
| 43 | Math.randInt(0,360), |
| 44 | ], |
| 45 | friction:0.9, restitution:0.1 |
| 46 | |
| 47 | }; |
| 48 | |
| 49 | rot = [ |
| 50 | Math.randInt(0,360), |
| 51 | Math.randInt(0,360), |
| 52 | Math.randInt(0,360), |
| 53 | ]; |
| 54 | |
| 55 | switch( 0 ){ |
| 56 | |
| 57 | case 0 : o.type = 'sphere'; o.size = [w]; break; |
| 58 | case 1 : o.type = 'box'; o.size = [w,w,d]; break; |
| 59 | case 2 : o.type = 'cylinder'; o.size = [d,h,d]; break; |
| 60 | |