LibGDX Angle/Rotation 问题

LibGDX Angle/Rotation Issue

我正在使用 Tiled map editor to create a simple tiled map. Within my map I have several rectangles, if I create a rectangle with a width of 50 and height of 10 and rotate it exactly 90°, save the map and load it up in my LibGDX 项目,形状渲染正确 - 但是如果我使用随机角度,例如 26°,我再次渲染地图,我没有得到想要的结果,实际上我得到了 exact 相反的所需角度。

我正在使用以下方法直接从地图读取平铺地图浮动:

 Map map = new TmxMapLoader().load(mapLocation + mapName + mapExtension);
 for (MapLayer mapLayer : map.getLayers()) {
     for (MapObject mapObject : mapLayer.getObjects() {
          MapProperties objectProperties = mapObject.getProperties();

          float objectRotation = objectProperties.get("rotation") != null ? Float.parseFloat(objectProperties.get("rotation").toString)) : 0.0f;
          objectRotation = MathUtils.degRad * objectRotation;
     }
 }

MathUtils.degRad 将从地图属性中直接读取的度数转换为弧度,但在线的某处发生了误读,或者我完全错过了一些东西。

稍后,我创建 bodyDef 并使用 bodyDef.angle = objectRotation 将其角度设置为上述 objectRotation,然后使用默认值创建我的 body。

你少了点数学知识。

MathUtils.cosDeg( angleInDegrees ) MathUtils.sinDeg ( angleInDegrees )