3

我想知道一种在水平轴上翻转角度的方法,而不必做很多操作。假设我的角度为 0(在我的代码坐标系中“指向右侧”),翻转角度应为 180(指向左侧)。如果是 90(向上),翻转它应该仍然是 90。89 是 91,依此类推。我可以对角度所暗示的 X/Y 速度进行操作,但这会减慢速度,而且我觉得这不是正确的方法。我不太懂数学,所以我可能会用错误的名字来称呼事物......有人可以帮忙吗?

编辑:对不起,我花了很长时间,我不得不长时间离开电脑,好的... http://img215.imageshack.us/img215/8095/screenshot031v.jpg

这个截图可能会。上面的结构是两颗卫星和一个连接到中心白点的光束。两颗卫星应该继承白点的角度(为了调试目的它是可见的),所以如果它瞄准一个角度,它们就会跟随。左边的卫星是镜像的,所以我按照建议用 180 角计算它,虽然这也是我第一次尝试。如您所见,它不是镜像而是翻转的。当白点旋转时,它会向后旋转。另一个没问题。

这是与其他事物相关联的事物的角度重新计算,pid 将是父项,id 是当前的。pin.ang 是当对象链接到另一个对象时复制的角度偏移量,因此它在旋转时保持位置:

if(object[id].mirror)
    object[id].angle = 180 - (object[id].pin.ang + object[pid].angle);
else
    object[id].angle = object[id].pin.ang + object[pid].angle;

这是具体的旋转部分。OpenGL。offx/y 用于偏离中心旋转的事物,例如即将出现的光束,它使其他一切都正确。

glTranslatef(list[index[i]].x, list[index[i]].y, 0);
glRotatef(list[index[i]].angle, 0.0, 0.0, 1.0);
glTranslatef(list[index[i]].offx, -list[index[i]].offy, 0);

当旋转速度(每次重绘到当前角度添加一个整数,顺时针旋转为正值时,旋转似乎也丢失了,如下一个:http: //img216.imageshack.us/img216/7/screenshot032ulr.jpg

所以它绝对不是 180 度角,尽管它有多么明显。镜像是通过反转纹理坐标来完成的,因此它不会影响角度。恐怕这可能是 GL 轮换的一个怪癖。

4

7 回答 7

12

反映的数量(只看数学)将是(180 - angle)

Angle | Reflection
------+-----------
    0 |        180
   90 |         90
   89 |         91
   91 |         89
  360 |       -180
  270 |        -90

如果您低于“水平平面”,请注意负面因素 - 您可以保持原样,或者作为特殊情况处理。

于 2009-09-03T07:06:30.013 回答
3

是不是很简单

结果 = 180-(你的角度)

于 2009-09-03T07:10:18.723 回答
2

As already explained, you find the opposite angle by subtracting your angle from 180 degrees. Eg:

180 - yourangle

Directly manipulating the X/Y speeds would not be very cumbersome. You simply reverse the direction of the X speed, by multiplying it by minus 1, example: speedx = (-1) * speedx. This would change the left-right direction, eg: something moving to the left would start moving to the right, and vice versa, and the vertical speed would be unaffected.

If you're using sine/cosine (sin/cos) to recalculate your X/Y speed components, then the *(-1) method would probably be more efficient. Ultimately it depends on the context of your program. If you're looking for a better solution, update your question with more details.

于 2009-09-03T07:53:48.963 回答
2

此解决方案适用于 -Y 方向的角度(如手表)!对于 +X 方向(如学校数学),您需要交换 X 和 Y。

public static float FlipAngleX(float angle)
{
    angle = NormalizeAngle(angle);

    angle = TwoPi - angle;

    return angle;
}

public static float FlipAngleY(float angle)
{
    angle = NormalizeAngle(angle);

    if (angle < Pi)
    {
        angle = Pi - angle;
    }
    else
    {
        angle = TwoPi - angle + Pi;
    }
    return angle;
}

/// <summary>
/// Keeps angle between 0 - Two Pi
/// </summary>
public static float NormalizeAngle(float angle)
{
    if (angle < 0)
    {
        int backRevolutions = (int)(-angle / TwoPi);
        return angle + TwoPi * (backRevolutions + 1);
    }
    else
    {
        return angle % TwoPi;
    }
}
于 2019-01-10T13:41:56.377 回答
0

啊,看来问题毕竟来自负数,我确保它们是正数,现在旋转很好,我什至不需要重新计算角度......感谢大家,我最终弄清楚了回复。

于 2009-09-03T19:01:25.133 回答
0

逆时针翻转到顺时针(右侧 270 -> 右侧 90)

angle - 360

--

垂直翻转(顶部 180 -> 顶部 0/360)

Math.Normalize(angle - 180)

--

两个都:

float flipped_vertical = angle - 360 float flipped_vertical_and_horizontal = Math.Normalize(flipped_vertical- 180)

于 2018-12-28T03:34:26.113 回答
-1

只会360-angle水平翻转你的角度,但不会垂直翻转

于 2016-08-07T16:23:16.240 回答