围绕一个点旋转图像

时间:2014-04-25 12:35:00

标签: raphael

我试图解决这个问题几个小时,我无法弄清楚我哪里出错了..

在我的页面上有一个图像和一个"选择框"。可以移动和调整此框架的大小。 我试图让图像转动,转弯的中心点是框架的中心。

我在顶部创建了一个小手柄以便旋转。

这里是小提琴:http://jsfiddle.net/8PhqX/7/(加载一分钟)

小提琴中的代码很长,因为我无法隔离与我的问题相关的特定区域。当你玩它时,你会发现第一次旋转通常很好,但是,事情变得疯狂。

这里是轮换的代码行:

//selfRotator.handle.angle is the angle(clockwise) at which the rotation handle was       rotated
//selfSelector.rotator.ox/oy is the position of the middle of the selection frame
//selfDefaults.imageArea.y is the y position of the section with the image (because of the red stripe in the top)
//selfImageArea.page.startX/Y is starting position of the image storing its position when the drag begins
//rotating by angle, at center point of selection
selfImageArea.page.transform(
['r', -selfRotator.handle.angle, selfSelector.rotator.ox - selfImageArea.page.startX,    selfSelector.rotator.oy - (selfImageArea.page.startY - selfDefaults.imageArea.y)]
)
//tracking the image's start position and compensating 
selfImageArea.page.attr({
transform: "...T" + (selfImageArea.page.startX) + "," + (selfImageArea.page.startY - selfDefaults.imageArea.y)
});

由于getBBox值不遵循图片轮廓,因此看起来很混乱。

我已添加网格线来说明问题

另外,我发现这段代码(https://groups.google.com/forum/#!topic/raphaeljs/b8YG8DfI__g)代表了#34; getBBoxRotated()"应该解决我的问题的功能,但我似乎无法实现它。

0 个答案:

没有答案