/* Visualizing Quaternions: Chapter 13: Table 13.1: page 128 Rolling ball implementation code fragment. Copyright 2006, Trustees of Indiana University These files may be freely copied for personal and educational uses provided these lines are included. Full License available at: visualizingquaternions_license.txt */ int x0, y0; /* Global previous cursor state */ float R = 100.0; /* Global tuning parameter */ void rollball(int x, int y) {int dx, dy; float dr, nhatx, nhaty, theta; dx = x - x0; dy = y - y0; dr = sqrt(dx*dx + dy*dy); if(dr != 0.0) { nhatx = - (float)dy/dr; nhaty = + (float)dx/dr; theta = dr/R; leftrotate(theta, nhatx, nhaty, 0.0); } }