-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlog2hud.js
27 lines (23 loc) · 836 Bytes
/
log2hud.js
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
// A-Frame component that logs the position and rotation of an entity to a text element
AFRAME.registerComponent('log2hud', {
schema: {
target: {type: 'string', default: 'chud'}
},
init: function() {
this.hud = document.getElementById(this.data.target);
},
tick: function () {
// var rotation = this.el.getAttribute('rotation'); // angle in degrees
var rotation = this.el.object3D.rotation; // angle in radians
var pos = this.el.object3D.position; // (relative) position in meters
var s = "pos: " + this.toString(pos) + "\nrot: " + this.toString(rotation);
// console.log(s);
this.hud.setAttribute('text', 'value: ' + s);
},
toString: function(pos) {
var x = pos.x.toFixed(1);
var y = pos.y.toFixed(1);
var z = pos.z.toFixed(1);
return [x, y, z].join(" ");
}
})