Koroldev Posted September 26, 2016 Share Posted September 26, 2016 Hi guys, I have little problem. There is a function, that rotates bone // type script function public static rotateBone(bone: BABYLON.Bone, quat: BABYLON.Quaternion): void { var result = bone.getLocalMatrix(); var xx = quat.x * quat.x; var yy = quat.y * quat.y; var zz = quat.z * quat.z; var xy = quat.x * quat.y; var zw = quat.z * quat.w; var zx = quat.z * quat.x; var yw = quat.y * quat.w; var yz = quat.y * quat.z; var xw = quat.x * quat.w; result.m[0] = 1.0 - (2.0 * (yy + zz)); result.m[1] = 2.0 * (xy + zw); result.m[2] = 2.0 * (zx - yw); result.m[3] = 0; result.m[4] = 2.0 * (xy - zw); result.m[5] = 1.0 - (2.0 * (zz + xx)); result.m[6] = 2.0 * (yz + xw); result.m[7] = 0; result.m[8] = 2.0 * (zx + yw); result.m[9] = 2.0 * (yz - xw); result.m[10] = 1.0 - (2.0 * (yy + xx)); result.m[11] = 0; result.m[15] = 1.0; } But this function rotates bone in local space, and I need rotetes bone in world space. What I should change in function? Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted September 26, 2016 Share Posted September 26, 2016 You can get a world space quaternion and transform it to a local space quaternion using inverse world matrix Quote Link to comment Share on other sites More sharing options...
Koroldev Posted September 26, 2016 Author Share Posted September 26, 2016 3 hours ago, Deltakosh said: You can get a world space quaternion and transform it to a local space quaternion using inverse world matrix Can you explain me more clearly? Because I am confusing in quternions and matrixes. 1. How can I get world space quaternion from bone? 2. When I get world quaternion, than I should change desired angle and convert new quaternion in local quaternion? 3. How to convert world quaternion to local and apply it to bone? Thank! Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted September 26, 2016 Share Posted September 26, 2016 1. bone.getWorldMatrix() 2. Matrix.Invert(bone.getWorldMatrix()) 3.var finalQuat = Quaternion.FromRotationMatrix(Matrix.Invert(bone.getWorldMatrix())) Quote Link to comment Share on other sites More sharing options...
Koroldev Posted September 27, 2016 Author Share Posted September 27, 2016 11 hours ago, Deltakosh said: 1. bone.getWorldMatrix() 2. Matrix.Invert(bone.getWorldMatrix()) 3.var finalQuat = Quaternion.FromRotationMatrix(Matrix.Invert(bone.getWorldMatrix())) Okay, I wrote code, and nothing happens var worldMat = this.boneTorsoDown.getWorldMatrix(); worldMat = worldMat.multiply(BABYLON.Matrix.RotationX(r)); var localMat = BABYLON.Matrix.Invert(worldMat); var quat = BABYLON.Quaternion.FromRotationMatrix(localMat); var result = this.boneTorsoDown.getLocalMatrix(); var xx = quat.x * quat.x; var yy = quat.y * quat.y; var zz = quat.z * quat.z; var xy = quat.x * quat.y; var zw = quat.z * quat.w; var zx = quat.z * quat.x; var yw = quat.y * quat.w; var yz = quat.y * quat.z; var xw = quat.x * quat.w; result.m[0] = 1.0 - (2.0 * (yy + zz)); result.m[1] = 2.0 * (xy + zw); result.m[2] = 2.0 * (zx - yw); result.m[3] = 0; result.m[4] = 2.0 * (xy - zw); result.m[5] = 1.0 - (2.0 * (zz + xx)); result.m[6] = 2.0 * (yz + xw); result.m[7] = 0; result.m[8] = 2.0 * (zx + yw); result.m[9] = 2.0 * (yz - xw); result.m[10] = 1.0 - (2.0 * (yy + xx)); result.m[11] = 0; result.m[15] = 1.0; Quote Link to comment Share on other sites More sharing options...
adam Posted September 27, 2016 Share Posted September 27, 2016 The only way I was able to get the WorldMatrix for a bone was by using the Mesh worldMatrix and the absoluteTransform of the bone. Take a look at the SkeletonViewer: https://github.com/BabylonJS/Babylon.js/blob/master/src/Debug/babylon.skeletonViewer.ts#L40 Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted September 28, 2016 Share Posted September 28, 2016 Yes Adam is correct. bone.getWorldMatrix is not enough as the bone matrix is applied to mesh world matrix Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.