【发布时间】:2014-10-28 22:33:44
【问题描述】:
对于 Haskell 中 Gloss 库的 Rotate 函数,我需要为它提供一个角度,而不是我用于可移动对象的方向矢量,因此我想知道如何转换它?我想我会为此使用 atan2 ,但这给了我一个非常奇怪的结果(应该旋转的图片只旋转一点,然后返回等等,而不是围绕它的原点)。
我尝试的是使用 Gloss Library 中的 Rotate 函数加上 atan2 函数将矢量转换为角度:
Rotate (atan2 (snd dir) (fst dir)) pic
其中 dir 是一个标准化向量,初始为 (1,0),指向图片(在本例中为玩家的船)指向并可能移动的方向。
但是这不能正常工作。
如果有人可以帮助我,将不胜感激!
最好的问候, Skyfe。
【问题讨论】:
-
rotate期望度数,atan2似乎给出弧度。 -
请注意
atan2 (snd dir) (fst dir)是uncurry atan2 dir -
@user2407038:我认为
atan2 (fst dir) (snd dir)是uncurry atan2 dir。请注意,atan2首先采用snd,而不是fst。