adam Posted July 1, 2015 Share Posted July 1, 2015 I'm trying to get the initial euler angles of the bones right when my model is loaded. I tried this:bone.getLocalMatrix().decompose(vec1, quat, vec2);quat.toEulerAnglesToRef(vec3); but the values I'm getting in vec3 are not correct. The angles I want are relative to the parent bone. Quote Link to comment Share on other sites More sharing options...
Dad72 Posted July 1, 2015 Share Posted July 1, 2015 have you try a Vector4() and not Vector3 for EuleurAngles Quote Link to comment Share on other sites More sharing options...
adam Posted July 1, 2015 Author Share Posted July 1, 2015 I didn't. toEulerAnglesToRef takes a Vector3:public toEulerAnglesToRef(result: Vector3): Quaternion { //result is an EulerAngles in the in the z-x-z convention var qx = this.x; var qy = this.y; var qz = this.z; var qw = this.w; var qxy = qx * qy; var qxz = qx * qz; var qwy = qw * qy; var qwz = qw * qz; var qwx = qw * qx; var qyz = qy * qz; var sqx = qx * qx; var sqy = qy * qy; var determinant = sqx + sqy; if (determinant !== 0.000 && determinant !== 1.000) { result.x = Math.atan2(qxz + qwy, qwx - qyz); result.y = Math.acos(1 - 2 * determinant); result.z = Math.atan2(qxz - qwy, qwx + qyz); } else { if (determinant === 0.0) { result.x = 0.0; result.y = 0.0; result.z = Math.atan2(qxy - qwz, 0.5 - sqy - qz * qz); //actually, degeneracy gives us choice with x+z=Math.atan2(qxy-qwz,0.5-sqy-qz*qz) } else //determinant == 1.000 { result.x = Math.atan2(qxy - qwz, 0.5 - sqy - qz * qz); //actually, degeneracy gives us choice with x-z=Math.atan2(qxy-qwz,0.5-sqy-qz*qz) result.y = Math.PI; result.z = 0.0; } } return this; } Quote Link to comment Share on other sites More sharing options...
adam Posted July 1, 2015 Author Share Posted July 1, 2015 I just notice this comment in the toEulerAnglesToRef function: //result is an EulerAngles in the in the z-x-z convention I'm thinking I'm going have to do some research on how to get an x-y-z euler from a matrix. Heck, I'll probably just end up hard coded the angles into my code. Quote Link to comment Share on other sites More sharing options...
jahow Posted July 2, 2015 Share Posted July 2, 2015 Hi, I'm not very familiar with all this, but it seems the conversion from z-x-z to x-y-z convention is pretty complicated. Basically you're looking to have the yaw/pitch/roll angles of your bone, right? If that's what you specifically need, then I guess BabylonJS doesn't have the right function for you. Although transforming a quaternion to x-y-z euler angles should be as feasible as what's currently implemented. At any rate, please keep us informed on your progress: rotation issues are common and sometimes complicated, especially with quaternions involved. Quote Link to comment Share on other sites More sharing options...
adam Posted July 3, 2015 Author Share Posted July 3, 2015 I just needed the z angle of the bones. This is what ended up working for me:var ang = Math.atan2(boneLocalMatrix.m[4], boneLocalMatrix.m[5]); GameMonetize 1 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.