XNA Creators Club Online
Page 1 of 1 (7 items)
Sort Posts: Previous Next

Rotation based on mouse

Last post 11/1/2008 11:17 AM by Bigfellahull. 6 replies.
  • 10/31/2008 4:16 AM

    Rotation based on mouse

    Hey all,

    I was wondering if there is a rotation based on mouse sample for a 2D texture. All I've found is 3D and I don't want 3D.

    Thanks,
    Dro Sarhadian
  • 10/31/2008 12:23 PM In reply to

    Re: Rotation based on mouse

    Well that depends, what do you want to rotate how?

    Do you mean that a texture always faces the mouse cursor? Or do you want to rotate something with you mouse wheel?


    Greg the Mad
  • 10/31/2008 1:15 PM In reply to

    Re: Rotation based on mouse

    Like kinda face the mouse texture.
  • 10/31/2008 3:33 PM In reply to

    Re: Rotation based on mouse

    I couldnt get what you really want... Post some code or an example so we can try helping you.
  • 10/31/2008 4:51 PM In reply to

    Re: Rotation based on mouse

    Would this help you? Is a sample based on turning one 2D object to face another one. In your case, the object being turned to would be the mouse cursor.

    http://creators.xna.com/en-US/sample/aiming


  • 10/31/2008 10:35 PM In reply to

    Re: Rotation based on mouse

    The current code I have is the following:

    //Set the Arm Rotation 
    armRotation = mState.X + mState.Y; 
     
    //In Draw Method, draw the arm 
    spriteBatch.Draw(arm, armPos, null, Color.White, armRotation, Vector2.Zero, 1, SpriteEffects.None, 0); 

    I want lets say I move the mouse up, the arm moves up.
  • 11/1/2008 11:17 AM In reply to

    Re: Rotation based on mouse

    I would compared the previousMouseState with currentMouseState then set the rotation of your object:

    int result = mouseState.Y - previousMouseState.Y; 
     
    rotation += (float)result * 0.001f; 

    I would also lock mouse movement to the centre of the screen and set a clamp on the rotation of the arm.
Page 1 of 1 (7 items) Previous Next