9
\$\begingroup\$

I can't find any good library for animation, the ones that I found are just really old and discontinued, but I have noticed that the libraries are relatively small, so I'm thinking about coding one on my own: where should I start? What are the basics for this? There is a book about this?

Some further notes about a good file format for animation are also highly appreciated.

I'm using C++.

\$\endgroup\$
8
\$\begingroup\$

Don't try to write anything from scratch. Refer to existing code and take it from there.

And if you want reading material:

| improve this answer | |
\$\endgroup\$
7
\$\begingroup\$

Forward kinematics is just a prerequisite for inverse kinematics, in general.

For forward kinematics you must have some knowledge of transform chains (what a scene-graph means for example). As an example, a good point to start from is the Denavit-Hartenberg convention. For inverse kinematics, study Cyclic Coordinate Descent (CCD), Jacobian Inverse, Jacobian transpose and pseudo-inverse solutions. These concepts and algorithms offer you a decent overview of what the mathematics and partly the physics of this field is all about. The library, programming language or file formats are never the key element if you also want to understand what happens behind the magic.

If you need a quick solution or a component for some application you're working on, then do take a look on some of the libraries provided in the other answer(s) here. If you're into robotics, then OpenRAVE is a monster worth mentioning. Also, there is a Matlab Robotics Toolbox (provided you're into that kind of engineering side of the matter).

All of the concepts yield a truckload of relevant results on your favourite search engine, so sorry for not posting that many links to nice materials.

| improve this answer | |
\$\endgroup\$
1
\$\begingroup\$

Original Article: What do I need to know about Inverse Kinematics?

You’ve probably heard of Inverse Kinematics. IK is a popular tool in Unity and computer graphics, but if this is the first time you’ve tried to create or use an Inverse Kinematics system then you might want more details. I’m going to explain what IK is, define the vocabulary, and review the uses. What is the necessary vocabulary to understand IK?

Before we get into the heart of IK, we need to define some IK-related vocabulary. IK is a method that is applied to an articulated body. What is an articulated body?

Articulated Body

An articulated body can represent most animated bodies such as humans and animals with skeletons. Simply put, an articulated body is a tree of linked chains. The linked chains are made up of joints and links, where a link is a rigid cylinder.

enter image description here

Types of Joints

As for joints, there are two types. The first type of joint is a revolute joint. It is connected to a link that rotates around it.

A revolute joint is much like the center pin of a clock — with a clock hand as a link.

enter image description here

A prismatic joint is a joint such that the connected link translates from the joint to extend/shorten the link.

enter image description here

A prismatic joint acts much like extending/retracting the length of the retractable handle on your luggage. If you look closely, a retractable luggage handle has 4 prismatic joints. 2 prismatic joints half way down the handle, and another 2 prismatic joints all the way down the handle at the top of the luggage.

If you’re confused by prismatic joints, don’t worry. They are not used that often in Inverse Kinematics, and as you might be able to tell, no humans have prismatic joints — only revolute joints.

Hierarchical Structure

An articulated body has a root joint. The root joint is the base of the structure. The root joint for a humanoid is usually the center of the hips. The articulated body is formed from a tree of joints and links, starting at the root joint. A new joint and link is similar to a new branch on a tree. An inboard link/joint is a link/joint that is closer to the root joint within the tree hierarchy of the articulated body, as it relates to given joint/link. An outboard link/joint is a link/joint that is further away from the root joint within the tree hierarchy of the articulated body.

End Effector

An end effector is a position at the most outboard position of the most outboard link. It is the free end of the chain of alternating joints and links. The end effector is not a joint. The end effector is merely the position at the end of an articulated body. An articulated body can have multiple end effectors, just like a binary tree can have multiple leaves.

enter image description here

End Effector is depicted as a green circle here.

Articulations and Poses

An articulation is a rotation/translation of a joint which moves a connected link. On the other hand, a pose is a set of joint articulations which results in positioning the articulated body. In other words, the pose is a vector value of instead of a scalar value.

What is Forward Kinematics?

Before we can get into what Inverse Kinematics is, we need to figure out what Forward Kinematics is. The Forward Kinematics function/algorithm takes a pose as the input, and calculates the position of the end effector as the output. Forward Kinematics is the inverse function of Inverse Kinematics. With Forward Kinematics, you need to define the whole pose of an articulated body so as to provide the function/algorithm with the pose input. This means you need to define the articulation of each joint in the articulated body. This might be fine if you have a low number of joints, but with a high number of joints this tends to be tedious.

What is Inverse Kinematics?

Now, imagine if you’d like the end effector of your articulated body to reach a particular target position. This means that you know the end effector position you’d like to target, but you don’t know what the pose of the articulated body needs to be for the end effector to reach this target position. This is where Inverse Kinematics shines!

enter image description here

Inverse Kinematics is the inverse function/algorithm of Forward Kinematics. The Forward Kinematics function/algorithm takes a target position as the input, and calculates the pose required for the end effector to reach the target position — the pose is the output.

As you can see, the input and output are switched between FK and IK. With Inverse Kinematics, you do not need to define the whole pose of an articulated body — this gets calculated for your by the IK algorithm. With IK, you only need to define a position as the input.

Inverse Kinematics does all the challenging computational work of calculating what the pose is. In the Before State, there is an articulated body with some known pose. It defines a target position for the end effector to try to reach. Once the IK algorithm is applied to the articulated body, we have reached the After State. The After State shows that a new pose has been computed, such that the end effector is now at the target position.

What are the uses of IK?

At this point, we know that IK is applied to an articulated body, we know what an articulated body is made up of, and we know the difference between IK and FK. We have a good overview of IK so far, but let’s round it out with some good use cases of IK as well. IK can be used for a humanoid arm to reach for an object/target, as we’ve seen. IK can also be used for foot stepping, such that we tell the foot where to step and the IK figures out how to configure the leg joints. IK is not usually used as an animation itself (reaching for an object), but more as an animation tool. So, if you are implementing a walk cycle, you could position some of the key frames using the IK tool.

enter image description here

Another key point about IK is that your goal/target is not limited to position alone — your goal can be defined as a rotation. For example, if your feet need to rotate based on uneven terrain, your IK rotation goal can be defined based on the floor’s normal. This way your feet are inclined along the floor, such as when you are walking up an incline. Note that you can also use IK to have your head (or even eyes) look in a certain direction. If you want your head to follow an object, you can use IK to have the head follow the object around.

| improve this answer | |
\$\endgroup\$

Not the answer you're looking for? Browse other questions tagged or ask your own question.