Free javascript Hosting


ad-example.js

Uploaded on Feb 21 2022 09:02 by ruaronicola

function round(num) {
return Math.round((num + Number.EPSILON) * 100) / 100;
}

function get_log(el, name) {
return name +" x:"+round(el.object3D.position.x)+", y:"+round(el.object3D.position.y)+", z:"+round(el.object3D.position.z);
}

setInterval(function(){
let camera = document.querySelector('[camera]')
let controllers = document.querySelectorAll('[tracked-controls]')

let hud = document.querySelector('a-plane#hud')
if (hud == null) {
<!-- <a-plane id="hud" overlay position="0 0 -0.5" width="0.4" height="0.2" color="black"> -->
hud = document.createElement('a-plane');
hud.setAttribute('id', 'hud');
hud.setAttribute('position', '0 0 -0.5');
hud.setAttribute('width', '0.4');
hud.setAttribute('height', '0.2');
hud.setAttribute('color', 'black');

<!-- <a-text id="hud_text" position="0.01 0 0" align="left" anchor="center" width="0.39" height="0.2" value="Loading tracking data ..."> -->
let hud_text = document.createElement('a-text');
hud_text.setAttribute('id', 'hud_text');
hud_text.setAttribute('position', '0.01 0 0');
hud_text.setAttribute('align', 'left');
hud_text.setAttribute('anchor', 'center');
hud_text.setAttribute('width', '0.39');
hud_text.setAttribute('height', '0.2');
hud_text.setAttribute('value', 'Loading tracking data ...');

hud.appendChild(hud_text);
controllers[0].appendChild(hud);
}

let hud_text = document.querySelector('a-text#hud_text')

let text = get_log(camera, "CAMERA") + "\n" + get_log(controllers[0], "CONTROLLER 1") + "\n" + get_log(controllers[1], "CONTROLLER 2")
hud_text.setAttribute('value', text);
}, 100);

Back to list