Convert mouse point to b2d point in opengl

Hi,
I want to convert mouse point on window to a point in box2D engine and I don't have those magic numbers to convert x and y 😉
I'm using windows calls to get mouse input and opengl to draw stuff.

So box2d testbed has this function ConvertScreenToWorld but i dont want to use GLUT to get those magic numbers...

Ive serched forum and found only this tut:
http://www.emanueleferonato.com/2008/11/16/understanding-pixels-and-meters-with-box2d-and-how-to-select-an-object-with-mouse-part-1/ but he just divides x,y by 30.0 ...


For me the closest aproximation looks like this
Code:
float32 u = x / 10.0;//almost good magic number ; )
float32 v = y / 10.0;
u *= cameradistance/100;
v *= cameradistance/100;
//+camera offset later.
b2Vec2 p(u,v);
return p;


Is there a better way to deal with this?


-edit-
OK ive found those magic numbers maybe someone will make use of this:

Code:
b2Vec2 ConvertScreenToWorld(int32 x, int32 y)
{
   float32 u = -x / 10.0;
   float32 v =  y / 10.0;
   u+= GLwidth /20;
   v-= GLheight/20;
   u *= cameradistance/72.5;//for default opengl frustrum
   v *= cameradistance/72.5;
   b2Vec2 p(u,v);
return p;
}


but still is there some other already tried and tested way? : P
Try asking around on some OpenGL or general game-dev forums - this is a very common problem, but it's not specific to Box2d, and if you ask the people that specialize in graphics you'll probably find a link to some robust code that can do this for you.

All the Box2d testbeds (to my knowledge) just hard code this stuff, but it's got to be possible to pull the transformation matrices from OpenGL or make a call that does the inverse transform for you, particularly in 2D.

FWIW, the underlying algorithm is identical to the one used for texture mapping.
Instead of using the default projection matrix, set it to whatever you want and keep track of it in some class (eg class View). Your class can then easily perform the needed transforms.

Original thread: https://box2d.org/forum/viewtopic.php?t=2812