![]() ![]() Vector2 center = CenterOfPolygon(vertices) Public Polygon(Vector2 vertices, Vector2 position) / The position, in world space, around which the polygon should be centered. / An array of Vector2 positions defining the vertices of the polygon. / Create a polygon defined by, centered around. Here’s my code in case anyone else wants to do this same thing: class Polygon That’s exactly what I ended up going with! Thanks! Those are just my ideas though… and all assuming I’ve understood what you want to do correctly Personally I’d recommend the first approach, but it’s up to you. This keeps the vertex storage combined to a single array however, there will likely be cascading small errors that will add up over time. ![]() Then, when you want to rotate by 90 degrees, rotate by -45 degrees, then rotate by 90 degrees. So, if your points initialize to 0 degrees rotation, then you want to rotate by 45 degrees, rotate by negative 0 (ie, nothing) and then rotate by 45 degrees. Whenever you rotate, first rotate by the negative of the previous rotation, then rotate by the new rotation.You could also just store two arrays in your polygon class… original vertices and transformed vertices. This will probably give you the most accurate rotation, but you’ll increase your memory allocations (probably not a big deal). This way you can request a rotation of whatever you want. Instead, write a method that requests an array of rotated points while the original remains intact. Don’t update your original points with the new rotation.If I’ve understood this correctly, I can think of two options… Then say rotate to 90 degrees, and it does… instead of rotating to 135, which would be the sum of those two rotations? I’m not sure if I’ve understood this correctly, but you want to have your polygon to go any specified rotation and not incremented, right? So you want to say, rotate to 45 degrees, and it does. Polygon class with this problem solved here: I want to be able to just sayĬurrentAngle = MathHelper.ToRadians(degreesRotation) Īnd just have the polygon pointing in that direction. ![]() Vertices = Vector2.Transform(Vertices, transformMatrix) īut 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). Matrix.CreateTranslation(Center.X - Position.X, Center.Y - Position.X, 0.0f) įor (int i = 0 i < Vertices.Length i++) transformMatrix = Matrix.CreateTranslation(-Center.X + Position.X, -Center.Y + Position.Y, 0.0f) * What I have at the moment is this, where position is the desired position of the polygon on screen. 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? With the centre of mass at the red circle. Say I have a 2D polygon with 5 sides which I’ve defined like this: Vertices = new Vector2 ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |