1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 function NaClAMBulletInit() {
6 aM.addEventListener('sceneloaded', NaClAMBulletSceneLoadedHandler);
7 aM.addEventListener('noscene', NaClAMBulletStepSceneHandler);
8 aM.addEventListener('sceneupdate', NaClAMBulletStepSceneHandler);
11 function NaClAMBulletLoadScene(sceneDescription) {
12 aM.sendMessage('loadscene', sceneDescription);
15 function NaClAMBulletSceneLoadedHandler(msg) {
16 console.log('Scene loaded.');
17 console.log('Scene object count = ' + msg.header.sceneobjectcount);
20 function NaClAMBulletPickObject(objectTableIndex, cameraPos, hitPos) {
21 aM.sendMessage('pickobject', {index: objectTableIndex, cpos: [cameraPos.x, cameraPos.y, cameraPos.z], pos: [hitPos.x,hitPos.y,hitPos.z]});
24 function NaClAMBulletDropObject() {
25 aM.sendMessage('dropobject', {});
28 // Values used to display simulation time every second.
30 lastTimeMs: +new Date(),
35 function NaClAMBulletStepSceneHandler(msg) {
39 var numTransforms = 0;
40 if (msg.header.cmd == 'sceneupdate') {
41 if (skipSceneUpdates > 0) {
45 TransformBuffer = new Float32Array(msg.frames[0]);
46 numTransforms = TransformBuffer.length/16;
47 for (i = 0; i < numTransforms; i++) {
48 for (j = 0; j < 16; j++) {
49 objects[i].matrixWorld.elements[j] = TransformBuffer[i*16+j];
53 var simTime = msg.header.simtime;
54 fps.sumSimTime += simTime;
58 var curTimeMs = +new Date();
59 if (curTimeMs - fps.lastTimeMs > 1000) { // 1 sec
60 var meanSimTime = fps.sumSimTime / fps.numSteps;
61 $('simulationTime').textContent = meanSimTime.toFixed(0);
62 $('fps').textContent =
63 (fps.numSteps * 1000 / (curTimeMs - fps.lastTimeMs)).toFixed(1);
64 fps.lastTimeMs = curTimeMs;