Doxygen Source Code Documentation
SUMA_trackball.c File Reference
#include "SUMA_suma.h"Go to the source code of this file.
| Defines | |
| #define | TRACKBALLSIZE (1) | 
| #define | RENORMCOUNT 97 | 
| Functions | |
| float | tb_project_to_sphere (float, float, float) | 
| void | normalize_quat (float[4]) | 
| void | vzero (float *v) | 
| void | vset (float *v, float x, float y, float z) | 
| void | vsub (const float *src1, const float *src2, float *dst) | 
| void | vcopy (const float *v1, float *v2) | 
| void | vcross (const float *v1, const float *v2, float *cross) | 
| float | vlength (const float *v) | 
| void | vscale (float *v, float div) | 
| void | vnormal (float *v) | 
| float | vdot (const float *v1, const float *v2) | 
| void | vadd (const float *src1, const float *src2, float *dst) | 
| void | trackball (float q[4], float p1x, float p1y, float p2x, float p2y) | 
| void | trackball_Phi (float q[4], float p1x, float p1y, float p2x, float p2y, float phi) | 
| void | axis_to_quat (float a[3], float phi, float q[4]) | 
| void | add_quats (float q1[4], float q2[4], float dest[4]) | 
| void | SUMA_build_rotmatrix (GLfloat m[4][4], float q[4]) | 
| Variables | |
| SUMA_CommonFields * | SUMAg_CF | 
Define Documentation
| 
 | 
| 
 Definition at line 207 of file SUMA_trackball.c. Referenced by add_quats(). | 
| 
 | 
| 
 Definition at line 16 of file SUMA_trackball.c. Referenced by trackball(), and trackball_Phi(). | 
Function Documentation
| 
 | ||||||||||||||||
| 
 Definition at line 210 of file SUMA_trackball.c. References normalize_quat(), RENORMCOUNT, vadd(), vcopy(), vcross(), vdot(), and vscale(). 
 00211 {
00212   static int count = 0;
00213   float t1[4], t2[4], t3[4];
00214   float tf[4];
00215 
00216   vcopy(q1, t1);
00217   vscale(t1, q2[3]);
00218 
00219   vcopy(q2, t2);
00220   vscale(t2, q1[3]);
00221 
00222   vcross(q2, q1, t3);
00223   vadd(t1, t2, tf);
00224   vadd(t3, tf, tf);
00225   tf[3] = q1[3] * q2[3] - vdot(q1, q2);
00226 
00227   dest[0] = tf[0];
00228   dest[1] = tf[1];
00229   dest[2] = tf[2];
00230   dest[3] = tf[3];
00231 
00232   if (++count > RENORMCOUNT) {
00233     count = 0;
00234     normalize_quat(dest);
00235   }
00236 }
 | 
| 
 | ||||||||||||||||
| 
 Definition at line 174 of file SUMA_trackball.c. References a, q, vcopy(), vnormal(), and vscale(). Referenced by SUMA_input(), trackball(), and trackball_Phi(). 
 | 
| 
 | 
| 
 Definition at line 242 of file SUMA_trackball.c. Referenced by add_quats(). 
 | 
| 
 | ||||||||||||
| 
 Definition at line 254 of file SUMA_trackball.c. References LocalHead, q, SUMA_Boolean, SUMA_ENTRY, and SUMA_RETURNe. 
 00255 {
00256         static char FuncName[]={"SUMA_build_rotmatrix"};
00257         SUMA_Boolean LocalHead = NOPE;
00258         
00259         SUMA_ENTRY;
00260         m[0][0] = 1.0 - 2.0 * (q[1] * q[1] + q[2] * q[2]);
00261         m[0][1] = 2.0 * (q[0] * q[1] - q[2] * q[3]);
00262         m[0][2] = 2.0 * (q[2] * q[0] + q[1] * q[3]);
00263         m[0][3] = 0.0;
00264 
00265         m[1][0] = 2.0 * (q[0] * q[1] + q[2] * q[3]);
00266         m[1][1] = 1.0 - 2.0 * (q[2] * q[2] + q[0] * q[0]);
00267         m[1][2] = 2.0 * (q[1] * q[2] - q[0] * q[3]);
00268         m[1][3] = 0.0;
00269 
00270         m[2][0] = 2.0 * (q[2] * q[0] - q[1] * q[3]);
00271         m[2][1] = 2.0 * (q[1] * q[2] + q[0] * q[3]);
00272         m[2][2] = 1.0 - 2.0 * (q[1] * q[1] + q[0] * q[0]);
00273         m[2][3] = 0.0;
00274 
00275         m[3][0] = 0.0;
00276         m[3][1] = 0.0;
00277         m[3][2] = 0.0;
00278         m[3][3] = 1.0;
00279         
00280         SUMA_RETURNe;
00281 }
 | 
| 
 | ||||||||||||||||
| 
 Definition at line 186 of file SUMA_trackball.c. References r. Referenced by trackball(), and trackball_Phi(). 
 | 
| 
 | ||||||||||||||||||||||||
