Say I have a 2D polygon with 5 sides which I’ve defined like this:
Vertices = new Vector2[5]
{
new Vector2(140, 100),
new Vector2(250, 50),
new Vector2(450, 80),
new Vector2(550, 240),
new Vector2(200, 190)
}
Which looks like this:
With the centre of mass at the red circle. Assuming that the rotation of the polygon as it’s initialised is 0.0f radians and I want to rotate it around the COM to X radians… How do I do that?
What I have at the moment is this, where position
is the desired position of the polygon on screen.
transformMatrix = Matrix.CreateTranslation(-Center.X + Position.X, -Center.Y + Position.Y, 0.0f) *
Matrix.CreateRotationZ(currentAngle) *
Matrix.CreateTranslation(Center.X - Position.X, Center.Y - Position.X, 0.0f);
for (int i = 0; i < Vertices.Length; i++)
{
Vertices[i] = Vector2.Transform(Vertices[i], transformMatrix);
}
But I don’t want to treat currentAngle
as a relative rotation (If I run this code in the update at the moment, it just spins in place with the angle incremented by currentAngle
). I want to be able to just say
currentAngle = MathHelper.ToRadians(degreesRotation);
And just have the polygon pointing in that direction. Or do:
currentAngle += 0.01f;
in the update and have it spin place.
How do I go about achieving that?
EDIT:
Polygon class with this problem solved here: