lookAt() modification

Hi all, and merry christmas.

I've a problem in one of my spare time projects that has been bugging me for quite a while. I'm playing with an IK implementation and my bones simply won't do what i want.

My plan is to modify the Quaternion.lookAt() method:

public void lookAt(Vector3f direction, Vector3f up ) {
        tmpZaxis.set( direction ).normalizeLocal();
        tmpXaxis.set( up ).crossLocal( direction ).normalizeLocal();
        tmpYaxis.set( direction ).crossLocal( tmpXaxis ).normalizeLocal();
        fromAxes( tmpXaxis, tmpYaxis, tmpZaxis );

I use a rig from blender, which has Y going along the length of the bone. I think i've now tried every combination of axis changing/flipping, but the bones never point where they're supposed to, and i must now admit that my grasp of quaternions is rather weak. It seems it shouldn't be that hard for someone with better understanding of math.
To summarize what i want help with:
I'd like to have the bone point towards "direction", but along the Y axis, rather than Z.


Thanks ttrocha.

I had noticed your modification, but thought it was a separate issue that i needed to look at after this was fixed. I'll apply it now and see if it solves my problem.



Ok, i've modified my lookAt() to use ttrocha's addition as well, and there seems to be better consistency in the bones now. I still don't get the results i'm after though, and i would appreciate if someone could fill me in on some quaternion stuff.

I've thought a bit more about what it is i want to achieve, and if i use a standard Quaternion.lookAt(), i think i need to rotate it 90 degrees around the X-axis, and 90 degrees around the Z-axis.

And to clear up my original explanation; i need the Y-axis to be "forward", along the "dir".

Alternatively, i think it would solve my problems if there was a way in blender to change how bones are aligned, so that Z is going along the length of the bone, rather than Y. Does anyone know if that is possible?