Fire ball from direction cannon pointing wp7

Topics: Developer Forum
Feb 20, 2013 at 2:06 PM
I have a Cannon located bottom right of screen that the angle can be altered by dragging up and down on the screen. What I want is the vector2 position of the end of the cannon. Then I can fire the ball from bottom right of screen in the direction the cannon is pointing.

I can do this if I capture where the user touches the screen:
Vector2 direction = new Vector2();
direction = newPos - oldPos;
direction.Normalize();
bouncingBall.farseerRectangle.ApplyForce(direction * 20);
But I need to know where the end of the cannon is not its centre point.

Thanks
Coordinator
Feb 24, 2013 at 2:30 AM
Edited Feb 24, 2013 at 2:31 AM
This has nothing to do with Farseer Physics. It is a basic part of vector math.

You already have the center of the cannon, and you have the angle. You can extend a vector that starts at the center of the body and angle of the body, with half the length of the cannon.

One way of doing it is:

1.5f is half the length of the cannon. This moves the point from the center to the end of the cannon.
Vector2 point = body.Position + new Vector2(1.5f, 0);
Matrix matrix = Matrix.CreateRotationZ(body.Rotation);
Rotate the point to have the same angle as the body.
Vector2.Transform(ref point, ref matrix, out point);