quaternion to 2d angle

Discussion in 'Programming' started by mbeytekin, Oct 10, 2019.

  1. mbeytekin

    mbeytekin Member

    Joined:
    Jun 26, 2016
    Posts:
    7
    I've a little personal project about converting mocap data from 3ds max ASE file to Spine skeletons.
    I have no idea about quaternion conversions and after searching forum I found quaternionGetx and other scripts by Slayer64

    But after trying a lot of combinations couldn't get usable results.
    Example of 3ds max ASE file about rotation;
    *CONTROL_ROT_SAMPLE 0 -1.0 0.1 -0.1 0.8
    *CONTROL_ROT_SAMPLE 160 -0.9 -0.3 0.3 0.0
    *CONTROL_ROT_SAMPLE 320 -0.9 -0.2 0.4 0.0
    *CONTROL_ROT_SAMPLE 480 -0.8 -0.2 0.6 0.0
    *CONTROL_ROT_SAMPLE 640 -0.0 0.0 1.0 0.0
    *CONTROL_ROT_SAMPLE 800 0.9 0.2 0.5 0.0
    *CONTROL_ROT_SAMPLE 960 1.0 0.2 0.2 0.0
    *CONTROL_ROT_SAMPLE 1120 1.0 0.2 0.1 0.0
    *CONTROL_ROT_SAMPLE 1280 1.0 0.2 0.0 0.0
    *CONTROL_ROT_SAMPLE 1440 1.0 0.2 -0.0 0.1
    *CONTROL_ROT_SAMPLE 1600 1.0 0.1 -0.1 0.1


    -1.0 0.1 -0.1 0.8 are rotation values.. I think first 3 arguments are x,y,z and last one is angle.
    which is rw,rx,ry,rz ... and I need rotate this values around z axis for projection before convertion.(for example 90 or 80 degrees)

    I tried

    quaternionCreate(rw,rx,ry,rz)
    quaternionAutoRotate(rw,rx,ry,rz,0,0,-1,90)
    quaternionGetx(rw,rx,ry,rz)


    and I use rx for Spine skeleton rotation ... but it doesnt work.

    I tried other combinations for rw rx ry rz, Autorotate with changing up vectors and degree, gettin rx ry rz .. doesnt work.

    Anybody can help me about this.

    Regards
     
    Last edited: Oct 10, 2019
  2. flyingsaucerinvasion

    flyingsaucerinvasion Member

    Joined:
    Jun 20, 2016
    Posts:
    2,169
    What value exactly are you trying to find for your spine rotation? An angle to rotate around the z axis?
     
    mbeytekin likes this.
  3. mbeytekin

    mbeytekin Member

    Joined:
    Jun 26, 2016
    Posts:
    7
    Yes. I think so.But I'm not sure...
    Imagine that there is a model from mixamo with animation. I export this from 3ds max to ASE format. For example leftleg bone rotating from its pivot point in 3ds max (for example 30 degrees in x axis at first keyframe). I want to get this angle with a side view. In fact my codes must be correct. But I'm not sure why results are bad.
    Normally I need only x axis' rotation of 3d model's bones (because my Spine characters are drawn in sideview). But I think I missed that 3d model's rotation values must be rotated to a side view.That's why I tried rotate quaternion value by 90 degree in z axis. But as I say this gives me very strange results.
     
  4. mbeytekin

    mbeytekin Member

    Joined:
    Jun 26, 2016
    Posts:
    7
  5. flyingsaucerinvasion

    flyingsaucerinvasion Member

    Joined:
    Jun 20, 2016
    Posts:
    2,169
    Do all the quaternions represent rotations around the same axis (i.e.,you could consider it 2d when viewed from one direction)?
     
    Last edited: Oct 10, 2019
  6. mbeytekin

    mbeytekin Member

    Joined:
    Jun 26, 2016
    Posts:
    7
    Yes they are. In 3d model there are y and z rotations too. But its not important for me.I need only x axis. And problem is 3d model viewed from front in 3ds max. Rotating it 90 degrees to side view doesnt change anything.
    Could you say my quaternion script usage is correct or am I missing something?
     
  7. flyingsaucerinvasion

    flyingsaucerinvasion Member

    Joined:
    Jun 20, 2016
    Posts:
    2,169
    Ok, first apologies because I am still not 100% sure I understand what you're doing.

    However, if all of the quaternions are doing rotations around the same axis, I think you can get away with an easy solution to this.

    The angle of rotation for the quaternion is

    angle = acos(w)*2 (use darccros if dealing with degrees)

    If you just apply that same angle as a rotation on the z axis, I think it ought to do the trick. But it is presuming that all the rotations are on the same axis (AND that all rotations use a positive angle of rotation).

    EDIT: If all rotations are on the x axis, then you should be able to get get the angle even if it is negative, like this:

    angle = 2*acos(w)*sign(x)
     
    Last edited: Oct 10, 2019
  8. mbeytekin

    mbeytekin Member

    Joined:
    Jun 26, 2016
    Posts:
    7
    Thank you I will try...
     
  9. mbeytekin

    mbeytekin Member

    Joined:
    Jun 26, 2016
    Posts:
    7
    Sorry. It doesnt work. I think I can't understand well what must I do with this '*CONTROL_ROT_SAMPLE 0 -1.0 0.1 -0.1 0.8' values from ASE file.
     
  10. flyingsaucerinvasion

    flyingsaucerinvasion Member

    Joined:
    Jun 20, 2016
    Posts:
    2,169
    If that is a quaternion then it doesn't represent a rotation around a world axis. If it did, it would only have two values that were non-zero.

    I don't know what kind of input that spine will accept. Does it do other kinds of rotations apart from only rotations around the z axis? I suppose we could convert any rotation in 3d to a combination of z rotation and length contraction.
     
    mbeytekin likes this.
  11. mbeytekin

    mbeytekin Member

    Joined:
    Jun 26, 2016
    Posts:
    7
    thank you flyingsaucerinvasion for your help and interest.
    After a couple of days I realized that main problem is Spine 2d angle format. it works parent relative angle. and its rotation limits -180 to 180. For example if rotation angle of 3d model 190 degrees Spine angle must 190-180=10 and 180-10=170 negative.-170.
    After I realized that I wrote a scipt in 3ds max for getting rotation angle of every bone relative to its parent and converting it to Spine's rotation system.And it works...
    arccos(w)*2*sign(rx) works if I want to work with quaternion values. But as I say I realized that I don't need quaternion values and my 3ds max script exports relative angles in euler format.

    If anyone need to help about matching any mocap file with Spine skeletons I can help. I want to share my mini converter program but it is not clean for now. After I organize codes I can share..
    Thanks again..
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice