I have a set of 2D coordinates. Their positions are regular on the X axis, but unpredictable on the Y axis:
I would like to create slim platform between each point in order tu use it as ground for my game, expecting a result like this:
I'm working with Box2D, so I thought about create boxes like this:
float x1, y1, x2, y2; // Coordinates between two points
float centerX, centerY;
float differenceX, differenceY;
float width;
b2BodyDef bodyDef;
b2Body* body;
b2PolygonShape shape;
centerX = (x1 + x2) / 2.0;
centerY = (y1 + y2) / 2.0;
differenceX = x2 - x1;
differenceY = y2 - y1;
width = sqrtf(differenceX * differenceX + differenceY * differenceY);
height = 10.0f
bodyDef.position.Set(centerX, centerY);
bodyDef.angle = -M_PI / 4.0f * width / height
body = world.CreateBody(&bodyDef);
shape.SetAsBox(width, 10.0f);
body->CreateFixture(&box, 0.0f);
But the wrong part of this code seems to be on angle. I cannot find the correct rotation between two points from their coordinates.
Is there a correct math formula to find it?
Or am I simply wrong to use rectangular boxes to trace it, and should I use something else? Like a b2PolygonShape
?