You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

62 lines
1.0 KiB

class Matrix{
constructor(){
this.a = 1;
this.b = 0;
this.c = 0;
this.d = 1;
this.e = 0;
this.f = 0;
}
applyToPoint(p){
return {
x: round(p.x * this.a + p.y * this.c + this.e),
y: round(p.x * this.b + p.y * this.d + this.f)
}
}
transform(a2, b2, c2, d2, e2, f2){
var a1 = this.a,
b1 = this.b,
c1 = this.c,
d1 = this.d,
e1 = this.e,
f1 = this.f;
this.a = a1 * a2 + c1 * b2;
this.b = b1 * a2 + d1 * b2;
this.c = a1 * c2 + c1 * d2;
this.d = b1 * c2 + d1 * d2;
this.e = a1 * e2 + c1 * f2 + e1;
this.f = b1 * e2 + d1 * f2 + f1;
}
rotate(angle){
var cs = cos(angle),
sn = sin(angle);
this.transform(cs, sn, -sn, cs, 0, 0);
}
}
class Rotation{
constructor(axis, index, dir, v, finishedCallback){
this.axis = axis;
this.index = index;
this.dir = dir;
this.angle = 0;
this.v = v;
this.finished = function(){
finishedCallback();
}
}
update(){
if (abs(this.angle) > PI / 2){
this.finished();
}
this.angle += this.v * this.dir;
}
}