简体   繁体   中英

JavaScript gl-matrix: quaternion from mat4

I'm using gl-matrix lib ( https://github.com/toji/gl-matrix ) There is a possibility to create mat3 from quat and quat from mat3:

  • mat3.fromQuat
  • quat.fromMat3

But I have mat4 rotation matrix. I create it this way:

var turnmat = mat4.create();
mat4.identity(turnmat);

mat4.rotate(turnmat,turnmat, yaw,   [0, 1, 0]);
mat4.rotate(turnmat,turnmat, pitch, [1, 0, 0]);
mat4.rotate(turnmat,turnmat, roll,  [0, 0, 1]);

And then I want quat from this matrix. But there is only quat.fromMat3, not quat.fromMat4. What do I do wrong here?

refs (no rep to add as links):

http:// glmatrix.net/docs/2.2.0/symbols/mat3.html#.fromQuat

http:// glmatrix.net/docs/2.2.0/symbols/quat.html#.fromMat3

The quaternions as defined in gl-matrix are for 3D spaces only. What you want to do is to get the 3D rotation component out of your Mat4 and convert that to a quaternion.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM