Inverse Kinematics
-
kelmer
- Halfling
- Posts: 81
- Joined: Fri Dec 11, 2009 9:31 am
- x 4
Inverse Kinematics
I need a simple IK solver for a three-bone limb (the usual shoulder-elbow-hand) but haven't found any simple solvers around aside from this analytical solver, which is not working properly for me: http://www.lostchamber.com/inverse-kine ... e-for-ogre
Are there any code snippets around implementing some solvers, like CCD for instance?
Are there any code snippets around implementing some solvers, like CCD for instance?
-
Matheus Martino
- Gremlin
- Posts: 164
- Joined: Mon Sep 07, 2009 10:44 pm
- Location: Brazil
Re: Inverse Kinematics
I know nothing about it sorry.... but using search on the forun i found one post of one of that techniques implemented in ogre: Inverse Kinematics support using OpenTissue
Excuse me if my english fail!
-
kelmer
- Halfling
- Posts: 81
- Joined: Fri Dec 11, 2009 9:31 am
- x 4
Re: Inverse Kinematics
Thanks for your reply.
I implemented CCD method for IK recently, which works ok, but I need to implement bone constraints (DOF angle restrictions). The problem is, if I use getOrientation() I get a Quaternion, and my restrictions are euler angles (i. e. elbow can't bend more than X degrees in X axis). Is there any way to convert Quat->Euler and vice-versa?
I implemented CCD method for IK recently, which works ok, but I need to implement bone constraints (DOF angle restrictions). The problem is, if I use getOrientation() I get a Quaternion, and my restrictions are euler angles (i. e. elbow can't bend more than X degrees in X axis). Is there any way to convert Quat->Euler and vice-versa?
-
madmarx
- OGRE Expert User

- Posts: 1671
- Joined: Mon Jan 21, 2008 10:26 pm
- x 51
Re: Inverse Kinematics
quaternion-> matrix -> matrix::toEulerAngle->euler
euler->matrix::fromEulerAngle->matrix->quaternion
Be careful about projection XYZ/UXZ etc...
I am exactly at the same point as you with inverse kinematic (introducing constraint in my ccd)
.
I have also the jacobian method.
euler->matrix::fromEulerAngle->matrix->quaternion
Be careful about projection XYZ/UXZ etc...
I am exactly at the same point as you with inverse kinematic (introducing constraint in my ccd)
I have also the jacobian method.
Tutorials + Ogre searchable API + more for Ogre1.7 : http://sourceforge.net/projects/so3dtools/
Corresponding thread : http://www.ogre3d.org/forums/viewtopic. ... 93&start=0
Corresponding thread : http://www.ogre3d.org/forums/viewtopic. ... 93&start=0
-
kelmer
- Halfling
- Posts: 81
- Joined: Fri Dec 11, 2009 9:31 am
- x 4
Re: Inverse Kinematics
Thanks, I had not found about that function. What do you mean by XYZ,UXZ projection?
Did you already introduced constraints? Can you post some code?
Did you already introduced constraints? Can you post some code?
-
madmarx
- OGRE Expert User

- Posts: 1671
- Joined: Mon Jan 21, 2008 10:26 pm
- x 51
Re: Inverse Kinematics
I meant :
FromEulerAnglesXYZ
FromEulerAnglesYYX
FromEulerAnglesXZY
...
etc... which can fail, because of gimbal lock. 'U' was a missed key
.
I have not introduced constraints, before that I need to clean my classes, since some of my tools might be used for other things than ik.
I am likely to do that this week end. My aim is to test if one of my algorithm that allow mixing physics, animation playing and ik really works.
FromEulerAnglesXYZ
FromEulerAnglesYYX
FromEulerAnglesXZY
...
etc... which can fail, because of gimbal lock. 'U' was a missed key
I have not introduced constraints, before that I need to clean my classes, since some of my tools might be used for other things than ik.
I am likely to do that this week end. My aim is to test if one of my algorithm that allow mixing physics, animation playing and ik really works.
Tutorials + Ogre searchable API + more for Ogre1.7 : http://sourceforge.net/projects/so3dtools/
Corresponding thread : http://www.ogre3d.org/forums/viewtopic. ... 93&start=0
Corresponding thread : http://www.ogre3d.org/forums/viewtopic. ... 93&start=0
-
kelmer
- Halfling
- Posts: 81
- Joined: Fri Dec 11, 2009 9:31 am
- x 4
Re: Inverse Kinematics
Okay, how do I know which one I should use??
Just for reference, if anyone needs a simple IK function, I'm posting my CCD solver, based on Jeff Lander's at http://www.darwin3d.com:
Just for reference, if anyone needs a simple IK function, I'm posting my CCD solver, based on Jeff Lander's at http://www.darwin3d.com:
Code: Select all
// returns given bone's world position
inline Vector3 wp(SceneNode* node, Bone* bone)
{
return node->_getDerivedPosition() + node->_getDerivedOrientation() * node->_getDerivedScale() * bone->_getDerivedPosition();
}
double VectorSquaredDistance(Vector3 *v1, Vector3 *v2)
{
double retValue = ( ((v1->x - v2->x) * (v1->x - v2->x)) +
((v1->y - v2->y) * (v1->y - v2->y)) +
((v1->z - v2->z) * (v1->z - v2->z)) );
return retValue;
}
BOOL ComputeCCDLink3D(Vector3 endPos, tMovableElement *m_Link, int numTries){
/// Local Variables ///////////////////////////////////////////////////////////
Vector3 rootPos,curEnd,targetVector,curVector,crossResult;
double cosAngle,turnAngle;
Degree turnDeg;
int link,tries;
Quaternion aQuat;
int EFFECTOR_POS = m_Link->posEffector;
Bone** m_bones;
//////////////////////////////////////////////////////////////////////////////////
// // Empezamos por el ultimo hueso de la lista, sin contar el efector (no angulamos
//el efector) m_bones = m_Link->bones;
link = EFFECTOR_POS - 1;
tries = 0; // LOOP COUNTER SO I KNOW WHEN TO QUIT
m_bones = m_Link->bones;
lineList.clear();
do
{
// THE COORDS OF THE X,Y,Z POSITION OF THE ROOT OF THIS BONE IS IN THE MATRIX
// TRANSLATION PART WHICH IS IN THE 12,13,14 POSITION OF THE MATRIX
// Calculamos la posición real de este hueso
rootPos = wp(m_Link->node,m_bones[link]);
// y la del efector
curEnd = wp(m_Link->node,m_bones[EFFECTOR_POS]);
if (VectorSquaredDistance(&curEnd, &endPos) > IK_POS_THRESH)
{
// Vector a la posición actual del efector
curVector = curEnd - rootPos;
debugLine(curEnd,rootPos);
// Vector a la posición deseada del efector
targetVector = endPos - rootPos;
debugLine(endPos,rootPos);
curVector.normalise();
targetVector.normalise();
crossResult = curVector.crossProduct(targetVector);
crossResult.normalise();
aQuat = curVector.getRotationTo(targetVector,Vector3::NEGATIVE_UNIT_Z);
m_bones[link]->rotate(aQuat, Ogre::Node::TransformSpace::TS_WORLD);
CheckDOFRestrictions(m_bones[link]);
m_bones[link]->_update(true,false);
if (--link < 0)
link = EFFECTOR_POS - 1; // START OF THE CHAIN, RESTART
}
} while (tries++ < numTries &&
VectorSquaredDistance(&curEnd, &endPos) > IK_POS_THRESH);
if (tries == numTries)
return FALSE;
else
return TRUE;
}-
kelmer
- Halfling
- Posts: 81
- Joined: Fri Dec 11, 2009 9:31 am
- x 4
Re: Inverse Kinematics
Where can I find source for toEulerAngleXXX?? Can't find it in OgreMatrix3.h...
-
kelmer
- Halfling
- Posts: 81
- Joined: Fri Dec 11, 2009 9:31 am
- x 4
Re: Inverse Kinematics
What is it exactly you don't understand?
-
kelmer
- Halfling
- Posts: 81
- Joined: Fri Dec 11, 2009 9:31 am
- x 4
Re: Inverse Kinematics
Inverse Kinematics try to calculate rotations and positions of limbs for an effector (say, a hand) to reach a desired point, as opposed to Forward Kinematics in which you explicitly indicate the rotation angles and positions of the limbs directly.
For instance, you want your character to reach several objects which might be at different heights, so instead of creating an animation of your character reaching at every possible height you can use Inverse Kinematics to make his arm reach specifically to that object (the object is the target position of the hand).
For instance, you want your character to reach several objects which might be at different heights, so instead of creating an animation of your character reaching at every possible height you can use Inverse Kinematics to make his arm reach specifically to that object (the object is the target position of the hand).
-
kelmer
- Halfling
- Posts: 81
- Joined: Fri Dec 11, 2009 9:31 am
- x 4
Re: Inverse Kinematics
Glad to help 
-
kelmer
- Halfling
- Posts: 81
- Joined: Fri Dec 11, 2009 9:31 am
- x 4
Re: Inverse Kinematics
Hey, where have the posts of this guy gone? Looks like I'm talking alone there 
-
xadhoom
- Minaton
- Posts: 973
- Joined: Fri Dec 28, 2007 4:35 pm
- Location: Germany
- x 1
Re: Inverse Kinematics
I think you talked actually to a very clever acting bot
Don´t take it personally
xad
Don´t take it personally
xad
-
kelmer
- Halfling
- Posts: 81
- Joined: Fri Dec 11, 2009 9:31 am
- x 4
Re: Inverse Kinematics
But he/it answered my questions (although its/his grammar was not that great)...
I'm buying a voight kampf test
I'm buying a voight kampf test
-
Florin
- Kobold
- Posts: 33
- Joined: Thu Mar 19, 2009 3:15 am
Re: Inverse Kinematics
For IK I use ROBOOP http://www.cours.polymtl.ca/roboop/download.php
It has also an editor for Denavit-Hartenberg parameters - "GLroboop". You cand easily configure any kind of serial robotic arm with this one. And it is very easy to implement.
It has also an editor for Denavit-Hartenberg parameters - "GLroboop". You cand easily configure any kind of serial robotic arm with this one. And it is very easy to implement.
-
johan07
- Greenskin
- Posts: 144
- Joined: Fri Dec 21, 2012 11:38 pm
Re: Inverse Kinematics
Hi ,
as i read , CCD ik solver is fast ? is when you implemnted it you get real time ?
as i read , CCD ik solver is fast ? is when you implemnted it you get real time ?
-
kelmer
- Halfling
- Posts: 81
- Joined: Fri Dec 11, 2009 9:31 am
- x 4
Re: Inverse Kinematics
It is fast for small distances, like in motion capture.
If you need the limb to reach to a far away point, then you should set a small iteration threshold so it does not block your application, and the arm should be reaching slow but smoothly towards the target point.
If you need the limb to reach to a far away point, then you should set a small iteration threshold so it does not block your application, and the arm should be reaching slow but smoothly towards the target point.
-
johan07
- Greenskin
- Posts: 144
- Joined: Fri Dec 21, 2012 11:38 pm
Re: Inverse Kinematics
so to move the arm i do not need to create animate state and use the interpolation to make the motion smooth ?slow but smoothly towards the target point.
what you mean by distance here ? you mean the distance between the target and the end effector pos?small distances
-
kelmer
- Halfling
- Posts: 81
- Joined: Fri Dec 11, 2009 9:31 am
- x 4
Re: Inverse Kinematics
The best thing you can do is try it, this solution is perfect for my needs, but it might not be suitable for every situation. I don't use any animation states, IIRC, I just set a small iteration threshold plus some damping (restriction of max movement) so that movements don't look sloppy.
-
johan07
- Greenskin
- Posts: 144
- Joined: Fri Dec 21, 2012 11:38 pm
Re: Inverse Kinematics
i will try it ,
last question :
my question is about your data and your skeleton
you applicate directelly motion data here in ogre ? or you was use another software ?
how it look your data
b
my data is like that
EDIT
last question :
my question is about your data and your skeleton
you applicate directelly motion data here in ogre ? or you was use another software ?
how it look your data
b
my data is like that
is it like that ?num frame_time position(x,y,z) of root and joints angle
0 0.01 12,10,100 5 0.1 0.3 0.2 0.3 2 .............
1 0.02 15,10,200 4 -0.2 0.3 ..................
3 0.03 100,1,300 1.2 3 4 .....
...........................................................
..........................................................
1000 20 200,100,1000
EDIT
where you defined those restriction in the code ?restriction of max movement
-
kelmer
- Halfling
- Posts: 81
- Joined: Fri Dec 11, 2009 9:31 am
- x 4
Re: Inverse Kinematics
I honestly don't understand your first question. As for the latter one, I don't actually remember the exact code I used, but you can check Jeff Lander's implementation over at darwin3d and do something similar.
-
johan07
- Greenskin
- Posts: 144
- Joined: Fri Dec 21, 2012 11:38 pm
Re: Inverse Kinematics
thanks for repling
for the first question ignore it because as i undestand now you have charcater without motion and you applicate ccd algorithm to reach somthing (target)
for the first question ignore it because as i undestand now you have charcater without motion and you applicate ccd algorithm to reach somthing (target)
-
johan07
- Greenskin
- Posts: 144
- Joined: Fri Dec 21, 2012 11:38 pm
Re: Inverse Kinematics
Hi again
with my stupid questions
the output of ccd algorithm is the joint orientation
how then you applicate this result to the charcter ?
if you do not undertand , i mean in frame rendred qued you make just bone->setorientation(result of ccd algorithm) in each frame ?
with my stupid questions
the output of ccd algorithm is the joint orientation
how then you applicate this result to the charcter ?
if you do not undertand , i mean in frame rendred qued you make just bone->setorientation(result of ccd algorithm) in each frame ?
-
kelmer
- Halfling
- Posts: 81
- Joined: Fri Dec 11, 2009 9:31 am
- x 4
Re: Inverse Kinematics
My implementation receives a reference so you would just call the function and the affected bones should be already rotated.
-
johan07
- Greenskin
- Posts: 144
- Joined: Fri Dec 21, 2012 11:38 pm
Re: Inverse Kinematics
so where is the time ?
you applicate then your algorithm to a one pose (posture) not in sequence of frames and posesMy implementation receives a reference so you would just call the function and the affected bones should be already rotated.