blob: 12061c32c6c0d525270592b5c768fc1fb13c138a (
plain)
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
|
<html>
<head>
<title>Bullet/WebGL Demo</title>
<script type="text/javascript" src="glge_math.js"></script>
<script type="text/javascript" src="glge.js"></script>
<script type="text/javascript" src="bullet.js"></script>
<script ty[e="text/javascript" src="bullet_demo.js"></script>
<style type="text/css">
body { background-color: #eee; }
</style>
</head>
<body>
<center>
<canvas id="canvas" width="500" height="500"></canvas>
<script type="text/javascript">
var doc = new GLGE.Document();
doc.onLoad = function() {
prepareBulletDemo();
var boxes = [];
function simulatePhysics(diff) {
simulateBulletDemo(diff);
for (var i = 0; i < 5; i++)
applyBulletObject(boxes[i], readBulletObject(i+1));
}
var renderer = new GLGE.Renderer(document.getElementById("canvas"));
var scene = doc.getElement("mainscene");
renderer.setScene(scene);
var mesh = doc.getElement("Box");
for (var i = 0; i < 5; i++) {
var box = new GLGE.Object('box_' + i);
box.setMesh(mesh);
box.setMaterial(doc.getElement("boxmaterial" + (i%2 == 0 ? 1 : 3)));
box.setId('box_' + i);
box.setLoc(i*2, 10, 0);
box.setScale(1, 1, 1);
scene.addChild(box);
boxes.push(box);
}
var t = Date.now();
var lastHUD = 0;
var diffs = 0, num = 0;
function render() {
var now = Date.now();
var diff = (now - t)/1000;
// Simulate
simulatePhysics(diff);
// Render
renderer.render();
// Show FPS
diffs += diff;
num++;
if (now - lastHUD > 250) {
document.getElementById('out').innerHTML = '<b>FPS:' + Math.ceil(1/(diffs/num)) + '</b>';
lastHUD = now;
diffs = 0;
num = 0;
}
t = now;
}
setInterval(render, 1000/60.);
}
doc.load("http://127.0.0.1:8991/scene.xml");
</script>
<br><br>
<div id="out">waka</div>
</center>
</body>
</html>
|