67#define TRACKBALLSIZE (0.8f)
84void vset(
double *v,
double x,
double y,
double z )
92void vsub(
const double *src1,
const double *src2,
double *dst )
94 dst[0] = src1[0] - src2[0];
95 dst[1] = src1[1] - src2[1];
96 dst[2] = src1[2] - src2[2];
104 for( i = 0 ; i < 3 ; i++ )
109void vcross(
const double *
v1,
const double *
v2,
double *cross )
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 (
double) sqrt( v[0] * v[0] + v[1] * v[1] + v[2] * v[2] );
146void 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];
166void 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 )
208 phi = 2.0f * (double) asin( t );
221 vscale( q, (
double) sin( phi / 2.0) );
222 q[3] = (double) cos( phi / 2.0 );
234 d = (double) sqrt( x*x + y*y );
236 if( d < r * 0.70710678118654752440 )
238 z = (double) sqrt( r*r - d*d );
242 const double t = r / 1.41421356237309504880f;
261#define RENORMCOUNT 97
263void add_quats(
double q1[4],
double q2[4],
double dest[4] )
265 static int count = 0;
266 double t1[4], t2[4], t3[4];
279 tf[3] = q1[3] * q2[3] -
vdot( q1, q2 );
311 mag = ( q[0] * q[0] + q[1] * q[1] + q[2] * q[2] + q[3] * q[3] );
313 for( i = 0; i < 4; i++ )
323 m[0][0] = (float) ( 1.0 - 2.0 * ( q[1] * q[1] + q[2] * q[2] ) );
324 m[0][1] = (float) ( 2.0 * ( q[0] * q[1] - q[2] * q[3] ) );
325 m[0][2] = (float) ( 2.0 * ( q[2] * q[0] + q[1] * q[3] ) );
328 m[1][0] = (float) ( 2.0 * ( q[0] * q[1] + q[2] * q[3] ) );
329 m[1][1] = (float) ( 1.0 - 2.0f * ( q[2] * q[2] + q[0] * q[0] ) );
330 m[1][2] = (float) ( 2.0 * ( q[1] * q[2] - q[0] * q[3] ) );
333 m[2][0] = (float) ( 2.0 * ( q[2] * q[0] - q[1] * q[3] ) );
334 m[2][1] = (float) ( 2.0 * ( q[1] * q[2] + q[0] * q[3] ) );
335 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])