How do I convert screen coordinates to between -1 and 1?

Posted by bbdude95 on Game Development See other posts from Game Development or by bbdude95
Published on 2014-05-28T18:11:01Z Indexed on 2014/06/03 3:44 UTC
Read the original article Hit count: 162

I'm writing a function that allows me to click on my tiles. The origin for my tiles is the center, however, the mouse's origin is the top left. I need a way to transform my mouse coordinates into my tile coordinates.

Here is what I already have (but is not working):

void mouseClick(int button, int state, int x, int y)
{
    x -= 400;
    y -= 300;
    float xx = x / 100; // This gets me close but the number is still high.
    float yy = y / 100; // It needs to be between -1 and 1
}

© Game Development or respective owner

Related posts about mathematics

Related posts about coordinates