XNA 2D矢量角度 - 什么是来计算正确的方法是什么? [英] XNA 2D vector angles - what's the correct way to calculate?

查看:147
本文介绍了XNA 2D矢量角度 - 什么是来计算正确的方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是XNA在2D的标准方式矢量角度的工作?

what is in XNA in 2D the standard way vector angles work ?

0度的点吧,90点了,180左右,270下跌?

0 degrees points right, 90 points up, 180 left, 270 down ?

什么是标准的实施

float VectortoAngle(Vector2 vec)

Vector2 AngleToVector(float angle)

让VectortoAngle(AngleToVector(PI))== PI?

so that VectortoAngle(AngleToVector(PI)) == PI ?

推荐答案

要回答你的第一个问题,0度指向上方,90度分右,180度指向下方,并留下270度点。 这里是一个简单的2D XNA旋转教程,给你更多的信息。

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:

Vector2 AngleToVector(float angle)
{
    return new Vector2((float)Math.Cos(angle), (float)Math.Sin(angle));
}

float VectorToAngle(Vector2 vector)
{
    return (float)Math.Atan2(vector.Y, vector.X);
}

另外,如果你是新来的2D节目,你可能想看看转矩×2D ,它提供了大量的这个要求。如果你祈祷,为开发XNA你得到的二进制文件引擎是免费的,而且是把从角度矢量和背部一个工具类,以及其他有用的功能是这样的。

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.

编辑:作为拉涅利指出的意见,该功能就没有意义了时为0度。这里是一个没有(最多为(0,-1),右边是(1,0),下降为(0,1),左为(-1,0):

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):

Vector2 AngleToVector(float angle)
{
    return new Vector2((float)Math.Sin(angle), -(float)Math.Cos(angle));
}

float VectorToAngle(Vector2 vector)
{
    return (float)Math.Atan2(vector.X, -vector.Y);
}

我也想指出,我一直在使用扭矩一段时间已经,并使用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 2D矢量角度 - 什么是来计算正确的方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