窗口坐标到屏幕坐标的转换不起作用

时间:2015-01-22 11:50:35

标签: c++ opengl

此功能无法将窗口坐标转换为我的屏幕。但在大多数网站中,它与此代码相同。

我的坐标是:x轴-8到8和y轴-3.3到3.3

void handleMouseclick(int button, int state, int x, int y) {

    if (state == GLUT_DOWN)
    {
        if (button == GLUT_LEFT_BUTTON){
        int w = glutGet(GLUT_SCREEN_WIDTH);
        int h = glutGet(GLUT_SCREEN_HEIGHT);
        //float striker_x = x*1.0 ;
        //float striker_y = y * 1.0;
        w = 1300;
        h = 715;
        float x1 = x / float(w) * 16 + -8;
        float y1 = y / float(h) * 6.6 + -3.3;
        //striker_x = ((1.0 / float(1300)) * x) - 1;
        //striker_y = ((1.0 / float(715)) * -y) + 1;

       // striker_x = ((8.0 / float(1300)) * striker_x);
        //striker_y = (((3.3 / float(715)) * -striker_y) + 0.5)*2;
            printf("x_s = %f\n",x1);
            printf("x = %d\n",x);
            printf("y_s = %f\n",y1);
            target_x= x1;
            target_y= y1;    
        }

        else if (button == GLUT_RIGHT_BUTTON){
            float theta = 0.0f;
            theta -= 15;
        }
    }
}

0 个答案:

没有答案
相关问题