| functions defined in SUMA_trackball.c Definition at line 99 of file SUMA_trackball.c. References a, axis_to_quat(), q, tb_project_to_sphere(), TRACKBALLSIZE, vcross(), vlength(), vset(), vsub(), and vzero(). Referenced by SUMA_input(). 
 00100 {
00101   float a[3];           /* Axis of rotation. */
00102   float phi;            /* How much to rotate about axis. */
00103   float p1[3], p2[3], d[3];
00104   float t;
00105 
00106   if (p1x == p2x && p1y == p2y) {
00107     /* Zero rotation */
00108     vzero(q);
00109     q[3] = 1.0;
00110     return;
00111   }
00112   /* First, figure out z-coordinates for projection of P1 and
00113      P2 to deformed sphere. */
00114   vset(p1, p1x, p1y, tb_project_to_sphere(TRACKBALLSIZE, p1x, p1y));
00115   vset(p2, p2x, p2y, tb_project_to_sphere(TRACKBALLSIZE, p2x, p2y));
00116 
00117   /* Now, we want the cross product of P1 and P2. */
00118   vcross(p2, p1, a);
00119   /* Figure out how much to rotate around that axis. */
00120   vsub(p1, p2, d);
00121   t = vlength(d) / (2.0 * TRACKBALLSIZE);
00122 
00123   /* Avoid problems with out-of-control values. */
00124   if (t > 1.0)
00125     t = 1.0;
00126   if (t < -1.0)
00127     t = -1.0;
00128   phi = 2.0 * asin(t);
00129   axis_to_quat(a, phi, q);
00130 }
 | 
| 
 | ||||||||||||||||||||||||||||
| A modification/hack of trackball function to control the rotation angle directement Definition at line 136 of file SUMA_trackball.c. References a, axis_to_quat(), q, tb_project_to_sphere(), TRACKBALLSIZE, vcross(), vlength(), vset(), vsub(), and vzero(). Referenced by SUMA_input(). 
 00137 {
00138   float a[3];           /* Axis of rotation. */
00139   float p1[3], p2[3], d[3];
00140   float t;
00141 
00142   if (p1x == p2x && p1y == p2y) {
00143     /* Zero rotation */
00144     vzero(q);
00145     q[3] = 1.0;
00146     return;
00147   }
00148   /* First, figure out z-coordinates for projection of P1 and
00149      P2 to deformed sphere. */
00150   vset(p1, p1x, p1y, tb_project_to_sphere(TRACKBALLSIZE, p1x, p1y));
00151   vset(p2, p2x, p2y, tb_project_to_sphere(TRACKBALLSIZE, p2x, p2y));
00152 
00153   /* Now, we want the cross product of P1 and P2. */
00154   vcross(p2, p1, a);
00155   /* Figure out how much to rotate around that axis. */
00156   vsub(p1, p2, d);
00157   t = vlength(d) / (2.0 * TRACKBALLSIZE);
00158 
00159   /* Avoid problems with out-of-control values. */
00160   if (t > 1.0) {
00161       t = 1.0;
00162       phi = 2.0 * asin(t);
00163   }
00164   if (t < -1.0) {
00165       t = -1.0;
00166       phi = 2.0 * asin(t);
00167   }
00168   
00169   axis_to_quat(a, phi, q);
00170 }
 | 
| 
 | ||||||||||||||||
| 
 Definition at line 91 of file SUMA_trackball.c. Referenced by add_quats(). 
 00092 {
00093   dst[0] = src1[0] + src2[0];
00094   dst[1] = src1[1] + src2[1];
00095   dst[2] = src1[2] + src2[2];
00096 }
 | 
| 
 | ||||||||||||
| 
 Definition at line 46 of file SUMA_trackball.c. Referenced by add_quats(), axis_to_quat(), and vcross(). 
 | 
| 
 | ||||||||||||||||
| 
 Definition at line 54 of file SUMA_trackball.c. Referenced by add_quats(), trackball(), and trackball_Phi(). 
 | 
| 
 | ||||||||||||
| 
 Definition at line 85 of file SUMA_trackball.c. References v1. Referenced by add_quats(). 
 | 
| 
 | 
| 
 Definition at line 65 of file SUMA_trackball.c. References v. Referenced by trackball(), trackball_Phi(), and vnormal(). 
 | 
| 
 | 
| 
 Definition at line 79 of file SUMA_trackball.c. References v, vlength(), and vscale(). Referenced by axis_to_quat(). 
 | 
| 
 | ||||||||||||
| 
 Definition at line 71 of file SUMA_trackball.c. References v. Referenced by add_quats(), axis_to_quat(), and vnormal(). 
 | 
| 
 | ||||||||||||||||||||
| 
 Definition at line 30 of file SUMA_trackball.c. References v. Referenced by trackball(), and trackball_Phi(). 
 | 
| 
 | ||||||||||||||||
| 
 Definition at line 38 of file SUMA_trackball.c. Referenced by trackball(), and trackball_Phi(). 
 00039 {
00040   dst[0] = src1[0] - src2[0];
00041   dst[1] = src1[1] - src2[1];
00042   dst[2] = src1[2] - src2[2];
00043 }
 | 
| 
 | 
| 
 Definition at line 22 of file SUMA_trackball.c. References v. Referenced by trackball(), and trackball_Phi(). 
 | 
Variable Documentation
| 
 | 
| Global pointer to structure containing info common to all viewers Definition at line 3 of file SUMA_trackball.c. | 
 
                             
                             
                             
                             
                             
                             
                             
                             
                             
                             
                             
                             
 
 
 
 
       
	   
	   
	   
	  