-1

I'm trying to rotate all sprites in the view port around a central character. I have made some progress, using the following I can get my ship to rotate around the coordinates 0,0, with the radius being the initial placement of the ship. How do I move the point that my ship will revolve around? If I try adding NewPoint to any meaningful screen position the ship buggers off!

    Dim NewPoint As New Vector2
    NewPoint = Vector2.Transform(Ship.Position, Matrix.CreateRotationZ(Ship.ShipAngle))
    Ship.Position = NewPoint
    Ship.RotationValue = Ship.ShipAngle

Thanks for all your help with this folks, I do appreciate it.

3 Answers3

2

You need to:

  1. "Move" the origin - translate the ship by -CenterPos (the position of central character)
  2. Do the desired rotating
  3. Move back translating by CenterPos

tip: automate the process by creating a function like RotateAround(Point)
see any "transformation composition" tutorial for detailed explanation.

wondra
  • 4,920
  • 1
  • 22
  • 36
0

With Many thanks.

        Ship.TransformValue = -0.1
        Ship.ShipAngle = Ship.TransformValue

        Dim LocalPosition As New Vector2(Ship.Position.X - cPosition.X, Ship.Position.Y - cPosition.Y)
        Dim TransormPosition As Vector2 = Vector2.Transform(LocalPosition, Matrix.CreateRotationZ(Ship.ShipAngle))

        Ship.Position = cPosition + TransormPosition

        Ship.RotationValue = Ship.ShipAngle
        Ship.Rotation += Ship.RotationValue
-1

translate your object with the same amount as the difference between the original rotating ankle and the new one, then rotate it.

Let's assume, your object is in 2d space, is 50 pixels wide and high, and you want your new ankle to be in the top left corner, inszead kf in the middle, then you would wanto to translate the object wirh 25 pixels on the x, and 25 pixels om the y axis, then rotate it.

Bálint
  • 14,887
  • 2
  • 34
  • 55
  • Sorry, I think I'm confusing you again. Could you please assume a 2d playing field where my character is centre screen, this character will never move or rotate, everything else will revolve around it. – MuntyScruntFundle Jan 21 '16 at 13:08
  • Then simply rotate every object except the player – Bálint Jan 21 '16 at 13:14
  • Yeah. That's the idea. So how would I set the central rotation point? Sorry if I'm being dim. The above code will revolve a sprite around a central coordinate 0,0. I don't understand how I move the centre point. – MuntyScruntFundle Jan 21 '16 at 13:21
  • Normally, you rotate skmething, then you translate it, now, translate the objwct with a certain amount (move it), then rotate it. – Bálint Jan 21 '16 at 13:23
  • Ok, I'm sat here with a pen and some graph paper!! I have an object revolving around graph coodinate 5,5. So first I have to 'move' my object to a literal position relative to 0,0, perform the transform, then move it back to it's original location+the new translation? – MuntyScruntFundle Jan 21 '16 at 13:47
  • Yes, like that. Imagine it like this: You have a coordinate system, and the object always get rotated around (0; 0), wich is currently at the middle of the sprite. But, if you move your sprite up , so it's center is located at (5; 5), then the coordinate system's origin (0; 0) don't get moved. If you rotate it now, then it still gets rotated around (0; 0). – Bálint Jan 21 '16 at 13:57
  • Ah, I think I know where the confusion is creeping in. Don't worry about the 'Rotation' of the sprite on it's own centre, that's taken care of. Imagine a football in the middle of a field, and a player running around the ball at a 5m radius. It's the player I'm trying to 'revolve' around the ball, but he's currently running around the corner of the field. – MuntyScruntFundle Jan 21 '16 at 14:07
  • Sorry, cross post. I have the idea now, I've just got to play about with it until I get the variables in the right place! Thanks. So far.... :o) – MuntyScruntFundle Jan 21 '16 at 14:30
  • I would really appreciate a mark for best answer if I helped – Bálint Jan 21 '16 at 14:32
  • Ship.TransformValue = -0.1 Ship.ShipAngle = Ship.TransformValue
            Dim LocalPosition As New Vector2(Ship.Position.X - cPosition.X, Ship.Position.Y - cPosition.Y)
            Dim TransormPosition As Vector2 = Vector2.Transform(LocalPosition, Matrix.CreateRotationZ(Ship.ShipAngle))
    
            Ship.Position = cPosition + TransormPosition
    
            Ship.RotationValue = Ship.ShipAngle
            Ship.Rotation += Ship.RotationValue
    
    – MuntyScruntFundle Jan 21 '16 at 14:41