Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to set and get the rotation of each joint #10

Open
Mr-djh opened this issue Jun 25, 2020 · 7 comments
Open

How to set and get the rotation of each joint #10

Mr-djh opened this issue Jun 25, 2020 · 7 comments

Comments

@Mr-djh
Copy link

Mr-djh commented Jun 25, 2020

Hi there,

I would like to use your library for my inverse kinematics of Ergonomic project ,however the instructions are not very clear for a beginner.Mainly lie in the input and output of rotations.The questions can be listed as follows:
1、Before ik.solver.solve(solver),should we set the rotations of root->rotation and target->rotation in global space ?
At the same time,should we set the rotation of child->rotation in local space?
2、After ik.solver.solve(solver),I want to get the rotation of each joint in order to realize the inverse kinematics,but I don't know whether the rotation that I get is a global rotation or a local rotation?
3、After ik.solver.solve(solver),whether the joint's rotation that I get is a delta rotation?

What's more,I have tried several forms of input and output of rotations, but the result is always unsatisfactory.Look forward to hearing from you.

@TheComet
Copy link
Owner

TheComet commented Jun 26, 2020

Hey!

  1. Yes, you should write the rotations to each node->rotation field before calling ik.solver.solve(). These rotations are all in local space. root->rotation usually is always an identity rotation in most game engines, but if you do want to set this you can. For the root node, local space is the same thing as global space. target->rotation is set in global space.

  2. After calling ik.solver.solve() you get the rotations back from each node->rotation field in local space.

  3. You do not get delta rotations, you get the "solved" rotations. That is, each node will have an absolute orientation that represents the solution. If you want to get delta rotations you can subtract the solved rotations from the initial rotations that are stored in each node->initial_rotation field.

Please let me know if this helped.

This library has undergone a lot of changes and I must admit I am no longer certain if V1.1 fully works as intended. If you are unable to get satisfactory results then there is an older API V1.0 which definitely does work, as this is the version used in the Urho3D game engine. However, it is slightly different.

Did you find the wiki page? Most of the information should be here: https://github.com/TheComet/ik/wiki/Tutorial-1.1

@Mr-djh
Copy link
Author

Mr-djh commented Jun 27, 2020

Thanks for your response!

According to your guidance,I updated my own program,But I encountered a problem ,namely, after calling ik.solver.solve(),the positions I get back from each node->position can work well;however, I use the rotations which I get back from each node->rotation to set the joint angle ,but I can not get the desired posture.Now I suspect I didn't use the solved rotations correctly or other reasons.Pardon my asking,whether you have relative sample program?

@TheComet
Copy link
Owner

TheComet commented Jun 27, 2020

Can you check if you have set the IK_ENABLE_JOINT_ROTATIONS flag? Without it, FABRIK does not calculate rotations.

solver->features |= IK_ENABLE_JOINT_ROTATIONS;

Do this once prior to ik.solver.solve().

Right now there are no samples that directly use this library unfortunately. There are only Urho3D samples that use the library indirectly. They're probably not that useful but if you want to go digging in Urho3D's source code you can find those here: https://github.com/urho3d/Urho3D/tree/master/Source/Samples/45_InverseKinematics and https://github.com/urho3d/Urho3D/tree/master/Source/Urho3D/IK

@Mr-djh
Copy link
Author

Mr-djh commented Jun 27, 2020

I have set the "solver->flag |= IK_ENABLE_JOINT_ROTATIONS;".

I plan to use the library(API V1.0) and try to dig in the Urho3D's sourse code.

Thanks again.If there is any progress, I will communicate with you in time.

@TheComet
Copy link
Owner

Alright. The biggest difference in V1.0 is all of the node positions and rotations are in global space, and the function names are global rather than ik.group.func.

Hopefully it won't be long until I can release V2.0.

@TheComet
Copy link
Owner

Hey! I was going to test the code you posted a week or so ago just now but I think you deleted it.

Does this mean you got it to work? :)

@Mr-djh
Copy link
Author

Mr-djh commented Jul 20, 2020

Thanks!
I have corrected the code that I posted somedays ago and it can work,so I delete the code.

At the same time,I plan to study how to add constraints to joints,because I find that it(the virtual human) can go wrong all of a sudden without the constraints.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants