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 implement Hinge Constraints? #2

Open
Peach1 opened this issue Nov 2, 2019 · 1 comment
Open

How to implement Hinge Constraints? #2

Peach1 opened this issue Nov 2, 2019 · 1 comment

Comments

@Peach1
Copy link

Peach1 commented Nov 2, 2019

Hey, I noticed that constraints don't seem to be implemented yet, I would like to try implementing it.
Would hinge constraints just be clamping angles of the quaternion or is it more complicated to do correctly?
https://github.com/TheComet/ik/blob/devel/ik/src/constraint.c#L35

This fabrik IK library is pretty useful and I'm using the version from Urho3D as a standalone, I was wondering if any insight could be provided on what parts of the this ik library need finishing and how to conceptually do so; Like implementing hinge constraints.

@TheComet
Copy link
Owner

TheComet commented Nov 5, 2019

Hey Peach1!

You are very welcome to give this a go.

static void
apply_hinge(ikreal_t delta_rotation[4],
            const ikreal_t current_rotation[4],
            struct ik_constraint_t* constraint)
{
    /* write to delta_rotation */
}

The way this was supposed to work is you would check if the segment is within the constraint limits, and if it is not, you calculate what the rotation would need to be in order to move the segment back into the limit (delta_rotation). current_rotation would be the joint rotation in local coordinates, and constraint->hinge.(axis|min_angle|max_angle) would be your constraint parameters (also in local coordinates).

Feel free to add or remove what you need from https://github.com/TheComet/ik/blob/devel/ik/include/public/ik/constraint.h#L33

If you look at https://github.com/TheComet/ik/blob/devel/ik/src/solver_fabrik.c you will see solve_chain_forwards and solve_chain_backwards. These are the variants that don't consider constraints. There are another two functions called solve_chain_forwards_with_constraints and solve_chain_backwards_with_constraints that would be called if the IK_ALGORITHM_CONSTRAINTS flag is set. They're basically copies of the non-constraint versions, except that they need to transform the current node from global to local space before applying the constraint, and then transform the node back into global space so the algorithm can continue.

This part doesn't work at all yet. If you want you can rewrite those two functions from scratch.

I think that's all I can offer for now. I've had very little time to work on this unfortunately, I'm not sure whether the devel branch even works properly. I recall leaving the project in a mess where nothing works, so if you have issues you should probably switch to master and I'll work on merging the fixes from devel.

Do you have Discord? I'm TheComet#5387

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