Icon Saver

Code sample

The following function is called in response to WM_MOUSEMOVE events, when the app is in interactive mode.
// This function maps mouse movements to icon movements
void ManipulateObject(POINT pt)
{
    // convert the mouse position into 2D cartesian coords
    GLfloat x = (GLfloat)pt.x - g_fOriginX;
    GLfloat y = (GLfloat)pt.y - g_fOriginY;
    // change rotation speed/direction of icon, based on
    // the distance of the mouse from the origin
    // left/right movements spin the icon
    // around the Y axis
    if (fabs(x) < g_fDeadRadius)
    {
        // we're in the dead zone - stop spinning
        g_RotationSpeedY = 0;
    }
    else
    {
        // - apply some spin
        g_RotationSpeedY = (x - g_fDeadRadius) / MOUSE_CHOKE;
    }
    // up/down movements spin the icon
    // around the X axis
    if (fabs(y) < g_fDeadRadius)
    {
        // we're in the dead zone - stop spinning
        g_RotationSpeedX = 0;
    }
    else
    {
        // - apply some spin
        g_RotationSpeedX = (y - g_fDeadRadius) / MOUSE_CHOKE;
    }
}