how to look around with mouse?
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
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
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
This is what I did:
(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);"
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);"
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
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
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]
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]
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement