码迷,mamicode.com
首页 > 其他好文 > 详细

四元数转化为矩阵

时间:2016-11-22 23:22:30      阅读:313      评论:0      收藏:0      [点我收藏+]

标签:from   float   mat   矩阵   ati   ret   blog   基于   object   

 1 /**
 2  *   /  R[ 0]   R[ 1]   R[ 2]   0   3  *   |  R[ 4]   R[ 5]   R[ 6]   0  |
 4  *   |  R[ 8]   R[ 9]   R[10]   0  |
 5  *   \  0       0       0       1  /
 6  */
 7 + (GLKMatrix4)getRotationMatrixFromQuaternion:(CMQuaternion*)quaternion{
 8     float xx = quaternion->x * quaternion->x;
 9     float yy = quaternion->y * quaternion->y;
10     float zz = quaternion->z * quaternion->z;
11     float xy = quaternion->x * quaternion->y;
12     float wz = quaternion->w * quaternion->z;
13     float wy = quaternion->w * quaternion->y;
14     float xz = quaternion->x * quaternion->z;
15     float yz = quaternion->y * quaternion->z;
16     float wx = quaternion->w * quaternion->x;
17     
18     float r00 = 1 - 2 * (yy + zz);
19     float r01 = 2 * (xy - wz);
20     float r02 = 2 * (wy + xz);
21     float r03 = 0;
22     
23     float r10 = 2 * (xy + wz);
24     float r11 = 1 - 2 * (xx + zz);
25     float r12 = 2 * (yz - wx);
26     float r13 = 0;
27     
28     float r20 = 2 * (xz - wy);//不是 xy - wy
29     float r21 = 2 * (yz + wx);
30     float r22 = 1 - 2 * (xx + yy);
31     float r23 = 0;
32     
33     float r30 = 0;
34     float r31 = 0;
35     float r32 = 0;
36     float r33 = 1;
37     
38     return GLKMatrix4Make(r00,r01,r02,r03,
39                       r10,r11,r12,r13,
40                       r20,r21,r22,r23,
41                       r30,r31,r32,r33);
42 }

本方法是基于Objective-C实现。

四元数转化为矩阵

标签:from   float   mat   矩阵   ati   ret   blog   基于   object   

原文地址:http://www.cnblogs.com/calence/p/6091129.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!