Ckef01

Quaternion to 3x3 row major matrix

Aug 1st, 2012
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.56 KB | None | 0 0
  1. //-----------------------------------------------------------------------
  2. void quaternion::toMatrix(mat3 &mat) const
  3. {
  4.     float x2 = x + x;
  5.     float y2 = y + y;
  6.     float z2 = z + z;
  7.  
  8.     float wx = x2 * w;
  9.     float wy = y2 * w;
  10.     float wz = z2 * w;
  11.     float xx = x2 * x;
  12.     float xy = y2 * x;
  13.     float xz = z2 * x;
  14.     float yy = y2 * y;
  15.     float yz = z2 * y;
  16.     float zz = z2 * z;
  17.  
  18.     mat[0] = 1.0f - (yy + zz); mat[1] = xy - wz; mat[2] = xz + wy;
  19.     mat[3] = xy + wz; mat[4] = 1.0f - (xx + zz); mat[5] = yz - wx;
  20.     mat[6] = xz - wy; mat[7] = yz + wx; mat[8] = 1.0f - (xx + yy);
  21. }
Advertisement
Add Comment
Please, Sign In to add comment