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
Is there a better way to deal with this?
-edit-
OK ive found those magic numbers maybe someone will make use of this:
but still is there some other already tried and tested way? : P
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;
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;
}
{
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