鼠标在旋转场景上的位置

时间:2018-05-20 18:44:30

标签: javascript rotation position mouse relative

我在javascript编写了一个游戏引擎,我试图在旋转的场景中获取鼠标位置。

我已经在场景中拥有相对鼠标位置。

mouse2X = mouseX+cameraX;
mouse2Y = mouseY+cameraY;

但是当我旋转整个关卡时,坐标开始出错了。

所以我想知道如何在旋转的场景中获得鼠标位置?

Example of my engine with the current problem.

编辑:

当我们停留在0,0

时,这是有效的
            var rad = VE.toRad(VE.canvas.angle+90);

            var c = Math.sin(rad);
            var s = Math.cos(rad);

            var x = VE.mouseX+VE.cameraX;
            var y = VE.mouseY+VE.cameraY;

            VE.mouse2X = (x*c - y*s);
            VE.mouse2Y = (x*s + y*c);

0 个答案:

没有答案
相关问题