javascript - p5.js how to translate along axes after rotate -


after rotated coordinates system translating along new axes. somehow possible translate along axes before rotation?

idea user uploads image , can rotate it, zoom , move around middle of viewport. somehow failt o achive of functions ta once.

any suggestions?

edit

i.e. there canvas. draw image there. rotate 90° , want translate on x axis. moves down screen. because axes turned around.

edit

here code snippet use transformation. image rotated in it's (0,0) point. why translate in way rotatet in middle point. afterwards draw image in offset point.

    p.push();         p.translate(canvaswidth/2, canvasheight/2);         p.rotate(angle * p.two_pi/360);          var x = -loadedimage.width/2  - offsetx;         var y = -loadedimage.height/2 - offsety;          p.image(loadedimage, x, y);     p.pop(); 

edit

i decied translate first, , rotate. makes translating correct rotates around wrong pivot point. can't have guess.

var c = document.getelementbyid("mycanvas"); var ctx = c.getcontext("2d"); ctx.save(); ctx.fillstyle="red"; ctx.translate(100,0); ctx.rotate(20 * math.pi / 180); ctx.fillrect(0, 0, 100, 50); ctx.restore(); ctx.fillrect(100,0,50,50); 

try code:use drawimage instead of fillrect in code


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

jquery - javascript onscroll fade same class but with different div -