KiCad PCB EDA Suite
trackball.h File Reference

Go to the source code of this file.

Functions

void trackball (double q[4], double p1x, double p1y, double p2x, double p2y)
 
void add_quats (double *q1, double *q2, double *dest)
 
void build_rotmatrix (float m[4][4], double q[4])
 
void axis_to_quat (double a[3], double phi, double q[4])
 

Function Documentation

void add_quats ( double *  q1,
double *  q2,
double *  dest 
)
void axis_to_quat ( double  a[3],
double  phi,
double  q[4] 
)

Definition at line 205 of file trackball.cpp.

References vcopy(), vnormal(), and vscale().

Referenced by trackball().

206 {
207  vnormal( a );
208  vcopy( a, q );
209  vscale( q, (double) sin( phi / 2.0) );
210  q[3] = (double) cos( phi / 2.0 );
211 }
void vscale(double *v, double div)
Definition: trackball.cpp:119
void vcopy(const double *v1, double *v2)
Definition: trackball.cpp:96
void vnormal(double *v)
Definition: trackball.cpp:126
void build_rotmatrix ( float  m[4][4],
double  q[4] 
)

Definition at line 306 of file trackball.cpp.

Referenced by CTRACK_BALL::Drag(), and CTRACK_BALL::Interpolate().

307 {
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]));
311  m[0][3] = 0.0f;
312 
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]));
316  m[1][3] = 0.0f;
317 
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]));
321  m[2][3] = 0.0f;
322 
323  m[3][0] = 0.0f;
324  m[3][1] = 0.0f;
325  m[3][2] = 0.0f;
326  m[3][3] = 1.0f;
327 }
void trackball ( double  q[4],
double  p1x,
double  p1y,
double  p2x,
double  p2y 
)

Definition at line 155 of file trackball.cpp.

References axis_to_quat(), opti_s::t, tb_project_to_sphere(), TRACKBALLSIZE, vcross(), vlength(), vset(), vsub(), and vzero().

Referenced by CTRACK_BALL::CTRACK_BALL(), CTRACK_BALL::Drag(), CTRACK_BALL::Reset(), and CTRACK_BALL::Reset_T1().

156 {
157  double a[3]; /* Axis of rotation */
158  double phi; /* how much to rotate about axis */
159  double p1[3], p2[3], d[3];
160  double t;
161 
162  if( p1x == p2x && p1y == p2y )
163  {
164  /* Zero rotation */
165  vzero( q );
166  q[3] = 1.0;
167  return;
168  }
169 
170  /*
171  * First, figure out z-coordinates for projection of P1 and P2 to
172  * deformed sphere
173  */
174  vset( p1, p1x, p1y, tb_project_to_sphere( TRACKBALLSIZE, p1x, p1y ) );
175  vset( p2, p2x, p2y, tb_project_to_sphere( TRACKBALLSIZE, p2x, p2y ) );
176 
177  /*
178  * Now, we want the cross product of P1 and P2
179  */
180  vcross(p2,p1,a);
181 
182  /*
183  * Figure out how much to rotate around that axis.
184  */
185  vsub( p1, p2, d );
186  t = vlength( d ) / (2.0f * TRACKBALLSIZE);
187 
188  /*
189  * Avoid problems with out-of-control values...
190  */
191  if( t > 1.0 )
192  t = 1.0;
193 
194  if( t < -1.0 )
195  t = -1.0;
196 
197  phi = 2.0f * (double) asin( t );
198 
199  axis_to_quat( a, phi, q );
200 }
static double tb_project_to_sphere(double, double, double)
Definition: trackball.cpp:217
void axis_to_quat(double a[3], double phi, double q[4])
Definition: trackball.cpp:205
void vset(double *v, double x, double y, double z)
Definition: trackball.cpp:82
void vcross(const double *v1, const double *v2, double *cross)
Definition: trackball.cpp:104
double vlength(const double *v)
Definition: trackball.cpp:114
#define TRACKBALLSIZE
Definition: trackball.cpp:67
void vsub(const double *src1, const double *src2, double *dst)
Definition: trackball.cpp:89
void vzero(double *v)
Definition: trackball.cpp:75