Page 1 of 1

how to convert the left-handed coordinate to right-handed?

Posted: Mon Nov 12, 2012 3:35 am
by wuallen
I searched the forum but don't find the answers. I readed a post of irrlicht and havok intergation and try. The rigid bodies motion in irrlicht and in havok are different, like a mirror. The convertion from havok to irrlicht is correct, but the convertion from irrlicht to havok is not correct!

I used this code:
irr::corse::vector3f rot(10.0f, 10.0f, 10.0f);
node->setRotation(rot);
print transform of node...

hkTransform trans1,trans2,trans3;
trans1.set(hkVector(1,0,0), rot.X);
trans2.set(hkvector(0,1,0), rot.Y);
trans3.set(hkVector(0,0,1), -rot.Z);
trans1.setMulEq(trans2);
trans1.setMulEq(trans3);
trans1.m(2,0) *= -1;
trans1.m(2,1) *= -1;
trans1.m(0,2) *= -1;
trans1.m(1,2) *= -1;
print transfrom of havok transform...

two prints of irrlicht and havok are same, but two rotations are not same.

anyone knows the answer please tell me!

My english is very bad then I say sorry!

Re: how to convert the left-handed coordinate to right-hande

Posted: Mon Nov 12, 2012 5:18 am
by codetiger
I've never tried Havok, but I recently tried converting meshes from RH to LH. Irrlicht uses LH as far as I understand. To convert from RH (blender software) to RH (Irrlicht):

1) Flip x coords of the verts. x = -x;
1) Flip x normals of the verts. x = -x;
2) Flip surface
3) flip y in texcoords. y = 1- y;

Re: how to convert the left-handed coordinate to right-hande

Posted: Mon Nov 12, 2012 8:56 am
by wuallen
wuallen wrote:I searched the forum but don't find the answers. I readed a post of irrlicht and havok intergation and try. The rigid bodies motion in irrlicht and in havok are different, like a mirror. The convertion from havok to irrlicht is correct, but the convertion from irrlicht to havok is not correct!

I used this code:
irr::corse::vector3f rot(10.0f, 10.0f, 10.0f);
node->setRotation(rot);
print transform of node...

hkTransform trans1,trans2,trans3;
trans1.set(hkVector(1,0,0), rot.X);
trans2.set(hkvector(0,1,0), rot.Y);
trans3.set(hkVector(0,0,1), -rot.Z);
trans1.setMulEq(trans2);
trans1.setMulEq(trans3);
trans1.m(2,0) *= -1;
trans1.m(2,1) *= -1;
trans1.m(0,2) *= -1;
trans1.m(1,2) *= -1;
print transfrom of havok transform...

two prints of irrlicht and havok are same, but two rotations are not same.

anyone knows the answer please tell me!

My english is very bad then I say sorry!
I tried the code and finded my faults.
trans1.set(hkVector(1,0,0), rot.X);
trans2.set(hkvector(0,1,0), rot.Y);
trans3.set(hkVector(0,0,1), -rot.Z);
It should be written like this:
trans2.set(hkvector(0,1,0), rot.Y);
trans1.set(hkVector(1,0,0), rot.X);
trans3.set(hkVector(0,0,1), -rot.Z);

this code is working! But I feel that effects of rotation is not really well.

Re: how to convert the left-handed coordinate to right-hande

Posted: Mon Nov 12, 2012 5:38 pm
by devsh
invert [12] float in the matrix array

Re: how to convert the left-handed coordinate to right-hande

Posted: Wed Nov 14, 2012 3:31 am
by wuallen
I just found the answer. How to convert left-handed coordinate to right-handed is represented as follow:
irr::core::matrix4 irr_mat;
irr_mat.setRotationDegrees(m_rotation);
irr_mat(2, 1) *= -1;
irr_mat(2, 0) *= -1;
irr_mat(0, 2) *= -1;
irr_mat(1, 2) *= -1;
hkTransform phy_mat;
phy_mat.setRows4(
hkVector4(irr_mat(0, 0), irr_mat(1, 0), irr_mat(2, 0), irr_mat(3, 0)),
hkVector4(irr_mat(0, 1), irr_mat(1, 1), irr_mat(2, 1), irr_mat(3, 1)),
hkVector4(irr_mat(0, 2), irr_mat(1, 2), irr_mat(2, 2), irr_mat(3, 2)),
hkVector4(irr_mat(0, 3), irr_mat(1, 3), irr_mat(2, 3), irr_mat(3, 3)));
phy_mat.setTranslation(hkVector4(m_position.X, m_position.Y, -m_position.Z));