67 #define TRACKBALLSIZE (.8)
85 vset(
double *v,
double x,
double y,
double z)
93 vsub(
const double *src1,
const double *src2,
double *dst)
95 dst[0] = src1[0] - src2[0];
96 dst[1] = src1[1] - src2[1];
97 dst[2] = src1[2] - src2[2];
104 for (i = 0 ; i < 3 ; i++)
113 temp[0] = (v1[1] * v2[2]) - (v1[2] * v2[1]);
114 temp[1] = (v1[2] * v2[0]) - (v1[0] * v2[2]);
115 temp[2] = (v1[0] * v2[1]) - (v1[1] * v2[0]);
122 return sqrt(v[0] * v[0] + v[1] * v[1] + v[2] * v[2]);
140 vdot(
const double *v1,
const double *v2)
142 return v1[0]*v2[0] + v1[1]*v2[1] + v1[2]*v2[2];
146 vadd(
const double *src1,
const double *src2,
double *dst)
148 dst[0] = src1[0] + src2[0];
149 dst[1] = src1[1] + src2[1];
150 dst[2] = src1[2] + src2[2];
166 trackball(
double q[4],
double p1x,
double p1y,
double p2x,
double p2y)
170 double p1[3], p2[3], d[3];
173 if (p1x == p2x && p1y == p2y) {
203 if (t > 1.0) t = 1.0;
204 if (t < -1.0) t = -1.0;
233 if (d < r * 0.70710678118654752440) {
239 t = r / 1.41421356237309504880;
265 #define RENORMCOUNT 97
271 double t1[4], t2[4], t3[4];
283 tf[3] = q1[3] * q2[3] -
vdot(q1,q2);
314 mag = (q[0]*q[0] + q[1]*q[1] + q[2]*q[2] + q[3]*q[3]);
315 for (i = 0; i < 4; i++) q[i] /= mag;
325 m[0] = 1.0 - 2.0 * (q[1] * q[1] + q[2] * q[2]);
326 m[1] = 2.0 * (q[0] * q[1] - q[2] * q[3]);
327 m[2] = 2.0 * (q[2] * q[0] + q[1] * q[3]);
330 m[4] = 2.0 * (q[0] * q[1] + q[2] * q[3]);
331 m[5]= 1.0 - 2.0 * (q[2] * q[2] + q[0] * q[0]);
332 m[6] = 2.0 * (q[1] * q[2] - q[0] * q[3]);
335 m[8] = 2.0 * (q[2] * q[0] - q[1] * q[3]);
336 m[9] = 2.0 * (q[1] * q[2] + q[0] * q[3]);
337 m[10] = 1.0 - 2.0 * (q[1] * q[1] + q[0] * q[0]);