Manually rotate joints using quaternion input

Started by nikola, October 20, 2013, 10:15:35 PM

Previous topic - Next topic

nikola

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:


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

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

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

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


raft

I bet Egon can write it without difficulty. he has a huge experience with transforms in relative spaces

EgonOlsen

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

I guess making a joint look at a certain direction with some certain rotation will be a great start

EgonOlsen

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

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

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

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

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

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

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?

Thanks in advance :)