Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var loadingBack;
- var canvas;
- var engine;
- var scene;
- var main;
- var catMesh = null;
- var vectorX = 0, vectorY = 0, vectorZ = 0;
- var mainObjectBox;
- var doPoll = function() {
- $.ajax({
- url : "/orientation/getdata",
- type: "POST",
- dataType: 'json',
- success: function(data, textStatus, jqXHR)
- {
- vectorX = data.vectorX;
- vectorY = data.vectorY;
- vectorZ = data.vectorZ;
- },
- error: function (jqXHR, textStatus, errorThrown)
- {
- console.log(textStatus);
- }
- });
- setTimeout(doPoll, 10);
- }
- window.onload = function () {
- console.log("onload is called");
- loadingBack = document.getElementById("loadingBack");
- canvas = document.getElementById("renderCanvas");
- engine = new BABYLON.Engine(canvas, true);
- doPoll();
- main();
- };
- var main = function () {
- var loadScene = function (name, incremental, then, scene) {
- sceneChecked = false;
- var restoreUI = function () {
- };
- // Loading
- var importScene = function () {
- loadingBack.removeEventListener("transitionend", importScene);
- loadingBack.removeEventListener("webkitTransitionend", importScene);
- engine.resize();
- scene = CreatePhysicsScene(engine, scene, catMesh);
- scene.collisionsEnabled = true;
- scene.executeWhenReady(function () {
- if (scene.activeCamera) {
- scene.activeCamera.attachControl(canvas);
- if (then) {
- then();
- }
- }
- // UI
- restoreUI();
- });
- return;
- };
- importScene();
- };
- var doIt = false;
- // Render loop
- var renderFunction = function () {
- // Render scene
- if (scene) {
- if (doIt) {
- mainObjectBox.applyImpulse(new BABYLON.Vector3(-vectorY, vectorZ, vectorX), new BABYLON.Vector3(0, 0, 0));
- vectorX = 0;
- vectorY = 0;
- vectorZ = 0;
- doIt = false;
- }
- scene.render();
- }
- };
- var scene = new BABYLON.Scene(engine);
- scene.registerBeforeRender(function() {
- if (vectorX != 0 || vectorY != 0 || vectorZ!=0) {
- console.log("impulse X:" + vectorX);
- console.log("impulse Y:" + vectorY);
- console.log("impulse Z:" + vectorZ);
- console.log(mainObjectBox);
- mainObjectBox.position.x = 0;
- mainObjectBox.position.y = 0;
- mainObjectBox.position.z = 0;
- /*mainObjectBox.position.y = -0;
- mainObjectBox.position.z = -25;*/
- doIt = true;
- } else {
- //console.log(mainObjectBox.position.x);
- mainObjectBox.position.x = mainObjectBox.position.x + 100;
- }
- });
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement