views:

18

answers:

0

Here are snippets of my code, but every time I print out my code, I get large integers for coordinates. Center should be (0,0) and sides should be 1.. but I get very large integers when I click on center.. look at last code below.

// how i set up window in reshape
void reshape(int w, int h) {
    GW = w;
    GH = h;

    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glOrtho( -2*(float)w/h, (float)2*w/h, -2, 2, -2, 2); 
    glMatrixMode(GL_MODELVIEW);
    glViewport(0, 0, w, h);

}

// translating pixel to world
float p2w_x(int gx) {
    return (float)2.*GW / (GW*GH-GH) * gx - (float)GW/GH;
}

float p2w_y(int gy) {
    int py = GH - 1 - gy;
    return (float)2./(GH - 1.) * py-1;
}

// when i see what x, y is
void mouse(int button, int state, int x, int y) {
    cout << p2w_x(x) << "," << p2w_y(y) << endl;
}
// this prints out 536870912 and 1063553029 when i click on the center, i should be     getting 0,0