-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconstraint.js
32 lines (31 loc) · 1.04 KB
/
constraint.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
function DirConstraint(type, object, idp, ids)
{
this.update = function()
{
switch (type) {
case "north":
var angle = object.box.getAngle();
angle = (angle%(Math.PI*2));
if(angle < 0) angle += Math.PI*2;
angle -= Math.PI;
var percent = Math.abs(angle/Math.PI)*100;
document.getElementById(idp).innerHTML = percent.toFixed(0) + "%";
document.getElementById(ids).innerHTML = percent > 95 ? "✔" : "❌";
}
}
}
function ProxiConstraint(ref, nbmin, distmin, check, idp, ids)
{
this.update = function () {
var refpos = ref.box.getPosition();
var done = 0;
for(var obj of check)
{
let dist = (Vec2.clone(obj.box.getPosition()).sub(refpos)).length();
if(dist < distmin)
done++;
}
document.getElementById(idp).innerHTML = done + "/" + nbmin;
document.getElementById(ids).innerHTML = done >= nbmin ? "✔" : "❌";
}
}