Right way to rotate things with a mouse in Fabric.js

后端 未结 1 1801
滥情空心
滥情空心 2021-02-08 14:40

This is the example:
http://jsbin.com/UHENoKi/11/

Here I use simple formula to find the angle between two points (vectors):

1条回答
  •  傲寒
    傲寒 (楼主)
    2021-02-08 15:24

    The angle to rotate by is being calculated based on the 0,0 origin, but the square is rotating around its own center at 100, 100, so they don't match. If you move the square to 0,0, it feels OK:

    var rect = new fabric.Rect({
      fill: '#00FFAB', 
      top: 0, 
      left: 0, 
      width: 100, 
      height: 100, 
      selectable: false
    });
    

    Rather than translating to canvas coordinates in toLocal, translate into the coordinate space of the square.

    0 讨论(0)
提交回复
热议问题