void ArcBall::mouseDragged(int mouseX, int mouseY) { v_drag = mouse_to_sphere(mouseX, mouseY); QQuaternion q_drag( QVector3D::dotProduct(v_down, v_drag), QVector3D::crossProduct(v_down, v_drag)); q_now = q_drag * q_down; }
void Arcball::mouse_motion(int x, int y, int shift, int ctrl, int alt) { /* Set the X constraint if CONTROL key is pressed, Y if ALT key */ set_constraints( ctrl != 0, alt != 0 ); vec2 new_pt( (float)x, (float) y ); vec3 v0 = mouse_to_sphere( down_pt ); vec3 v1 = mouse_to_sphere( new_pt ); vec3 cross = v0^v1; q_drag.set( cross, v0 * v1 ); // *rot_ptr = (q_drag * q_now).to_mat4(); mat4 temp = q_drag.to_mat4(); *rot_ptr = *rot_ptr * temp; down_pt = new_pt; /* We keep a copy of the current incremental rotation (= q_drag) */ q_increment = q_drag; rot_increment = q_increment.to_mat4(); set_constraints(false, false); if ( q_increment.s < .999999 ) { is_spinning = true; zero_increment = false; } else { is_spinning = false; zero_increment = true; } }
void ArcBall::mousePressed(int mouseX, int mouseY) { v_down = mouse_to_sphere(mouseX, mouseY); q_down = q_now; }