使用弧度翻转角度
各位数学高手大家好!
我正在努力解决一道数学问题,希望你能帮助我。我使用弧度计算了方向角。在 OpenGL ES 中,我通过改变我的点值来移动我的家伙:
spriteLocation.x -= playerSpeed * cosf(playerRadAngle);
spriteLocation.y -= playerSpeed * sinf(playerRadAngle);
// playerRadAgnle is my angle of direction using radians
这对于将我的精灵向正确的方向移动非常有效。然而,我决定将我的精灵“锁定”在屏幕中间,并移动背景。这需要我反转我计算的角度。如果我的精灵的方向(以弧度表示)相当于 90 度,我想将其转换为 270 度。再次强调,一切都以弧度表示。
我承认我对三角函数的了解充其量是很贫乏的。有没有办法用弧度算出对角?我知道我可以将弧度转换为度数,然后加/减 180 度,然后转换回弧度,但我正在寻找更有效的方法。
预先感谢...-
斯科特
Hello all you math whizzes out there!
I am struggling with a math problem I am hoping you can help me with. I have calculated an angle of direction using radians. Within OpenGL ES I move my guy by changing my point value as such:
spriteLocation.x -= playerSpeed * cosf(playerRadAngle);
spriteLocation.y -= playerSpeed * sinf(playerRadAngle);
// playerRadAgnle is my angle of direction using radians
This works very well to move my sprite in the correct direction. However, I have decided to keep my sprite "locked" in the middle of the screen and move the background instead. This requires me to Reverse my calculated angle. If my sprite's direction in radians is equivalent to 90 degrees, I want to convert it to 270 degrees. Again, keeping everything in radians.
I will admit that my knowledge of Trig is poor at best. Is there a way to figure out the opposite angle using radians? I know I could convert my radians into degrees, then add/subtract 180 degrees, then convert back to radians, but I'm looking for something more efficient.
Thanks in advance....
-Scott
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
加/减
pi
即可。Add/subtract
pi
instead.您需要添加 Pi,然后使用除以 2 Pi 后的余数(使其限制在
[0; 2 Pi]
范围内)。JavaScript:
You need to add Pi and then use the remainder after division by 2 Pi (to make it restricted within
[0; 2 Pi]
range).JavaScript:
object_sprite.rotation = warp_direction - 3.14;
object_sprite.rotation = warp_direction - 3.14;