Jump to content
  • Advertisement
Sign in to follow this  
ursus

OpenGL how to look around with mouse?

This topic is 4869 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello Forgive me if this question was answered before but I don’t seem to be able to find any answer. I’m learning OpenGL and presently I’m at the stage where I’d like to control where the camera is headed with the mouse. This is what I came up with so far: float heading_horizontal; float heading_vertical; float old_mouse_posx; float old_mouse_posy; float new_mouse_posx; float new_mouse_posy; In the windows msg checking: case WM_MOUSEMOVE: { new_mouse_posx = LOWORD(lparam); new_mouse_posy = HIWORD(lparam); heading_horizontal-= old_mouse_posx - new_mouse_posx; heading_vertical-= old_mouse_posy - new_mouse_posy; old_mouse_posx = new_mouse_posx; old_mouse_posy = new_mouse_posy; } This kind of approach appears to work fine as long as the pointer moves within the screen/window. Then the movement stops. How can I control the camera heading without the screen/window boundaries? This is done in hundreds of games. I’d be very happy for some quick explanation or a link to some article or thread or anything Thank you

Share this post


Link to post
Share on other sites
Advertisement
hi,

in general, you put the "real" mouse after each movement
back to the middle of your window.

and with the relative movement you can work with your camera...

Marc

Share this post


Link to post
Share on other sites
This is what I did:



CameraZAngle -= ( new_mouse_posy-windowCentrey)*(Pi/900.0f);
CameraYAngle -= ( new_mouse_posx-windowCentreX)*(Pi/900.0f);
SetCursorPos(windowCentreX, windowCentreY);
new_mouse_posx = windowCentreX;
new_mouse_posy = windowCentreY;
// Calculate DirectionVector (Vector3)
CameraDirection.Set(-sin(CameraYAngle)*sin(CameraZAngle), cos(CameraYAngle)*sin(CameraZAngle), cos(CameraZAngle));





(The Pi/900.0f is for not rotating to fast.)

Putting the mouse back to the centre of the screen is done by "SetCursorPos(windowCentreX, windowCentreY);"

Share this post


Link to post
Share on other sites
Thank you for suggestions.

I tried to implement Kwak's idea (which appears to be the only logic way) but if I SetCursorPos every frame the window with GL Scene is kind of transparent (nothing is visible) and if I go full screen weird transparent thigs happen but the scene isn't renered also.

My best guess is that something is holding the buffer or something. The application is alive since I can see the pointer trying to move and returning to the middle of the screen. Tried adding sleep(10) but that didn't help much.

Any idea what I could be doing wrong?

I use the NeHe code tamplate and add heading vectors and SetCursorPos in WM_MOUSEMOVE message

Share this post


Link to post
Share on other sites
glClear(GL_COLOR_BUFFER_BIT);
must be done after a viewport is set, and the "SwapBuffers(hDC);" command may not be forgotten.

If glClear(GL_COLOR_BUFFER_BIT); is never done for a certain area in the window that area wil be transparent -> you will see other applications (or the desktop) flickering behind it.

I guess this has been done, so the only thing i can think of is the "SwapBuffers(hDC);" command is: never reached.

(If you want to get rid of the cursor you can use the command "ShowCursor(false);")

[Edited by - Kwak on November 22, 2005 1:24:39 PM]

Share this post


Link to post
Share on other sites
My mistake. Many thanks to Benryves who pointed that I put SetCursorPos in the WM_MOSEMOVE message. As the result WM_MOSEMOVE was called in some constant loop disallowing, just like Kwak was suspecting to SwapBuffers.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!