Remove pointless variable
[dormin.git] / vec.c
blob8b011138e6e681e54bad3495d59f1fe111c33d58
1 static void vneg (float *res, float *v)
3 res[0] = -v[0];
4 res[1] = -v[1];
5 res[2] = -v[2];
8 static void vcopy (float *res, float *v)
10 *res++ = *v++;
11 *res++ = *v++;
12 *res++ = *v++;
15 static void vadd (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 vsub (float *res, float *v1, float *v2)
24 res[0] = v1[0] - v2[0];
25 res[1] = v1[1] - v2[1];
26 res[2] = v1[2] - v2[2];
29 static void qconjugate (float *res, float *q)
31 vneg (res, q);
32 res[3] = q[3];
35 static float qmagnitude (float *q)
37 return sqrt (q[0]*q[0]+q[1]*q[1]+q[2]*q[2]+q[3]*q[3]);
40 static void qapply (float *res, float *q, float *v)
42 float a = -q[3];
43 float b = q[0];
44 float c = q[1];
45 float d = q[2];
46 float v1 = v[0];
47 float v2 = v[1];
48 float v3 = v[2];
49 float t2, t3, t4, t5, t6, t7, t8, t9, t10;
50 t2 = a*b;
51 t3 = a*c;
52 t4 = a*d;
53 t5 = -b*b;
54 t6 = b*c;
55 t7 = b*d;
56 t8 = -c*c;
57 t9 = c*d;
58 t10 = -d*d;
59 res[0] = 2*( (t8 + t10)*v1 + (t6 - t4)*v2 + (t3 + t7)*v3 ) + v1;
60 res[1] = 2*( (t4 + t6)*v1 + (t5 + t10)*v2 + (t9 - t2)*v3 ) + v2;
61 res[2] = 2*( (t7 - t3)*v1 + (t2 + t9)*v2 + (t5 + t8)*v3 ) + v3;
64 static void qscale (float *res, float *q, float scale)
66 *res++ = *q++ * scale;
67 *res++ = *q++ * scale;
68 *res++ = *q++ * scale;
69 *res++ = *q++ * scale;
72 static void qcompose (float *res, float *q1, float *q2)
74 res[0] = q1[3]*q2[0] + q1[0]*q2[3] + q1[1]*q2[2] - q1[2]*q2[1];
75 res[1] = q1[3]*q2[1] + q1[1]*q2[3] + q1[2]*q2[0] - q1[0]*q2[2];
76 res[2] = q1[3]*q2[2] + q1[2]*q2[3] + q1[0]*q2[1] - q1[1]*q2[0];
77 res[3] = q1[3]*q2[3] - q1[0]*q2[0] - q1[1]*q2[1] - q1[2]*q2[2];
80 static void q2matrixt (float *mat, float *q, float *v)
82 float X = q[0];
83 float Y = q[1];
84 float Z = q[2];
85 float W = q[3];
87 float xx = X * X;
88 float xy = X * Y;
89 float xz = X * Z;
90 float xw = X * W;
92 float yy = Y * Y;
93 float yz = Y * Z;
94 float yw = Y * W;
96 float zz = Z * Z;
97 float zw = Z * W;
99 mat[0] = 1 - 2 * ( yy + zz );
100 mat[1] = 2 * ( xy - zw );
101 mat[2] = 2 * ( xz + yw );
103 mat[4] = 2 * ( xy + zw );
104 mat[5] = 1 - 2 * ( xx + zz );
105 mat[6] = 2 * ( yz - xw );
107 mat[8] = 2 * ( xz - yw );
108 mat[9] = 2 * ( yz + xw );
109 mat[10] = 1 - 2 * ( xx + yy );
111 #ifdef USE_ALTIVEC
112 mat[12] = v[0];
113 mat[13] = v[1];
114 mat[14] = v[2];
115 #else
116 mat[3] = v[0];
117 mat[7] = v[1];
118 mat[11] = v[2];
119 #endif
122 static void q2matrix (float *mat, float *q)
124 float z[3] = {0,0,0};
125 q2matrixt (mat, q, z);
128 static void mscale (float *res, float *m, float s)
130 int i;
131 for (i = 0; i < 12; ++i) *res++ = *m++ * s;
134 static void mapply_to_point (float *res, float *m, float *v)
136 float x = v[0];
137 float y = v[1];
138 float z = v[2];
139 res[0] = x*m[0] + y*m[4] + z*m[8] + m[3];
140 res[1] = x*m[1] + y*m[5] + z*m[9] + m[7];
141 res[2] = x*m[2] + y*m[6] + z*m[10] + m[11];
144 static void mapply_to_vector (float *res, float *m, float *v)
146 float x = v[0];
147 float y = v[1];
148 float z = v[2];
149 res[0] = x*m[0] + y*m[4] + z*m[8];
150 res[1] = x*m[1] + y*m[5] + z*m[9];
151 res[2] = x*m[2] + y*m[6] + z*m[10];
154 static void vaddto (float *v1, float *v2)
156 v1[0] += v2[0];
157 v1[1] += v2[1];
158 v1[2] += v2[2];