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

Rotation algorithms

Last post 11/22/2007 11:55 PM by ppontheweb. 8 replies.
  • 11/16/2007 5:39 AM

    Rotation algorithms

    Hi all
     I am looking for some rotation algorithms.....................suggestions are extremely appreciated.
  • 11/16/2007 8:57 AM In reply to

    Re: Rotation algorithms

    You'll need to be more specific. What do you mean by "rotation algorithms"?
  • 11/18/2007 11:23 AM In reply to

    Re: Rotation algorithms

    You have to be more specific.

     

    But a good start is that if you have a force-vector, called F, located at position R from the center of your object. Then the momentum, M, is M=R x F. (cross product).

    With this you can get the rotation-acceleration by M/m where m is the mass of the object.

     

    I don't know if the last equation(M/m) is physicaly correct but at least it works and it looks good :D

     

    Edit: I think you should replace the mass with the inertia of the object, check this link for a good reference between linear and rotational motion. (My M is his I)

    http://hyperphysics.phy-astr.gsu.edu/hbase/mi.html

  • 11/20/2007 5:02 AM In reply to

    Re: Rotation algorithms

    Hi

    Actually i am computing my world matrices with the quarternion computed from D3DXQuaternionRotationYawPitchRoll function and the rotation of the object is not according to what is expected. Rotation of one axis is relative to the other axis..

    Algorithm of my code

    1. Calculate quaternion.
    2. Compute matrix from quaternion.
    3. Compute world matrix = scaling * rotation * translation.

    thanks
  • 11/20/2007 5:48 AM In reply to

    Re: Rotation algorithms

    I am calculating this quaternion at every instance. and i want to ask one more thing that should i calculate this every time or store the old values and add up the new ones or any thing else??????????????????????????
  • 11/20/2007 5:10 PM In reply to

    Re: Rotation algorithms

    Are you using radians for the yaw, pitch, and roll?

    What do you mean by: "Rotation of one axis is relative to the other axis." ? Are you saying you put yaw of Pi/4 degrees, but instead get a 45 degree turn for pitch?

    And for building your matrices each update; it is all to personal preference. But if you rebuild you obviousily have to reconstruct the full rotation. If you add on a new amount of change (which I personally like) you must remember your order of operations... quaternions don't multiply like vectors and floats. You have to multiply them in the correct order.
    Also don't do what some others I've read do, and assume you have to multiply on the entire rotation. Just find the amount of yaw pitch and roll you want to do with respect to the origin and just multiply that by the current quaternion rotation.
  • 11/21/2007 12:27 AM In reply to

    Re: Rotation algorithms

    Hi lordofduct
    I am using Radians as the function D3DXQuaternionRotationYawPitchRoll function uses radians...............And "Rotation of one axis is relative to the other axis" means that when i rotate the object in the axis independently than it is fine but when i rotate the object in X axis and then in Z axis it rotates in Z axis w.r.t X axis not independently in to Z axis. As you specified that you like adding new rotation , Is there any advantage of using this method over calculating at every update?

    thanks
  • 11/21/2007 3:14 PM In reply to

    Re: Rotation algorithms

    You are rotating weird around different axis's because of the way Euler's work. I never used the D3DQuaternionRotationYawPitchRoll method, but from checking it out on msdn I assume it takes any generic yaw pitch roll and converts it to a quaternion just like the XNA method QuaternionFromYawPitchRoll.

    Regular Euler rotations are with respect to the origin no matter what the already existing angle is. This means that if you were to rotate into -45 degrees around the X axis and then rotate continuousily around the Z axis your object will always stay pointing down the -Z axis.

    If you're expecting the object to yaw, pitch or roll around it's own existing angle. Then you either A) have to know what the correct euler rotation should be, which isn't easy. Or solve each one independently and multiply them up. Like so using XNA:

    Quaternion rotation = Quaternion.FromAxisAngle(Vector3.UnitX, pitch) * Quaternion.FromAxisAngle(Vector3.UnitY, yaw) * Quaternion.FromAxisAngle(Vector3.UnitZ, roll);

    This will result in completely independent rotations around each axis of the object. Then if you take the current quaternion rotation and multiply it by any new rotation you want to do... then it will smoothly work out.

    like so:

    Quaternion current = "current Rotation";
    float yawChange = -thumbstick.X * modifier;
    Quaternion target = Quaternion.CreateFromAxisAngle(Vector3.UnitY, yawChange);
    current *= target;

    now if you change this code and say "target *= current;" instead then you'll get something else, what would happen then is you'd rotate around the world UnitY, but as "current *= target;" you get the object yawing around it's own up vector.



    ... As for your other question, why I like to just add on the new rotation instead of resolving. This is my personal choice merely because I can visualize it better in my head instead of refiguring out the entire rotation. I work in spherical coordinate system's a lot (when I do math, not when I program), so it is what I'm used to... I'm used to treating quaternions and rotations as vectors instead of as complete rotations.
  • 11/22/2007 11:55 PM In reply to

    Re: Rotation algorithms

    got it right.............................

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