简体   繁体   中英

LibGDX Angle/Rotation Issue

I'm using 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 project, the shape is rendered correctly - however if I use a random angle, let's say 26° for example and I render the map again, I do not get the desired result, in fact I get the exact opposite desired angle.

I'm reading the Tiled map float directly from the map using:

 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;
     }
 }

The MathUtils.degRad converts the degrees read directly from the map properties into radians, but somewhere along the line there's a misread happening or I've completely missed something.

Later, I create my bodyDef and set its angle to the above mentioned objectRotation using bodyDef.angle = objectRotation followed by creating my body with default values.

您缺少一些数学知识。

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM