67#define TRACKBALLSIZE (0.8f)
82void vset(
double *v,
double x,
double y,
double z )
89void vsub(
const double *src1,
const double *src2,
double *dst )
91 dst[0] = src1[0] - src2[0];
92 dst[1] = src1[1] - src2[1];
93 dst[2] = src1[2] - src2[2];
100 for( i = 0 ; i < 3 ; i++ )
104void vcross(
const double *
v1,
const double *
v2,
double *cross )
108 temp[0] = (
v1[1] *
v2[2]) - (
v1[2] *
v2[1]);
109 temp[1] = (
v1[2] *
v2[0]) - (
v1[0] *
v2[2]);
110 temp[2] = (
v1[0] *
v2[1]) - (
v1[1] *
v2[0]);
116 return (
double) sqrt( v[0] * v[0] + v[1] * v[1] + v[2] * v[2] );
136void vadd(
const double *src1,
const double *src2,
double *dst )
138 dst[0] = src1[0] + src2[0];
139 dst[1] = src1[1] + src2[1];
140 dst[2] = src1[2] + src2[2];
155void trackball(
double q[4],
double p1x,
double p1y,
double p2x,
double p2y )
159 double p1[3], p2[3], d[3];
162 if( p1x == p2x && p1y == p2y )
197 phi = 2.0f * (double) asin( t );
209 vscale( q, (
double) sin( phi / 2.0) );
210 q[3] = (double) cos( phi / 2.0 );
221 d = (double) sqrt( x*x + y*y );
223 if( d < r * 0.70710678118654752440 )
225 z = (double) sqrt( r*r - d*d );
229 const double t = r / 1.41421356237309504880f;
247#define RENORMCOUNT 97
249void add_quats(
double q1[4],
double q2[4],
double dest[4] )
252 double t1[4], t2[4], t3[4];
265 tf[3] = q1[3] * q2[3] -
vdot( q1, q2 );
296 mag = (q[0]*q[0] + q[1]*q[1] + q[2]*q[2] + q[3]*q[3]);
298 for( i = 0; i < 4; i++ )
308 m[0][0] = (float)(1.0 - 2.0 * (q[1] * q[1] + q[2] * q[2]));
309 m[0][1] = (float)(2.0 * (q[0] * q[1] - q[2] * q[3]));
310 m[0][2] = (float)(2.0 * (q[2] * q[0] + q[1] * q[3]));
313 m[1][0] = (float)(2.0 * (q[0] * q[1] + q[2] * q[3]));
314 m[1][1] = (float)(1.0 - 2.0f * (q[2] * q[2] + q[0] * q[0]));
315 m[1][2] = (float)(2.0 * (q[1] * q[2] - q[0] * q[3]));
318 m[2][0] = (float)(2.0 * (q[2] * q[0] - q[1] * q[3]));
319 m[2][1] = (float)(2.0 * (q[1] * q[2] + q[0] * q[3]));
320 m[2][2] = (float)(1.0 - 2.0 * (q[1] * q[1] + q[0] * q[0]));
void vcross(const double *v1, const double *v2, double *cross)
void vscale(double *v, double div)
double vdot(const double *v1, const double *v2)
void build_rotmatrix(float m[4][4], double q[4])
static void normalize_quat(double[4])
void trackball(double q[4], double p1x, double p1y, double p2x, double p2y)
void axis_to_quat(double a[3], double phi, double q[4])
void vset(double *v, double x, double y, double z)
double vlength(const double *v)
void vcopy(const double *v1, double *v2)
void vsub(const double *src1, const double *src2, double *dst)
void vadd(const double *src1, const double *src2, double *dst)
static double tb_project_to_sphere(double, double, double)
void add_quats(double q1[4], double q2[4], double dest[4])