Advertisement

Picking issue

Started by September 24, 2002 03:22 PM
8 comments, last by zoidy 22 years, 5 months ago
Hi. A project I am working on is now up and running, but I am experiencing an odd problem. When running in windowed mode, the vertical picking point is offset by the height of the title bar of the window. Also, if I move the window, the picking continues to act as though the window were still in its starting position. Is there any way I could find the window position to compensate for this? Or is there any other solution? Ok, the above still stands. I also have another problem. Whenever I try to toggle between fullscreen and window, the program exits. Im not aware of having changed any related code, and comparing it with nehe progs it all seems to be the same. Any suggestions? Thanks in advance... zoidy [edited by - zoidy on September 25, 2002 12:45:33 PM]
Please? Anyone?
Advertisement
For the coordinates of the mouse cursor, there''s only one solution : you have to know what is the coordinate of your window, relatively to the desktop. Obviously, this problem does not happen in fullscreen.

About your fullscreen problem, it simply depends on your fullscreen method, which I''m afraid is not related to OpenGL.
How do you render your OpenGL window ? with NeHe basecode ? with GLUT ? SDL ? something else ?
Thanks for your reply.
How would I go about finding the coordinates of the window relative to the desktop? I have searched through the msdn but havent managed to find anything I could get working.
I am using the NeHe basecode to render the opengl window. Like I say, I dont think I have changed anything and cant see any discrepencies, but if you could give me an idea of perhaps where to focus or what to change that would be great...
zoidy
Since you''re using NeHe Basecode, you can use Windows GDI to query the window position.
Haven''t looked at it for a while, but that must be something as simple as GetPosition() or GetWindowPos() or GetWindowRect() ... (I think the last one is the good, AFAIR)
Hi zoidy,

The following will give you an accurate mouse position within your current window, so using it to get mouse coords prior to doing your picking testing should fix the problem for you.

Note the two lines marked "UGLY HACK" - you should really use some API calls to get the real width of the window border and height of the title bar in case people aren''t using the standards; which, given that the XP themes mess them around, is probably essential...

Still, hope it helps.


  // Replace screenHeight, screenWidth and hWnd with your globals// or whatever that contain the height and width of your window// and the HWND of your windowstruct MousePosition {	int	x, y, z;};MousePosition GetMousePosition() {	MousePosition m;	RECT wndRect;	POINT mousePos;	GetWindowRect(hWnd, &wndRect);	GetCursorPos(&mousePos);	mousePos.x -= wndRect.left;	// These are the lines that account for the position of your window	mousePos.y -= wndRect.top;	mousePos.x-=4;		// UGLY HACK!! Account for left border	mousePos.y-=23;		// UGLY HACK!! Account for top of window	if (mousePos.x < 0) mousePos.x = 0;	// Don''t let it go off the left	if (mousePos.y < 0) mousePos.y = 0;	// Don''t let it go off the top	if (mousePos.x > screenWidth) mousePos.x = screenWidth; 	// Don''t let it go off the right	if (mousePos.y > screenHeight) mousePos.y = screenHeight;	// Don''t let it go off the bottom	mousePos.y = screenHeight - mousePos.y; // To return the bottom left pixel as (0,0), which is how OpenGL treats it.	m.x = mousePos.x;	m.y = mousePos.y;	m.z = 0;	return m;}  


www.coldcity.com
code, pics, life
[size="2"]www.coldcity.com code, art, life
Advertisement
Thanks loads! Ive added that to the program, and it works great! As per your suggestion, I am now looking into "UGLY HACK" alternatives .
Thanks again!
Um... I dont suppose anyone has any suggestions for my fullscreen problem now? As I said everytime I try to toggle fullscreen, the programs stops. What could this be?
zoidy
your forgetting that the system settings may differer...
to get exact values for window sizings, etc (there are quite a few you need to take into account) use GetSystemMetrics

It's been a while since i screwed about with it, but I think the left edge of the window will be GetSystemMetrics(SM_CXEDGE) and the top edge will be GetSystemMetrics(SM_CYCAPTION)-GetSystemMetrics(SM_CYEDGE). Not sure though (doesn't seem right)

[edited by - RipTorn on September 29, 2002 10:26:36 PM]
Which basecode did you download ?
If you started from the basecode of a tutorial, then you have to be carfeul of the tutorial you picked because some tutorials were (and some still are) famous for screwing up the fullscreen mode. If you look at older topics, you''ll regularily see thread titles like ''fullscreen problem'' because it has been discussed quite often.
Actually, I dont know... I extracted the NeHe elements from my previous project when I started the new one. Prob not a good idea. Ill go through and update stuff to his new basecode and see how I get on. Thanks all for your help....
zoidy

This topic is closed to new replies.

Advertisement