XNA 2D 矢量角度 - 正确的计算方法是什么?
在 2D 中的 XNA 中矢量角度的标准工作方式是什么?
向右 0 度,向上 90 度,向左 180 度,向下 270 度?
的“标准”实现是什么
float VectortoAngle(Vector2 vec)
?
Vector2 AngleToVector(float angle)
VectortoAngle(AngleToVector(PI)) == PI
what is in XNA in 2D the standard way vector angles work ?
0 degrees points right, 90 points up, 180 left, 270 down ?
What are the 'standard' implementations of
float VectortoAngle(Vector2 vec)
and
Vector2 AngleToVector(float angle)
so that VectortoAngle(AngleToVector(PI)) == PI ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
要回答你的第一个问题,0 度点向上,90 度点向右,180 度点向下,270 度点向左。 这里是一个简单的 2D XNA 旋转教程,为您提供更多信息。
至于将矢量转换为角度和反向转换,我在此处:
此外,如果您不熟悉 2D 编程,您可能需要研究Torque X 2D< /a>,它为您提供了很多内容。如果您付费开发 XNA,您可以免费获得引擎二进制文件,并且有一个实用程序类可以在角度和矢量之间进行相互转换,以及其他类似的有用函数。
编辑: 正如 Ranieri 在评论中指出的那样,当向上为 0 度时,该函数没有意义。这是一个(上是 (0, -1),右是 (1, 0),下是 (0, 1),左是 (-1, 0):
我还想指出,我一直在使用扭矩一段时间,它使用 0 度向上,所以这就是我得到该部分的地方。向上的意思是,在这种情况下,以与文件中相同的方式将纹理绘制到屏幕上,所以向下将是。颠倒地绘制纹理。
To answer your first question, 0 degrees points up, 90 degrees points right, 180 degrees points down, and 270 degrees points left. Here is a simple 2D XNA rotation tutorial to give you more information.
As for converting vectors to angles and back, I found a couple good implementations here:
Also, if you're new to 2D programming, you may want to look into Torque X 2D, which provides a lot of this for you. If you've payed to develop for XNA you get the engine binaries for free, and there is a utility class which converts from angles to vectors and back, as well as other useful functions like this.
Edit: As Ranieri pointed out in the comments, that function doesn't make sense when up is 0 degrees. Here's one that does (up is (0, -1), right is (1, 0), down is (0, 1), left is (-1, 0):
I would also like to note that I've been using Torque for a while, and it uses 0 degrees for up, so that's where I got that part. Up meaning, in this case, draw the texture to the screen in the same way that it is in the file. So down would be drawing the texture upside down.
XNA 中没有约定某个角度代表哪个方向,因此您可以随意定义它。
我不确定我最后一次在游戏中使用角度是什么时候。几乎在所有情况下,直接使用向量都会更容易,尽管一开始不太直观。
There is no convention for which direction a certain angle represents in XNA, so you can just define it however you like.
I'm not sure when the last time I used angles in a game was. In almost every case it's easier to work directly with vectors, if a little less intuitive to begin with.