Jump to content

setRotation problem by useWorldTransform (Gimbal Lock)


photo

Recommended Posts

In the process of setting up the transformation, rotate using a quaternion. but Why does the Gimbal lock occur?

 

ex) node->SetWorldTransform(node->getWorldTransform()*rotate(quat(20,90,0)));

ex)handsample->setWorldBoneTransform(13, handsample->getWorldBoneTransform(13)*(Mat4)rotate(quat(40, 90, 0)));

     handsample->setWorldBoneTransform(13, (Mat4)rotate(quat(40, 90, 0)));

 

The SetBoneRotation () function in the Utils file in the VRtemplete project has the same problem.

image.png.e49eecb93455434eb0ea1a36e7c2070e.png

 

I tested using this hand model(upload file).

How do I apply a Rotation with a quaternion without a gimbal Lock? (To node or bone transform)

Hand_rigged.3DS

Hand_rigged.FBX

Hand_rigged.FBX.meta

Hand_reflect.jpg

Hand_difuse.jpg

material #16.mat

material #16.mat.meta

Edited by dongju.jeong
Link to comment

Please, tell us in more detail how you get Gimbal lock.
Maybe a video or a simple example?

 

In the VRTemplate, I see such code

void setBoneRotation(ObjectMeshSkinnedPtr &skin, int boneNum, const quat &rot)
{
    mat4 transform = skin->getBoneTransform(boneNum);
    mat3 rotMat = rot.getMat3();
    transform.setColumn3(0, rotMat.getColumn(0));
    transform.setColumn3(1, rotMat.getColumn(1));
    transform.setColumn3(2, rotMat.getColumn(2));
    skin->setBoneChildrenTransform(boneNum, transform);
}

without WorldBoneTransform, maybe this is a mistake?

Link to comment

void setBoneRotation(ObjectMeshSkinnedPtr &skin, int boneNum, const quat &rot, const vec3 &scale)
{
    mat4 transform = skin->getBoneTransform(boneNum);
    mat3 rotMat = rot.getMat3();
    transform.setColumn3(0, vec3(rotMat.getColumn(0)));
    transform.setColumn3(1, vec3(rotMat.getColumn(1)));
    transform.setColumn3(2, vec3(rotMat.getColumn(2)));
    transform *= (mat4)Math::scale(scale);
    skin->setBoneTransform(boneNum, transform);
}

I use this on test.

 

 

OnUpdate()

{

   static float i = 0;
   i += 0.5f;
   setBoneRotation(handsample, 13, quat(i,90,0),vec3(0.001));  or   setBoneRotation(handsample, 13, quat(0,90,i),vec3(0.001)); 

}

 

Both rotate relative to the local Z axis.

when use "setBoneRotation(handsample, 13, quat(i,90,0),vec3(0.001));" ,  How can I programing rotate  relative to the changed local x axis?

 

and when using SetWorldBoneTransform() too.

 

Edited by dongju.jeong
Link to comment

you can try split rotation quat(i, 90, 0) as two rotation quat(0, 90, 0) * quat(i, 0, 0) to avoid Gimbal lock.

Also, we recomended use another constructor quat(vec3 axis, float angle) for rotation arround any axis, without use Euler Rotation.

  • Like 1
Link to comment

thank you.

 

When I only know the some destination  matrix( such as leapmotion's hand.basis), how do you rotate it using the quat (axis, angle) function?

using destination matrix, I can calculate how many need degree values each in the world standard X axis,  Y axis, and  Z axis.

But I do not know how to rotate with quat (axis, angle) at once.

Link to comment

I got ploblem about rotate this hand model bone using leapmotion bone basis matrix.

I try to test base on left hand.  But I do not understand this sentence . "You can change from right-hand to left-hand rule by multiplying the z basis vector by -1."

 

How I use leapmotion bone basis value for hand model bones.?

first, I do this.

 

Mat4 basis = Mat4(offsetHead)*Mat4(bones[a].basis);      //bones[a] is some finger's bone.

quat Rotate = quat(basis.getRotate().getAngle(vec3(-1, 0, 0)),
                    basis.getRotate().getAngle(vec3(0, 1, 0)),
                    basis.getRotate().getAngle(vec3(0, 0, -1)));

Edited by dongju.jeong
Link to comment
Quote

"You can change from right-hand to left-hand rule by multiplying the z basis vector by -1."

it's about how to translate from leapmotion coordinate system(left) to world(right) and backward. 

basis.setColumn3(2, basis.getColumn3(2) * -1);

a465e4c5-b6ca-4006-a40e-1aa9ad2ebc5d.png

you can also look at an example Samples/3rd party/other/LeapMotionVisualizer  

  • Like 1
Link to comment
×
×
  • Create New...