Esempio n. 1
0
void Controls::mousePressHandler(int button, int state, int x, int y) 
{
    if ((state == GLUT_DOWN) && (button == GLUT_LEFT_BUTTON))
    {
        controls.setLeftButton(true);
        controls.setOldx(x);
        controls.setOldy(y);
    }
    else if((state == GLUT_UP) && (button == GLUT_LEFT_BUTTON))
    {
        controls.setLeftButton(false);
    }

    else if((state == GLUT_DOWN) && (button == GLUT_RIGHT_BUTTON))
    {
        controls.setOldx(x);
        controls.setOldy(y);
        controls.setRightButton(true);
    }
    else if((state == GLUT_UP) && (button == GLUT_RIGHT_BUTTON))
    {
        controls.setRightButton(false);
    }

    glutPostRedisplay();
}
Esempio n. 2
0
void Controls::mouseMotionHandler(int x, int y)
{
    int viewport[4];
    glGetIntegerv(GL_VIEWPORT, viewport );

    // Rotate Camera
    if(controls.getLeftButton() == true && controls.getRightButton() == false)
    {
        //We fmod it by 360 because it is easier to see that it rotated 360 degrees instead of 720 degrees.
        //camera.setRotatex( fmod(camera.getRotatex() + (y - controls.getOldy()), 360) );
        //camera.setRotatey( fmod(camera.getRotatey() + (x - controls.getOldx()), 360) ); 
		camera.pitch((y - controls.getOldy())/2.0f);
		camera.yaw((x - controls.getOldx())/2.0f);
    }
    // Translate Camera
    else if(controls.getLeftButton() == false && controls.getRightButton() == true)
    {
        //camera.setTranslatex( camera.getTranslatex() +  .1f * (x - controls.getOldx()) ); 
        //camera.setTranslatey( camera.getTranslatey() + -.1f * (y - controls.getOldy()) ); 
		camera.upd(-(y - controls.getOldy())/5.0f);
		camera.leftr(-(x - controls.getOldx())/5.0f);
    }
    // Scale Camera
    else if(controls.getLeftButton() == true && controls.getRightButton() == true)
    {
        camera.setScale( camera.getScale() + float(y-controls.getOldy())/viewport[3] ); 
    }

    controls.setOldy(y);
    controls.setOldx(x);

    glutPostRedisplay();
}