I have a rigid body, it have a world position and rotation.
The rigid body may have multiple shapes, each shape may have a local rotation and offset.
Maybe one shape is a polygon and another is a circle - so its a combined thing.
Each of that has its local offset to some extend - so that its not on the body center anymore.
When i for example want to draw a polygon in world space with all the transformation applied i do it like this:
Mat2f localRotation(0.05f);
Vec2f localOffset(100, 0);
Mat2f worldRotation(0.15f);
Vec2f worldPosition(0, 0);
for (int i = 0; i < numVerts; i++) {
v2 p0 = (V2(localVertices[i]) * localRotation + localOffset) * worldRotation + worldPosition;
v2 p1 = (V2(localVertices[i < numVerts - 1 ? i + 1 : 0]) * localRotation + localOffset) * worldRotation + worldPosition;
drawLine(p0, p1);
}
But what about circle shapes? They will change the position when the local offset is not zero.
//Mat2f localRotation(0f); // Circles dont have a local rotation at all
Vec2f localOffset(-100, 0);
Mat2f worldRotation(0.15f);
Vec2f worldPosition(0, 0);
Vec2f pos = V2(localOffset) * worldRotation + worldPosition;
drawCircle(pos, radius);
This seems to be a totally different way than the implementation above.
Is there a nice way to change the polygon drawing to use this way - so that it uses a rotated position and of course, includes the vertex rotation as well ?
It must be really easy, but right now i dont see it at all...