Author Topic: Manually rotate joints using quaternion input  (Read 3912 times)

nikola

• byte
• Posts: 6
Manually rotate joints using quaternion input
« on: October 20, 2013, 10:15:35 pm »
Hello! I am participating in a small project aiming to create Motion capturing system. I must create some kind of visual representation of the collected data.

For input I have quaternions representing the rotation of different body parts. I took a look at ProceduralAnimationSample and modified ( deleted what I didn't understand ) targetJoint function. It now looks like this:

Code: [Select]
`private void targetJoint(SkeletonPose pose, int jointIndex, float x, float y,    float z, float w) {            final int parentIndex = pose.getSkeleton().getJoint(jointIndex).getParentIndex();        // neckBindGlobalTransform is the neck bone -> model space transform. essentially, it is the world transform of        // the neck bone in bind pose.        final Matrix jointInverseBindPose = pose.getSkeleton().getJoint(jointIndex).getInverseBindPose();        final Matrix jointBindPose = jointInverseBindPose.invert();        Quaternion quat = new Quaternion(x,y,z,w);        final Matrix subGlobal = quat.getRotationMatrix();                // now remove the global/world transform of the neck's parent bone, leaving us with just the local transform of        // neck + rotation.        subGlobal.matMul(jointBindPose);        subGlobal.matMul(pose.getSkeleton().getJoint(parentIndex).getInverseBindPose();        // set that as the neck's transform !!        pose.getLocal(jointIndex).setTo(subGlobal);    }`
I set left and right foreams of Seymor model with sample quaternion and expected them to point at same direction. But the angles were mirrored which I think has something to do with the joints unrotated orientation. I really don't get how these things work and I am missing the bigger picture. So please help me to make the joints point the same direction when I rotate them with one and the same quaternion. I really spent more than 10 hours and couldn't figure it out. As you can see English is not my native language and not a skilled Java person or mathematician ( just hardware guy ). Thank you

raft

• Moderator
• Posts: 1984
Re: Manually rotate joints using quaternion input
« Reply #1 on: October 20, 2013, 11:03:18 pm »
well, to tell the truth I'm not proficient in programatically changing directions of joints

I suppose, what you experience happens because all joints' transforms are in their parent joint's space (relative to their parent). left and right arms are mirrored so any same transform applied to their children results in mirrored look.

have you tried applying mirror of rotation to other arm?

nikola

• byte
• Posts: 6
Re: Manually rotate joints using quaternion input
« Reply #2 on: October 22, 2013, 07:41:57 am »
The point is that the quaternion represents the rotation of a part of the body. It is very important for it to be very precise. I want to eliminate the dependecy between the joint and it's parent. I know it is a hierachical system and this would require some serious math ( serious for me ). I have done this in Blender and it handles these things well. It's just I don't know where to start?

raft

• Moderator
• Posts: 1984
Re: Manually rotate joints using quaternion input
« Reply #3 on: October 22, 2013, 10:03:15 pm »
I'm sure you do that calculation but I cant figure how at the moment, and I'm too busy nowadays to try it.

but I guess, if left and right arms are precisely mirrored, mirroring rotation will give you a precise result.

nikola

• byte
• Posts: 6
Re: Manually rotate joints using quaternion input
« Reply #4 on: October 23, 2013, 04:58:40 pm »
I will apreciate any help if you have time

raft

• Moderator
• Posts: 1984
Re: Manually rotate joints using quaternion input
« Reply #5 on: October 26, 2013, 10:24:09 pm »
I bet Egon can write it without difficulty. he has a huge experience with transforms in relative spaces

EgonOlsen

• Posts: 11899
Re: Manually rotate joints using quaternion input
« Reply #6 on: October 29, 2013, 08:19:20 pm »
I'm not sure if i event get the requirements!? You want to decouple a joint from it's parents? I understand that you get data from some hardware for motion capturing and that you want to display it. So...what you actually want is to create different animation frames based on that data!?

raft

• Moderator
• Posts: 1984
Re: Manually rotate joints using quaternion input
« Reply #7 on: October 29, 2013, 11:21:31 pm »
I guess making a joint look at a certain direction with some certain rotation will be a great start

EgonOlsen

• Posts: 11899
Re: Manually rotate joints using quaternion input
« Reply #8 on: October 30, 2013, 09:33:03 pm »
I'm not sure...reading the actual post, i wanted to make sure that a solution to this would solve the actual problem. I don't see the relation between motion capturing and joint rotations!?

raft

• Moderator
• Posts: 1984
Re: Manually rotate joints using quaternion input
« Reply #9 on: October 30, 2013, 09:59:03 pm »
I guess it will solve the problem:
* we have all joint directions and rotations as data. applying them to joints starting from root joint will get us to same skeleton pose.
* even if not, it will be of great help for other purposes

nikola

• byte
• Posts: 6
Re: Manually rotate joints using quaternion input
« Reply #10 on: November 04, 2013, 10:14:18 am »
Hello again. Sorry for the late post,but I had some other things to do.

My question is: What is the right way ( most accurate ) to set joint rotation ( or whatever it is ) using quaternions ?

Also if you can tell me if there are any docs describing how joints work or everything related to their usage in Bones it would be great. I know my previous questions were weird, but I did not have time or the proper docs to do a proper research.

raft

• Moderator
• Posts: 1984
Re: Manually rotate joints using quaternion input
« Reply #11 on: November 04, 2013, 09:18:31 pm »
I cannot point you to a specific doc but it's a standard skeletal animation system. you can find many docs on the internet.

nikola

• byte
• Posts: 6
Re: Manually rotate joints using quaternion input
« Reply #12 on: November 06, 2013, 09:15:46 am »
Another question: How can I enable some kind of hardware rendering on ProceduralAnimationExample demo?

I am trying to work with MakeHuman model and the software renderer is pretty slow. Thanks in advance

raft

• Moderator
• Posts: 1984
Re: Manually rotate joints using quaternion input
« Reply #13 on: November 06, 2013, 09:36:21 am »
you should port the sample to a HW renderer. start with jPCT's HelloWorld sample for basic setup.

There are three HW renderers, GLRenderer, AWTGLRenderer and JOGLRenderer. GLRenderer is the easiest one to start and also the suggested one but you cannot use regular Java GUI elements on top of it. but that is not much important for this case IMHO. If required you can use use GLFont to render basic text on top of it.

nikola

• byte
• Posts: 6
Re: Manually rotate joints using quaternion input
« Reply #14 on: December 12, 2013, 08:21:32 pm »
I have another question. So far I have worked with "naked" makeHuman model ( model with only one texture file ). However now I have to make a demo with a model with some clothes on. MakeHuman exports the model with multiple texture files ( PNG ). How can I load multiple texture file and apply them on the makeHuman model?

Also I did not have time to port the sample to hardware renderer ( my java knowledge is basic ), but I found this topic about enabling multicore support to the software renderer. It might help but I just don't get it. Can someone explain where should I put the lines from the topic?