Hi, all!
Still fighting this for a long time now, but got zero success.
I want my character to turn his head, neck, chest and eyes to the point in 3D space.
This character can have any pose at that time and play animation.
Lets consider poses where head is relatively vertical (more vertical than horizontal, or can be made so
without much effects).
So I need:
- turn head to vertical position
- and then turn in direction of target.
- turn chest half-way
- turn neck half-way
Problems:
- Rotations are relative and accumulative, each one creates its new coordinate system.
When quaternion multiplication is done, it is done in order from left to right,
so if full transform of head is q1 * q2 * q3 *q4 , only q1 rotates in global space, all the rest
rotate in previous quaternion space. With lots of them it becomes very hard to track target rotation.
Also the transform is non-commutative, which means order is important. So if I want to convert my rotation from global space to local space, I will need to multiply it by inverse rotations in reversed order. - To rotate something in global space I will add my rotation at beginning of sequence, it will rotate the whole thing globally. so if q is current rotation of head and qdelta is additional rotation I need to apply, I just do qdelta * q
to get q rotated in global space. But general target is usually a bit different - we need to do local rotation
so that it comply to global goals. So we need to calculate local delta for each rotating bone, and that is where
biggest problem comes.
Initially we have some animation running, with head facing front. We have some global point in space, to which we want to look. We have some global node master which represents global character trasform in space.
Each bone contributes to that transform using its own quaternion each, having head as final.
So having our initial delta rotation, we somehow need to convert it to local rotation of head bone.
The simple approach of multiplying by parent’s world transform doesn’t work. That is where I stopped.
Tricks like Rotate(x, TS_WORLD) do not help either, so I think the problem is deeper.
This kind of look-at “IK” works quite well in other engines, like Unity, UE4, Godot. But not in Urho.
Probably there is some technical detail about quaternions in Urho, which make it different,
so I’d like to know them. Please note that I look for generic solution, not something which assumes vertical position
or Z-facing. I assume work in any random initial pose (which makes sense for look-at). In my case I think the problem
is solved when character can look-at from head-on pose in addition to standing and sitting.
The challenge looks quite tough.