-1

i have a little problem.

I have interval. 250 means 0 and 500 means 2. How i can get number between 0-2 by changing coordinates from 250 to 250.

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);
    }
}
  • Sounds like you're after this: http://stackoverflow.com/questions/929103/convert-a-number-range-to-another-range-maintaining-ratio – paulm Jun 06 '13 at 11:27
  • please elaborate a bit more, it's not clear what you're asking for – blue Jun 08 '13 at 12:11

2 Answers2

0

Have you tried this:

pos2[0] = ( (float)(x * 2.0) ) / ( (float)(m_viewport[2] * 1.0 - 1) );
Neigyl R. Noval
  • 6,018
  • 4
  • 27
  • 45
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
Enigma
  • 1,699
  • 10
  • 14