86 void fm_inverseRT(
const double *matrix,
const double *pos,
double *t)
89 double _x = pos[0] - matrix[3*4+0];
90 double _y = pos[1] - matrix[3*4+1];
91 double _z = pos[2] - matrix[3*4+2];
95 t[0] = (matrix[0*4+0] * _x) + (matrix[0*4+1] * _y) + (matrix[0*4+2] * _z);
96 t[1] = (matrix[1*4+0] * _x) + (matrix[1*4+1] * _y) + (matrix[1*4+2] * _z);
97 t[2] = (matrix[2*4+0] * _x) + (matrix[2*4+1] * _y) + (matrix[2*4+2] * _z);
134 void fm_getAABB(
unsigned int vcount,
const double *points,
unsigned int pstride,
double *bmin,
double *bmax)
137 const unsigned char *source = (
const unsigned char *) points;
148 for (
unsigned int i=1; i<vcount; i++)
151 const double *p = (
const double *) source;
153 if ( p[0] < bmin[0] ) bmin[0] = p[0];
154 if ( p[1] < bmin[1] ) bmin[1] = p[1];
155 if ( p[2] < bmin[2] ) bmin[2] = p[2];
157 if ( p[0] > bmax[0] ) bmax[0] = p[0];
158 if ( p[1] > bmax[1] ) bmax[1] = p[1];
159 if ( p[2] > bmax[2] ) bmax[2] = p[2];
171 double cr = cos(roll);
172 double cp = cos(pitch);
173 double cy = cos(yaw);
175 double sr = sin(roll);
176 double sp = sin(pitch);
177 double sy = sin(yaw);
179 double cpcy = cp * cy;
180 double spsy = sp * sy;
181 double spcy = sp * cy;
182 double cpsy = cp * sy;
184 quat[0] = ( sr * cpcy - cr * spsy);
185 quat[1] = ( cr * spcy + sr * cpsy);
186 quat[2] = ( cr * cpsy - sr * spcy);
187 quat[3] = cr * cpcy + sr * spsy;
193 double xx = quat[0]*quat[0];
194 double yy = quat[1]*quat[1];
195 double zz = quat[2]*quat[2];
196 double xy = quat[0]*quat[1];
197 double xz = quat[0]*quat[2];
198 double yz = quat[1]*quat[2];
199 double wx = quat[3]*quat[0];
200 double wy = quat[3]*quat[1];
201 double wz = quat[3]*quat[2];
203 matrix[0*4+0] = 1 - 2 * ( yy + zz );
204 matrix[1*4+0] = 2 * ( xy - wz );
205 matrix[2*4+0] = 2 * ( xz + wy );
207 matrix[0*4+1] = 2 * ( xy + wz );
208 matrix[1*4+1] = 1 - 2 * ( xx + zz );
209 matrix[2*4+1] = 2 * ( yz - wx );
211 matrix[0*4+2] = 2 * ( xz - wy );
212 matrix[1*4+2] = 2 * ( yz + wx );
213 matrix[2*4+2] = 1 - 2 * ( xx + yy );
215 matrix[3*4+0] = 0.0f;
216 matrix[3*4+1] = 0.0f;
217 matrix[3*4+2] = 0.0f;
219 matrix[0*4+3] = 0.0f;
220 matrix[1*4+3] = 0.0f;
221 matrix[2*4+3] = 0.0f;
223 matrix[3*4+3] =(double) 1.0f;
232 left[0] = quat[3]*v[0] + quat[1]*v[2] - v[1]*quat[2];
233 left[1] = quat[3]*v[1] + quat[2]*v[0] - v[2]*quat[0];
234 left[2] = quat[3]*v[2] + quat[0]*v[1] - v[0]*quat[1];
235 left[3] = - quat[0]*v[0] - quat[1]*v[1] - quat[2]*v[2];
237 r[0] = (left[3]*-quat[0]) + (quat[3]*left[0]) + (left[1]*-quat[2]) - (-quat[1]*left[2]);
238 r[1] = (left[3]*-quat[1]) + (quat[3]*left[1]) + (left[2]*-quat[0]) - (-quat[2]*left[0]);
239 r[2] = (left[3]*-quat[2]) + (quat[3]*left[2]) + (left[0]*-quat[1]) - (-quat[0]*left[1]);
246 t[0] = matrix[3*4+0];
247 t[1] = matrix[3*4+1];
248 t[2] = matrix[3*4+2];
254 double tr = matrix[0*4+0] + matrix[1*4+1] + matrix[2*4+2];
260 double s = (double) sqrt ( (
double) (tr + 1.0f) );
263 quat[0] = (matrix[1*4+2] - matrix[2*4+1]) * s;
264 quat[1] = (matrix[2*4+0] - matrix[0*4+2]) * s;
265 quat[2] = (matrix[0*4+1] - matrix[1*4+0]) * s;
271 int nxt[3] = {1, 2, 0};
276 if (matrix[1*4+1] > matrix[0*4+0]) i = 1;
277 if (matrix[2*4+2] > matrix[i*4+i]) i = 2;
282 double s = sqrt ( ((matrix[i*4+i] - (matrix[j*4+j] + matrix[k*4+k])) + 1.0f) );
286 if (s != 0.0f ) s = 0.5f / s;
288 qa[3] = (matrix[j*4+k] - matrix[k*4+j]) * s;
289 qa[j] = (matrix[i*4+j] + matrix[j*4+i]) * s;
290 qa[k] = (matrix[i*4+k] + matrix[k*4+i]) * s;
304 return (4.0f / 3.0f ) *
FM_PI * radius * radius * radius;
310 return FM_PI * radius * radius *h;
316 double ch = h-radius*2;
326 t[0] = (matrix[0*4+0] * v[0]) + (matrix[1*4+0] * v[1]) + (matrix[2*4+0] * v[2]) + matrix[3*4+0];
327 t[1] = (matrix[0*4+1] * v[0]) + (matrix[1*4+1] * v[1]) + (matrix[2*4+1] * v[2]) + matrix[3*4+1];
328 t[2] = (matrix[0*4+2] * v[0]) + (matrix[1*4+2] * v[1]) + (matrix[2*4+2] * v[2]) + matrix[3*4+2];
331 void fm_rotate(
const double *matrix,
const double *v,
double *t)
333 t[0] = (matrix[0*4+0] * v[0]) + (matrix[1*4+0] * v[1]) + (matrix[2*4+0] * v[2]);
334 t[1] = (matrix[0*4+1] * v[0]) + (matrix[1*4+1] * v[1]) + (matrix[2*4+1] * v[2]);
335 t[2] = (matrix[0*4+2] * v[0]) + (matrix[1*4+2] * v[1]) + (matrix[2*4+2] * v[2]);
341 double dx = p1[0] - p2[0];
342 double dy = p1[1] - p2[1];
343 double dz = p1[2] - p2[2];
345 return sqrt( dx*dx + dy*dy + dz *dz );
350 double dx = p1[0] - p2[0];
351 double dy = p1[1] - p2[1];
352 double dz = p1[2] - p2[2];
354 return dx*dx + dy*dy + dz *dz;
360 double vx = (B[0] - C[0]);
361 double vy = (B[1] - C[1]);
362 double vz = (B[2] - C[2]);
364 double wx = (A[0] - B[0]);
365 double wy = (A[1] - B[1]);
366 double wz = (A[2] - B[2]);
368 double vw_x = vy * wz - vz * wy;
369 double vw_y = vz * wx - vx * wz;
370 double vw_z = vx * wy - vy * wx;
372 double mag = sqrt((vw_x * vw_x) + (vw_y * vw_y) + (vw_z * vw_z));
374 if ( mag < 0.000001f )
383 double x = vw_x * mag;
384 double y = vw_y * mag;
385 double z = vw_z * mag;
388 double D = 0.0f - ((x*A[0])+(y*A[1])+(z*A[2]));
402 double fm_dot(
const double *p1,
const double *p2)
404 return p1[0]*p2[0]+p1[1]*p2[2]+p1[2]*p2[2];
409 cross[0] = a[1]*b[2] - a[2]*b[1];
410 cross[1] = a[2]*b[0] - a[0]*b[2];
411 cross[2] = a[0]*b[1] - a[1]*b[0];
416 n[0] = p2[0] - p1[0];
417 n[1] = p2[1] - p1[1];
418 n[2] = p2[2] - p1[2];
435 double ref[3] = { 1, 0, 0 };
451 double dist = n[0]*n[0] + n[1]*n[1] + n[2]*n[2];
454 if ( dist > 0.0000001f )
455 mag = 1.0f / sqrt(dist);