From 308e811c0e770a7f8f11acc48c545b1cc5155130 Mon Sep 17 00:00:00 2001 From: bluesaxman Date: Thu, 10 Feb 2022 08:51:20 -0700 Subject: [PATCH] Hopefully fixed relative rotation in containers. --- libs/bluepixle.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/libs/bluepixle.js b/libs/bluepixle.js index b7a8673..ced7fe6 100644 --- a/libs/bluepixle.js +++ b/libs/bluepixle.js @@ -67,7 +67,10 @@ class shape { }); } // restore context defaults - ctx.setTransform(1,0,0,1,0,0); + ctx.translate(center.d[0],center.d[1]); + ctx.rotate(-origRot); + ctx.translate(-center.d[0],-center.d[1]); + ctx.fillStyle = local.fillStyle; ctx.strokeStyle = local.strokeStyle; ctx.lineWidth = local.lineWidth; @@ -114,13 +117,20 @@ class container { position = position instanceof vector ? position : new vector([0,0]); rotation = rotation instanceof vector ? rotation : new vector([0,1]); var refPos = this.coordinates.add(position); - var refRot = this.rotation.add(rotation); + var refRot = rad2vec(this.rotation.getRadAngle() + (rotation instanceof vector ? rotation : new vector([0,1])).getRadAngle()); + var center = this.refPos.add(this.dimentions.mag(0.5)); + ctx.translate(center.d[0],center.d[1]); + ctx.rotate(refRot.getRadAngle()); + ctx.translate(-center.d[0],-center.d[1]); if (this.shapes.length) { this.shapes.forEach(shape => shape.render(ctx,refPos,refRot)); } if (this.containers.length) { this.containers.forEach(cont => cont.renderContainer(ctx,refPos,refRot)); } + ctx.translate(center.d[0],center.d[1]); + ctx.rotate(-origRot); + ctx.translate(-center.d[0],-center.d[1]); } grow(amp) {