Screen 2 World
Hi there,
for my application I need to transform window coordinates that I get from a double-click into the window into world coordinates.
I only need the x and y coordinate, I use orthographic projection and the modelview matrix does nothing ( = identity ). This is what I do:
// After a double click I get the corresponding window
// coordinates passed in function like this
void OnDblClick(long x, long y)
{
// 1.) Transform from the windows coordsystem to opengl
y = WINDOWSHEIGHT - y;
// 2.) Do the invert viewport transform
x = 2*x/WINDOWWIDTH - 1;
y = 2*y/WINDOWHEIGHT -1;
// 3.) Do the invert projection transform
Matrix4 mtx;
glGetFloatv(GL_PROJECTION_MATRIX, &mtx);
mtx.Invert();
Vector4 v(x, y, 0.0f, 1.0f);
vtx = mtx*v;
} // End
Something seems not work. Do I need the transform from windows coords to opengl coords like in step 1? After the transfrom vtx.w ist no more 1.0f. So so I need to divide by w?
Finally, is there a better way? Any help is greatly appreciated!
-Dirk
}
(Sorry for hijacking, but I have some questions that fit here )
Would this be better than using picking to find objects? Anyone know the relative speeds?
Would this be better than using picking to find objects? Anyone know the relative speeds?
Hey
Yeah I searched for this a while back because I had similar questions. The Opengl method of picking is like twice as slow(if my memory is correct, maybe bit slower) as when using a ray trace method.
I will try finding same article
Yeah I searched for this a while back because I had similar questions. The Opengl method of picking is like twice as slow(if my memory is correct, maybe bit slower) as when using a ray trace method.
I will try finding same article
I found the post
http://www.gamedev.net/community/forums/topic.asp?topic_id=193977
down the bottom there is a post of someone that did a test on his machine comparing different ways of doing picking.
http://www.gamedev.net/community/forums/topic.asp?topic_id=193977
down the bottom there is a post of someone that did a test on his machine comparing different ways of doing picking.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement