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

problems with rotation

Last post 6/28/2007 1:48 PM by SwampThingTom. 5 replies.
  • 6/27/2007 5:52 PM

    problems with rotation

    I have a problem regarding rotation of a model around its axis using the keyboard.

    if (newState.IsKeyDown(Keys.Left))
    beast.rotateY -= 0.03f;

    This is a sample of the code used to increase the rotation. rotateY is a float.
    The rotation is calculated using the following code:

    worldMatrix = Matrix.Identity * Matrix.CreateRotationY(rotationY) * Matrix.CreateTranslation(modelPosition);


    This is in the Update method. The problem is that the model spins correctly but too fast. Whatever the value I add to be rotated it is still the same speed. Can anyone help?
  • 6/27/2007 6:49 PM In reply to

    Re: problems with rotation

    Could it be that instead of rotationY in Matrix.CreateRotationY(), you should used beast.rotateY?  Just a hunch.
  • 6/27/2007 6:56 PM In reply to

    Re: problems with rotation

    Answer
    Reply Quote

    Whatever the value I add to be rotated it is still the same speed.

    Are you saying that no matter what value you use for rotationY, it always rotates at the same speed?  If so, then I would assume that rotationY is not getting set correctly.  You should use the debugger or some WriteLines to verify that the value is changing as you expect.

    As for what value to use, you can define a RotationsPerSecond constant that contains the number of radians needed to do a full rotation in one second:

    float RotationsPerSecond = MathHelper.TwoPi / 60f;

    Then just multiply that by the number of rotations you want per second to get the value to add to rotationY when the key is pressed.  The value you use in your example (.03) should produce a full rotation every 3 seconds.

    Tom

  • 6/27/2007 7:17 PM In reply to

    Re: problems with rotation

    The angle needs to be in radians, use MathHelper.ToRadians() to do it.

    For example:

    Matrix.CreateRotationY(MathHelper.ToRadians(myAngle));
    --
    Gamer Outfit - XNA News and Reviews
    Maker of Exisled - Helicopter 2d/3d Shooter available now!
  • 6/27/2007 7:35 PM In reply to

    Re: problems with rotation

    Maximos,
    you use a float beast.rotateY & a float rotationY,
    How are you using beast.rotateY to update rotationY that is used in the worldMatrix setup?


    Unlock The *I don't use 3 angles in a Vector3 for rotations anymore* Achievement Here
  • 6/28/2007 1:48 PM In reply to

    Re: problems with rotation

    L0STlogic:
    The angle needs to be in radians, use MathHelper.ToRadians() to do it.

    For example:

    Matrix.CreateRotationY(MathHelper.ToRadians(myAngle));

    Just a quick clarification on this -- you only need to call ToRadians if the original angle is in degrees.  If the angle he's using in his example (0.03f) is what he is actually using in his code, I would assume that is in radians already and doesn't need to be converted.  If that is the angles in degrees, he likely wouldn't be complaining that the model was rotating too slowly fast!  ;-)

    Tom

    EDIT: Fixed bonehead mistake.

Page 1 of 1 (6 items) Previous Next
var gDomain='m.webtrends.com'; var gDcsId='dcschd84w10000w4lw9hcqmsz_8n3x'; var gTrackEvents=1; var gFpc='WT_FPC'; /*<\/scr"+"ipt>");} /*]]>*/
DCSIMG