   i need to point a gun texture to a mouse position how do i do this?
  here is what i need:(My Explanation :D)Here is my code:using System;using System.Collections.Generic;using System.Linq;using Microsoft.Xna.Framework;using Microsoft.Xna.Framework.Audio;using Microsoft.Xna.Framework.Content;using Microsoft.Xna.Framework.GamerServices;using Microsoft.Xna.Framework.Graphics;using Microsoft.Xna.Framework.Input;using Microsoft.Xna.Framework.Media;using Microsoft.Xna.Framework.Net;using Microsoft.Xna.Framework.Storage;namespace WindowsGame2{    /// <summary>    /// This is the main type for your game    /// </summary>    public class Game1 : Microsoft.Xna.Framework.Game    {   GraphicsDeviceManager graphics;   SpriteBatch spriteBatch;   Texture2D gun;   Vector2 GunPosition;   float GunRotation;   Vector2 direction;   MouseState mState;   public Game1()   {  graphics = new GraphicsDeviceManager(this);  Content.RootDirectory = "Content";   }   /// <summary>   /// Allows the game to perform any initialization it needs to before starting to run.   /// This is where it can query for any required services and load any non-graphic   /// related content.  Calling base.Initialize will enumerate through any components   /// and initialize them as well.   /// </summary>   protected override void Initialize()   {  // TODO: Add your initialization logic here  base.Initialize();  this.IsMouseVisible = true;   }   /// <summary>   /// LoadContent will be called once per game and is the place to load   /// all of your content.   /// </summary>   protected override void LoadContent()   {  // Create a new SpriteBatch, which can be used to draw textures.  spriteBatch = new SpriteBatch(GraphicsDevice);  gun = Content.Load<Texture2D>("gun");  GunPosition = new Vector2(GraphicsDevice.Viewport.Width / 2, GraphicsDevice.Viewport.Height / 2);  GunRotation = 0.0f;  Mouse.SetPosition(GraphicsDevice.Viewport.Width / 2 + gun.Width, GraphicsDevice.Viewport.Height / 2);  // TODO: use this.Content to load your game content here   }   /// <summary>   /// UnloadContent will be called once per game and is the place to unload   /// all content.   /// </summary>   protected override void UnloadContent()   {  // TODO: Unload any non ContentManager content here   }   /// <summary>   /// Allows the game to run logic such as updating the world,   /// checking for collisions, gathering input, and playing audio.   /// </summary>   /// <param name="gameTime">Provides a snapshot of timing values.</param>   protected override void Update(GameTime gameTime)   {  // Allows the game to exit  if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed) this.Exit();  // TODO: Add your update logic here    mState = Mouse.GetState();  Vector2 mousePos = new Vector2(mState.X, mState.Y);  //option 1  direction = GunPosition - mousePos;  direction.Normalize();  GunRotation = (float)Math.Atan2(direction.X, direction.Y);  //option 2  //float arg1 = (float)(GunPosition.Y + (gun.Height / 2)) - (float)mousePos.Y;  //float arg2 = (float)(GunPosition.X + (gun.Width / 2)) - (float)mousePos.X;  //GunRotation = (float)(Math.Atan2(arg1, arg2));  base.Update(gameTime);   }   /// <summary>   /// This is called when the game should draw itself.   /// </summary>   /// <param name="gameTime">Provides a snapshot of timing values.</param>   protected override void Draw(GameTime gameTime)   {  GraphicsDevice.Clear(Color.CornflowerBlue);  // TODO: Add your drawing code here  spriteBatch.Begin();  spriteBatch.Draw(gun, GunPosition, null, Color.White, GunRotation, new Vector2(7, 35), 1f, SpriteEffects.None, 0f);  spriteBatch.End();  base.Draw(gameTime);   }    }}But The Mouse Doesnt Rotate AccuratelyCan Someone Tell Me What Is Wrong?Thanks in advance   
  Hey, im sorry. I dont have the answer to your problem, but you might find more help instead of the beginners, taking it to the directx/xna part of the forum.   ;Vector2 displacement = mousePosition - weaponPosition;weaponAngle = Math.Atan2(displacement.Y, displacement.X);EDIT: Ok I didn't read your source.  I think option 1, with the weapon position subtracted from the mouse, instead of vice versa, and don't normalize it.   ;  some one?   ;  Without reading too much of your code (I just woke up), I'm guessing the problem is that when your gun is at rest(rotated 0 degrees) it is pointing to the right, whereas at 0 degrees you'd want it to be aiming "up". So you'll need to take that into account when rotating the image, otherwise you'll end up with incorrect results. (unless of course there's something else I'm missing here)btw, it would be more helpful for both of us if you explained more accurately what the problem was, i.e. is the rotation completely incorrect, does it only work in special cases etc.   ;  here are some pictures of my example (the black dot is the mouse position):good:good:wrong:you see- except for two points in the rotate that are show to be correct all the other points are wrong   ;  First off, it's important to understand exactly what results you should expect from atan2. The illustration at http://en.wikipedia.org/wiki/Atan2 is a good reference. More importantly, remember that atan2() expects its arguments to be given as (y,x), NOT the opposite as you are doing in the Option 1 part of your code. By looking at the pictures you provided, this seems to be what's causing the problem, as it's basically only working when x is about the same as y (like in the two first images). In the third image showing the incorrect result, lets assume that x is -1 and y is +1. If you call atan2 correctly(with the y,x order), you'd get ~135 degrees(I'll use degrees for clarity), which is what you want. However with the parameters reversed, you'd get an incorrect result of around -45 degrees (which incidentally, is about the amount your gun is rotated in image 3).Hope this helps.   