-1
\$\begingroup\$

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.

\$\endgroup\$
1
  • \$\begingroup\$ Yes, because I thought the first post hadn't saved. Bit sniffy here isn't it. \$\endgroup\$ Commented Nov 25, 2016 at 4:40

3 Answers 3

2
\$\begingroup\$

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.

\$\endgroup\$
0
\$\begingroup\$

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
\$\endgroup\$
-1
\$\begingroup\$

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.

\$\endgroup\$
10
  • \$\begingroup\$ 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. \$\endgroup\$ Commented Jan 21, 2016 at 13:08
  • \$\begingroup\$ Then simply rotate every object except the player \$\endgroup\$
    – Bálint
    Commented Jan 21, 2016 at 13:14
  • \$\begingroup\$ 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. \$\endgroup\$ Commented Jan 21, 2016 at 13:21
  • \$\begingroup\$ Normally, you rotate skmething, then you translate it, now, translate the objwct with a certain amount (move it), then rotate it. \$\endgroup\$
    – Bálint
    Commented Jan 21, 2016 at 13:23
  • \$\begingroup\$ 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? \$\endgroup\$ Commented Jan 21, 2016 at 13:47

Not the answer you're looking for? Browse other questions tagged .