void ofxCamera::setViewByMouse(int x, int y) { ofxVec2f mouseDelta; float MouseSensitivity = 10.0f; float MiddleX = ofGetWidth()/2; float MiddleY = ofGetHeight()/2; if((x == MiddleX) && (y == MiddleY)) return; // otherwise move the mouse back to the middle of the screen glutWarpPointer(MiddleX, MiddleY); mouseDelta.x = (MiddleX - x)/MouseSensitivity; mouseDelta.y = (MiddleY - y)/MouseSensitivity; // get the axis to rotate around the x-axis. ofxVec3f axis = eyeCoord - posCoord; axis.cross(upVec); // To be able to use the quaternion conjugate, the axis to // rotate around must be normalized. axis.normalize(); // Rotate around the x axis qrotate(axis,mouseDelta.y); // Rotate around the y axis qrotate(ofxVec3f(0, 1, 0),mouseDelta.x); }
void view_turn(view *V, const double *w) { #if 0 double M[16], T[16], q[4], a[3], b[3], c[3], t[3]; assert(V); /* Transform the mark and drag vectors from eye space into the world */ /* space current at the time of the mark. */ state_matrix(M, &V->mark); mtranspose(T, M); vnormalize(t, V->a); vtransform(a, T, t); vnormalize(t, w); vtransform(b, T, t); /* These determine the axis and angle of rotation. Find the quaternion. */ vcrs(t, a, b); vnormalize(c, t); qrotate(q, c, acos(vdot(a, b))); /* Accumulate this quaternion with the view state, rotating the view. */ qmultiply(view_curr(V)->q, V->mark.q, q); #endif }