【发布时间】:2012-10-15 01:40:17
【问题描述】:
我正在尝试为 2D 游戏创建绳索物理,因此作为起点,我有一个小的旋转图像,我需要在其末端添加另一条绳索。不幸的是,当旋转发生在图像的顶部时,我在尝试跟踪图像的底部时遇到了麻烦。我已经设法使用以下代码跟踪图像的 (0,0) 坐标,但我需要能够跟踪点 (32,57)。这是我目前所拥有的:
xr = xm + (xPos - xm) * Math.cos(a) - (yPos - ym) * Math.sin(a);
yr = ym + (xPos - xm) * Math.sin(a) + (yPos - ym) * Math.cos(a);
感谢任何帮助!
编辑:
嘿,我搞定了 =D 使用极坐标比我以前做的任何事情都容易得多。
前 2 个变量保持不变:
theta0 = Math.atan2(y, x);
r = 25;
theta = theta0 + a;
xr = (r * Math.cos(theta)) + xm;
yr = (r * Math.sin(theta)) + ym;
xm 和 ym 是我图像的位置。
【问题讨论】: