Reputation: 1620
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.
Upvotes: 0
Views: 326
Reputation:
You're missing a bit of math.
MathUtils.cosDeg( angleInDegrees )
MathUtils.sinDeg ( angleInDegrees )
Upvotes: 1