void glutMotion(int x, int y) { if (gIsRotatingCamera) { static const double kTrackBallRadius = 0.8; Vec3d lastPos; lastPos[0] = gLastMouseX * 2.0 / gWindowWidth - 1.0; lastPos[1] = (gWindowHeight - gLastMouseY) * 2.0 / gWindowHeight - 1.0; lastPos[2] = projectToTrackball(kTrackBallRadius, lastPos[0], lastPos[1]); Vec3d currPos; currPos[0] = x * 2.0 / gWindowWidth - 1.0; currPos[1] = (gWindowHeight - y) * 2.0 / gWindowHeight - 1.0; currPos[2] = projectToTrackball(kTrackBallRadius, currPos[0], currPos[1]); currPos.normalize(); lastPos.normalize(); Vec3d rotateVec = lastPos.cross(currPos); double rotateAngle = asin(rotateVec.norm()); if (fabs(rotateAngle) > 1e-6) { double deltaRotation[16]; generateRotationMatrix(deltaRotation, rotateAngle, rotateVec[0], rotateVec[1], rotateVec[2]); multRight(gCameraRotation, deltaRotation); updateCamera(); } } else if (gIsScalingCamera) { float y1 = gWindowHeight - gLastMouseY; float y2 = gWindowHeight - y; gCameraScale *= 1 + (y1 - y2) / gWindowHeight; updateCamera(); } gLastMouseX = x; gLastMouseY = y; }
//! Right-multiply with the \a a_matrix matrix. \sa multRight(). matrix4<Type>& operator*=(const matrix4<Type>& a_matrix) { return multRight(a_matrix); }