forked from lo-th/Ammo.lab
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex_test.html
131 lines (92 loc) · 3.09 KB
/
index_test.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
129
130
131
<!DOCTYPE html>
<!-- saved from url=(0014)about:internet -->
<html lang="en">
<head>
<title>Ammo.lab.test</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="IE=11" />
<meta http-equiv="Pragma" content="no-cache">
<link rel="shortcut icon" href="favicon.ico">
<style>
body {
margin: 0px;
background-color: #000000;
overflow: hidden;
}
</style>
<!-- CODE -->
<!-- MAIN -->
<script src="./build/three.js"></script>
<script src="./js/controls/OrbitControls.js"></script>
<script src="./build/shot.js"></script>
</head>
<body>
<script>
var camera, scene, renderer, controler, light, physic;
var rand = THREE.Math.randInt;
init();
animate();
initPhysics();
function init() {
scene = new THREE.Scene();
renderer = new THREE.WebGLRenderer( { antialias: true } );
renderer.setPixelRatio( window.devicePixelRatio );
renderer.setSize( window.innerWidth, window.innerHeight );
document.body.appendChild( renderer.domElement );
camera = new THREE.PerspectiveCamera( 70, window.innerWidth / window.innerHeight, 1, 1000 );
camera.position.y = 20;
camera.position.z = 50;
controler = new THREE.OrbitControls( camera, renderer.domElement );
controler.target.set( 0, 10, 0 );
controler.screenSpacePanning = true;
controler.update();
light = new THREE.PointLight(0xffffff);
light.position.set(0,50,0);
scene.add(light);
scene.add( new THREE.AmbientLight( 0x333333 ));
//
window.addEventListener( 'resize', onWindowResize, false );
}
function onWindowResize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize( window.innerWidth, window.innerHeight );
}
function animate() {
requestAnimationFrame( animate );
renderer.render( scene, camera );
}
// PHYSICS
function initPhysics(){
physic = SHOT.engine;
physic.init( onPhysics );
}
function onPhysics(){
// add physics container
scene.add( physic.getContainer() );
// start simulation
physic.start();
// infinie plane
physic.add({ type:'plane', friction:1 });
// add random object
var i = 500, pos = [], s, d, rot = [0,0,90];
while( i-- ) {
h = 5;//rand(2,4);
d = 1;//rand(1,2);
pos[0] = rand(-5,5);
pos[1] = rand(2,20) + ( i*h );
pos[2] = rand(-5,5);
rot[2] = rand(-180,180);
switch( rand(4,4) ){
case 0 : physic.add({ type:'box', size:[d,h,d], pos:pos, mass:2 }); break;
case 1 : physic.add({ type:'sphere', size:[d,d,d], pos:pos, mass:2, friction:1, restitution:1, angular:0.1 }); break;
case 2 : physic.add({ type:'cylinder', size:[d,h,d], rot:rot, pos:pos, mass:2, friction:1, rolling:0.3, angular:0.1 }); break;
case 3 : physic.add({ type:'cone', size:[d,h,d], pos:pos, mass:2, friction:1, rolling:0.3, angular:0.1 }); break;
case 4 : physic.add({ type:'capsule', size:[d,h*0.5,d], rot:rot, pos:pos, mass:2, friction:1, rolling:0.3, angular:0.1 }); break;
}
}
}
</script>
</body>
</html>