1 static void vneg (float *res
, float *v
)
8 static void vadd (float *res
, float *v1
, float *v2
)
10 res
[0] = v1
[0] + v2
[0];
11 res
[1] = v1
[1] + v2
[1];
12 res
[2] = v1
[2] + v2
[2];
15 static void vsub (float *res
, float *v1
, float *v2
)
17 res
[0] = v1
[0] - v2
[0];
18 res
[1] = v1
[1] - v2
[1];
19 res
[2] = v1
[2] - v2
[2];
22 static void qconjugate (float *res
, float *q
)
28 static void qapply (float *res
, float *q
, float *v
)
37 float t2
, t3
, t4
, t5
, t6
, t7
, t8
, t9
, t10
;
47 res
[0] = 2*( (t8
+ t10
)*v1
+ (t6
- t4
)*v2
+ (t3
+ t7
)*v3
) + v1
;
48 res
[1] = 2*( (t4
+ t6
)*v1
+ (t5
+ t10
)*v2
+ (t9
- t2
)*v3
) + v2
;
49 res
[2] = 2*( (t7
- t3
)*v1
+ (t2
+ t9
)*v2
+ (t5
+ t8
)*v3
) + v3
;
52 static void qcompose (float *res
, float *q1
, float *q2
)
54 res
[0] = q1
[3]*q2
[0] + q1
[0]*q2
[3] + q1
[1]*q2
[2] - q1
[2]*q2
[1];
55 res
[1] = q1
[3]*q2
[1] + q1
[1]*q2
[3] + q1
[2]*q2
[0] - q1
[0]*q2
[2];
56 res
[2] = q1
[3]*q2
[2] + q1
[2]*q2
[3] + q1
[0]*q2
[1] - q1
[1]*q2
[0];
57 res
[3] = q1
[3]*q2
[3] - q1
[0]*q2
[0] - q1
[1]*q2
[1] - q1
[2]*q2
[2];
61 static void q2matrixt (float *mat
, float *q
, float *v
)
80 mat
[0] = 1 - 2 * ( yy
+ zz
);
81 mat
[1] = 2 * ( xy
- zw
);
82 mat
[2] = 2 * ( xz
+ yw
);
84 mat
[4] = 2 * ( xy
+ zw
);
85 mat
[5] = 1 - 2 * ( xx
+ zz
);
86 mat
[6] = 2 * ( yz
- xw
);
88 mat
[8] = 2 * ( xz
- yw
);
89 mat
[9] = 2 * ( yz
+ xw
);
90 mat
[10] = 1 - 2 * ( xx
+ yy
);
107 static void mapply_to_point (float *res
, float *m
, float *v
)
112 res
[0] = x
*m
[0] + y
*m
[4] + z
*m
[8] + m
[MAT_V0
];
113 res
[1] = x
*m
[1] + y
*m
[5] + z
*m
[9] + m
[MAT_V1
];
114 res
[2] = x
*m
[2] + y
*m
[6] + z
*m
[10] + m
[MAT_V2
];
117 static void mapply_to_vector (float *res
, float *m
, float *v
)
122 res
[0] = x
*m
[0] + y
*m
[4] + z
*m
[8];
123 res
[1] = x
*m
[1] + y
*m
[5] + z
*m
[9];
124 res
[2] = x
*m
[2] + y
*m
[6] + z
*m
[10];
127 static void vaddto (float *v1
, float *v2
)
134 static void vcopy (float *res
, float *v
)
143 static void q2matrixt (float *mat
, float *q
, float *v
)
162 mat
[0] = 1 - 2 * ( yy
+ zz
);
163 mat
[4] = 2 * ( xy
- zw
);
164 mat
[8] = 2 * ( xz
+ yw
);
166 mat
[1] = 2 * ( xy
+ zw
);
167 mat
[5] = 1 - 2 * ( xx
+ zz
);
168 mat
[9] = 2 * ( yz
- xw
);
170 mat
[2] = 2 * ( xz
- yw
);
171 mat
[6] = 2 * ( yz
+ xw
);
172 mat
[10] = 1 - 2 * ( xx
+ yy
);