-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhelpers.js
61 lines (52 loc) · 1.49 KB
/
helpers.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
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
"use strict";
var startTime, started = false;
var maxPlaneY = 200;
var skyColor = '#6AE';
const scene = cam.sceneEl; //document.querySelector('a-scene');
const deg360 = Math.PI*2;
const deg180 = Math.PI;
const deg90 = Math.PI/2;
const deg45 = Math.PI/4;
const oneTurn = deg360;
const halfTurn = deg180;
const quarterTurn = deg90;
var g = {x:1, y:0, z:0};
var fps = 30; // initialization only
var alphaPingeon;
var thePingeon;
var thePingeonWasCatched = false;
var armEndRealPos;
const sin = Math.sin;
const cos = Math.cos;
const abs = Math.abs;
const round = Math.round;
const dbgXYZ = (obj)=> `x:${round(obj.x*10)/10}, y:${round(obj.y*10)/10}, z:${round(obj.z*10)/10}`
const xyzDo = (func)=> ['x','y','z'].forEach((k)=> func(k));
function rnd(a, b) {
if (typeof(b) == 'undefined' || b == null) {
b = a;
a = 0;
}
return (Math.random() * (b-a)) + a;
}
const rRnd = (a, b)=> Math.round(rnd(a, b));
window.mk = function mk(type, attrs, parent) {
var el = document.createElement('a-'+type);
for (var att in attrs) el.setAttribute(att, attrs[att]);
if (parent) parent.appendChild(el);
else scene.appendChild(el);
return el;
}
HTMLElement.prototype.mk = function (type, attrs) {
return mk(type, attrs, this);
}
HTMLElement.prototype.selfRemove = function () {
this.parentNode.removeChild(this);
}
function roundDec(n,d) {
var m = 10**d;
return Math.round(n*m)/m;
}
function debugXYZ(desc, obj, d=3) {
console.log(desc+` x:${roundDec(obj.x,d)} y:${roundDec(obj.y,d)} z:${roundDec(obj.z,d)}`)
}