I have a projecile(Hook) and the tail of the projectile(yellow balls)
TailProjectile
class draws a ball at the exact position of the projectile(hook) and let it there until the projectile ends
I'd like to draw the ball at the start of the hook(red circle) because by now it draws at the projectile image position(blue point)
How can I do it independent of the rotation of the hook?
This is how I calculate the rotation of the projectile
distanceY = endPosition.Y - initialPosition.Y;
distanceX = endPosition.X - initialPosition.X;
if (distanceX < 0)
animation.SprtEffects = SpriteEffects.FlipVertically;
animation.Rotation = (float)Math.Atan2(distanceY, distanceX);
Then I pass the projectile to the tail and draw the ball
if (hasTail)
tail.Update(gameTime, position , animation.Rotation,animation.SprtEffects);
And at the TailProjectile update class :
public void Update(GameTime gameTime,Vector2 p,float rotation,SpriteEffects sprtEffect)
{
if (Vector2.Distance(animations[animations.Count - 1].Position, p) > distanceBetween)
{
Animation tempAnimation = new Animation();
tempAnimation.LoadContent(content, image, "", p);
tempAnimation.Rotation = rotation;
tempAnimation.SprtEffects = sprtEffect;
tempAnimation.DrawColor = color;
animations.Add(tempAnimation);
}
And the Animation Draw:
spriteBatch.Draw(image, position + origin, sourcRect, drawColor * alpha, rotation, origin, scale, sprtEffects, 0.0f);
Edit: Using rotation matrix solve half of the problem :
My problem now is how can I calculate it for angles higher than 90º ? (third picture of the image)
double xO, yO;
xO = originpoint.X * Math.Cos(rotation) - originpoint.Y * Math.Sin(rotation);
yO = originpoint.X * Math.Sin(rotation) + originpoint.Y * Math.Cos(rotation);
initialAnimation.Position = new Vector2((float)xO + initialAnimation.Position.X, (float)yO + initialAnimation.Position.Y);