水平翻转角度 [英] Flipping an angle horizontally

查看:117
本文介绍了水平翻转角度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道一种无需进行很多操作即可在水平轴上翻转角度的方法.假设我的角度为0(在我的代码的坐标系中为指向右"),则翻转的角度应为180(指向左).如果为90(向上),将其翻转仍应为90.89为91,依此类推. 我可以按角度暗示的X/Y速度进行操作,但这会使事情变慢,我觉得这不是正确的方法. 我不太懂数学,所以我可能用错误的名字称呼事物……有人可以帮忙吗?

I want to know a way to flip an angle in a horizontal axis, without having to do many operations. Say I have an angle of 0 ("pointing right" in my code's coordinate system), the flipped angle should be 180 (pointing left). If 90 (pointing up), flipped it should still be 90. 89 is 91, and so on. I can operate on the X/Y speeds implied by the angle but that would slow things down, and I feel it's not the proper way to go. I don't know much math so I might be calling things by the wrong name...Can anyone help?

对不起,我花了很长时间,我不得不离开计算机很长时间了,好吧... http://img215.imageshack.us/img215/8095/screenshot031v.jpg

Sorry I took long, I had to be out of the computer for long, OK... http://img215.imageshack.us/img215/8095/screenshot031v.jpg

此屏幕截图可能有用.上面的结构是两个卫星和一个链接到中心白点的光束.两颗卫星应该继承白点的角度(为调试目的可见),因此,如果瞄准某个角度,则它们将跟随.左边的卫星是镜像的,因此我按照建议使用180角进行了计算,尽管这也是我的第一次尝试.如您所见,它不是镜像的而是翻转的.当白点旋转时,它会向后旋转.另一个确实可以.

This screenshot might do.The above structure are two satellites and a beam linked to the white dot in the center. The two satellites should inherit the angle of the white dot (it's visible for debug purposes), so if it's aiming at an angle, they will follow. The satellite at the left is mirrored, so I calculated it with 180-angle as suggested, although it was my first try as well. As you can see it is not mirrored but flipped. And when the white dot rotates, it rotates backwards. The other does alright.

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

This is the angle recalculation for something linked to something else, pid would be the parent, and id the current. pin.ang is the angle offset copied when the object is linked to another, so it keeps position when rotated:

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用于使物体偏心旋转,例如光束即将从此处发出,它使其他所有物体都呈现正确的状态.

And this is the specific rotation part. OpenGL. the offx/y is for things rotated off-center, like the beam about to come out there, it renders everything else right.

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

The rotation also seems to miss when the rotation speed (an integer added every redraw to the current angle, positive for rotating clockwise, like in this next one: http://img216.imageshack.us/img216/7/screenshot032ulr.jpg

因此,尽管它看起来多么明显,但绝对不是180度角.通过仅反转纹理坐标即可完成镜像,因此它不会影响角度.恐怕这可能与GL轮换有关.

So it's definitely not 180-angle, despite how obvious it'd be. The mirroring is done by just reversing the texture coordinates so it doesn't affect angle. I am afraid it might be a quirk on the GL rotation thing.

推荐答案

反射量(仅看数学即可)为(180 - angle)

The reflected amount (just looking at the maths) would be (180 - angle)

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

请注意底片是否落在水平平面"以下-您可以将其保留原样,也可以作为特殊情况处理.

Note the negatives if you fall below the "horizontal plane" - which you could leave as they are, or handle as a special case.

这篇关于水平翻转角度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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