PDA

View Full Version : Help with OpenGL orbit, strafe and zoom controls



MOGL_Edit
12-16-2016, 08:23 PM
Does anyone know how to make it so when I move the mouse, it will orbit the camera (inverted controls so up is down and left is right) and so when I move the mouse it will strafe my camera (moving mouse left moves the camera to the right), and when I scroll the camera will move forwards/backwards?

I am using OpenTK with C# and I have the detection code for when the mouse is being moved when the right mouse button is being clicked and for when the left mouse button is being clicked but now I just need to move the camera around the scene.

I don't have the middle mouse zoom code though.

I have basic keyboard controls set up that rotate the model and can scale it but these are restricted and I want to be able to move around in my scene quickly and easily.

Dark Photon
12-17-2016, 11:16 AM
Does anyone know how to make it so when I move the mouse, it will orbit the camera (inverted controls so up is down and left is right)

This is called a "virtual trackball". If you websearch it, you'll end up with many hits, including one in the OpenGL wiki.

If you think about your camera as 1) a position, 2) a look direction, and 3) an up vector defined in WORLD space (the inputs to gluLookAt or similar), and you consider rotating this camera on the surface of a sphere around a center point, you can probably work out what should happen to these values for a given mouse movement vector.


and so when I move the mouse it will strafe my camera (moving mouse left moves the camera to the right), and when I scroll the camera will move forwards/backwards?

This is just standard panning (translation) of your camera's position in WORLD space (#1 above).

MOGL_Edit
12-18-2016, 06:44 PM
This is called a "virtual trackball". If you websearch it, you'll end up with many hits, including one in the OpenGL wiki.

Do you know the C# code for this? I've tried several times to do this myself but it never works.




This is just standard panning (translation) of your camera's position in WORLD space (#1 above).

I want my control to be smooth. I made this myself and it works but the controls feel so loose and inaccurate so I want professional code. All my code did was check if the mouse was greater than the previous value, if so then it moved the camera, if it was lower it moved the camera in a different direction.

Dark Photon
12-19-2016, 07:28 PM
Do you know the C# code for this? I've tried several times to do this myself but it never works.

No. If you find a trackball implementation you like though, you should be able to port it to C#. See if you can find one you like.

Failing that, feel free to post specific questions on what you've tried and what specific problems you're having. Should you decide to, we can move this thread to the Math and Algorithms forum. I'll bet there are some folks here that could help you out.


I want my control to be smooth. I made this myself and it works but the controls feel so loose and inaccurate so I want professional code. All my code did was check if the mouse was greater than the previous value, if so then it moved the camera, if it was lower it moved the camera in a different direction.

You might consider putting some filtering on your virtual camera, and/or reducing the sensitivity of the virtual camera to changes in your mouse.