From 2cc3f4d0cf710c51a6f324de53b3d8bdd42dc103 Mon Sep 17 00:00:00 2001 From: bluesaxman Date: Thu, 10 Feb 2022 10:34:16 -0700 Subject: [PATCH] after intensive tests, fixed rotation --- libs/bluepixle.js | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/libs/bluepixle.js b/libs/bluepixle.js index 404948a..ee61de3 100644 --- a/libs/bluepixle.js +++ b/libs/bluepixle.js @@ -45,9 +45,9 @@ class shape { var origRot = this.rotation.getRadAngle() + (rotation instanceof vector ? rotation : new vector([0,1])).getRadAngle(); var center = origin.add(this.dimentions.mag(0.5)); // Rotate - ctx.translate(center.d[0],center.d[1]); + ctx.translate(origin.d[0],origin.d[1]); ctx.rotate(origRot); - ctx.translate(-center.d[0],-center.d[1]); + ctx.translate(-origin.d[0],-origin.d[1]); // Draw ctx.fillStyle = this.fcolor; ctx.strokeStyle = this.bColor; @@ -67,9 +67,9 @@ class shape { }); } // restore context defaults - ctx.translate(center.d[0],center.d[1]); + ctx.translate(origin.d[0],origin.d[1]); ctx.rotate(-origRot); - ctx.translate(-center.d[0],-center.d[1]); + ctx.translate(-origin.d[0],-origin.d[1]); ctx.fillStyle = local.fillStyle; ctx.strokeStyle = local.strokeStyle; @@ -86,7 +86,7 @@ class container { constructor(coordinates,dimentions,rotation) { this.coordinates = coordinates instanceof vector ? coordinates : new vector([0,0]); this.size = dimentions instanceof vector ? dimentions : new vector([1,1]); - this.rotation = rotation instanceof vector ? rotation : new vector([0,1]); + this.rotation = rotation instanceof vector ? rotation : new vector([1,0]); this.movementVector = new vector([0,0]); this.shapes = []; this.containers = []; @@ -115,22 +115,23 @@ class container { renderContainer(ctx,position,rotation) { position = position instanceof vector ? position : new vector([0,0]); - rotation = rotation instanceof vector ? rotation : new vector([0,1]); + rotation = rotation instanceof vector ? rotation : new vector([1,0]); var refPos = this.coordinates.add(position); - var refRot = rad2vec(this.rotation.getRadAngle() + (rotation instanceof vector ? rotation : new vector([0,1])).getRadAngle()); + var refRot = rad2vec(this.rotation.getRadAngle() + (rotation instanceof vector ? rotation : new vector([1,0])).getRadAngle()); var center = refPos.add(this.size.mag(0.5)); - ctx.translate(center.d[0],center.d[1]); + ctx.translate(refPos.d[0],refPos.d[1]); ctx.rotate(refRot.getRadAngle()); - ctx.translate(-center.d[0],-center.d[1]); + ctx.translate(-refPos.d[0],-refPos.d[1]); if (this.shapes.length) { - this.shapes.forEach(shape => shape.render(ctx,refPos,refRot)); + this.shapes.forEach(shape => shape.render(ctx,refPos,rotation)); } + if (this.containers.length) { - this.containers.forEach(cont => cont.renderContainer(ctx,refPos,refRot)); + this.containers.forEach(cont => cont.renderContainer(ctx,refPos,rotation)); } - ctx.translate(center.d[0],center.d[1]); + ctx.translate(refPos.d[0],refPos.d[1]); ctx.rotate(-refRot.getRadAngle()); - ctx.translate(-center.d[0],-center.d[1]); + ctx.translate(-refPos.d[0],-refPos.d[1]); } grow(amp) {