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
);
104 static void mapply_to_point (float *res
, float *m
, float *v
)
109 res
[0] = x
*m
[0] + y
*m
[4] + z
*m
[8] + m
[3];
110 res
[1] = x
*m
[1] + y
*m
[5] + z
*m
[9] + m
[7];
111 res
[2] = x
*m
[2] + y
*m
[6] + z
*m
[10] + m
[11];
114 static void mapply_to_vector (float *res
, float *m
, float *v
)
119 res
[0] = x
*m
[0] + y
*m
[4] + z
*m
[8];
120 res
[1] = x
*m
[1] + y
*m
[5] + z
*m
[9];
121 res
[2] = x
*m
[2] + y
*m
[6] + z
*m
[10];
124 static void vaddto (float *v1
, float *v2
)
131 static void vcopy (float *res
, float *v
)
141 static void q2matrixt (float *mat
, float *q
, float *v
)
160 mat
[0] = 1 - 2 * ( yy
+ zz
);
161 mat
[4] = 2 * ( xy
- zw
);
162 mat
[8] = 2 * ( xz
+ yw
);
164 mat
[1] = 2 * ( xy
+ zw
);
165 mat
[5] = 1 - 2 * ( xx
+ zz
);
166 mat
[9] = 2 * ( yz
- xw
);
168 mat
[2] = 2 * ( xz
- yw
);
169 mat
[6] = 2 * ( yz
+ xw
);
170 mat
[10] = 1 - 2 * ( xx
+ yy
);