OpenGL鼠标坐标

时间:2013-06-06 10:59:00

标签: c++ opengl coordinates

我有点问题。

我有间隔。 250表示0和500表示2.如何通过将坐标从250更改为250来获得0-2之间的数字。

void MouseButton(int button, int state, int x, int y)
{
    // MIN(250) - 0
    // MAX(500) - 2
    if (button == GLUT_LEFT_BUTTON && state == GLUT_DOWN)
    {
        pos2[0] = ( (float)x * 2 ) / ((float)m_viewport[2] -1);
        printf("%f - %d\n", pos2[0], x);
    }
}

2 个答案:

答案 0 :(得分:0)

你试过这个:

pos2[0] = ( (float)(x * 2.0) ) / ( (float)(m_viewport[2] * 1.0 - 1) );

答案 1 :(得分:0)

float scalar = 2.0f
float lBound = 250.0f;
float rBound = 500.0f;

float t = ((float)x-lBound)/(rBound-lBound)

pos2[0] = std::max(std::min(0.0f, t), 1.0f)*scalar
相关问题