好吧,直截了当,我正在使用 SDL 和 openGL 以及 lua 脚本编写 C++ 游戏引擎,我需要使用此 lua 代码获取模拟摇杆的角度以确定 2d 枪的方向
playerLookArrow.rotation = math.atan(logic:controllerAxisForce(3)/-logic:controllerAxisForce(4))
逻辑:controllerAxisForce(int AXIS) 返回
SDL_JoystickGetAxis(Joystick, AXIS);
问题是我的枪只会指向左边,而不是左右。
最佳答案
您应该使用 math.atan2 为您执行此逻辑 (http://www.lua.org/manual/5.1/manual.html#pdf-math.atan2):
playerLookArrow.rotation = math.atan2(
logic:controllerAxisForce(3),
-logic:controllerAxisForce(4))
请注意,返回值以弧度为单位(180 deg = Pi rad)并且 Pi 是 3.141592,不是 3.1 :)
关于c++ - Xbox360 模拟摇杆角度 SDL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22392840/