 |
 |
Using the mouse with OpenGL
|
 |
|
 |
|
Mac Elite
Join Date: Jan 2001
Location: Sad King Billy's Monument on Hyperion
Status:
Offline
|
|
Can anyone direct me to some sample code or a tutorial of a mouse-controlled OpenGL environment? Just something that ties the camera rotation to the mouse movement. You'd think this would be easy to find, but so far I haven't had much luck. Thanks to all who reply.
|
|
I abused my signature until she cried.
|
| |
|
|
|
 |
|
 |
|
Admin Emeritus 
Join Date: Oct 2000
Location: Boston, MA
Status:
Offline
|
|
Using Cocoa or GLUT?
There should be something at nehe.gamedev.net for mouse-movement in GLUT.
As for Cocoa, you may want to check out GDCExamples from OmniGroup.
|
|
"Against stupidity, the gods themselves contend in vain" (Schiller)
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Jan 2001
Location: Sad King Billy's Monument on Hyperion
Status:
Offline
|
|
Originally posted by parallax:
<STRONG>Using Cocoa or GLUT?
</STRONG>
Whichever I find works best; I haven't started yet.
There should be something at nehe.gamedev.net for mouse-movement in GLUT.
I was checking that out yesterday, but the closest thing I found was a tutorial for controlling movement via the keyboard. I'll look again.
As for Cocoa, you may want to check out GDCExamples from OmniGroup.
Thanks. I'll take a look.
|
|
I abused my signature until she cried.
|
| |
|
|
|
 |
|
 |
|
Senior User
Join Date: Mar 2000
Location: Ithaca, NY
Status:
Offline
|
|
Take a look at the project in /Developer/Examples/GLUTExamples, which should be there if the dev tools are installed. The target named "Walker" has some GLUT code to handle camera movement with the mouse.
|
|
|
| |
|
|
|
 |
|
 |
|
Fresh-Faced Recruit
Join Date: Jul 2001
Location: San Francisco, CA
Status:
Offline
|
|
It may be difficult to find because there are no camera-specific functions in OpenGL. There's a model-view matrix stack with which you apply transformations to define the spatial relationship between model space (the objects in the scene) and view space (where the implicit virtual camera lies). GLU (the utility layer over OpenGL, not to be confused with GLUT, the GL Utility Toolkit which deals with windows and event handling) has a function gluLookAt which allows you to specify which direction (and with which orientation) you want the camera to look at.
Porbably the simplest way to get started is to tie x and y mouse movement to tethered rotation about an object (it's easier to debug than a camera that freely moves around in space beceause the camera is always looking at the center on your scene). Before rendering your geometry, apply the following transformations:
glTranslated( 0., 0., -z ); // pull the camera back from the scene
glRotated( x, 0., 1., 0. ); // rotate x degress about the y axis
glRotated( -y, 1., 0., 0. ); // rotate -y degress about the x axis
Appropriate values of z depend on the size of the objects in your scene. This will keep your camera on the inside of a sphere of radius z, looking at the center, with the y-axis aligned vertically. This works well for studying an object from any angle, like a QTVR of an object (not the panoramic ones).
Since I don't know your level of experience with OpenGL or 3D in general, I'm not sure if I'm insulting your intelligence or talking way over your head. There are countless ways to control the camera with the mouse, and without knowing more about what you intend to do, it's impossible to say what the best or simplest approach is.
|
|
|
| |
|
|
|
 |
|
 |
|
Fresh-Faced Recruit
Join Date: Jul 2001
Location: San Francisco, CA
Status:
Offline
|
|
After running those rotations through my head, I realized that I had them backwards (unless you want the x-axis to be always horizontally aligned). So those transformations should look like this:
glTranslated( 0., 0., -z ); // pull the camera back from the scene
glRotated( -y, 1., 0., 0. ); // rotate -y degress about the x axis
glRotated( x, 0., 1., 0. ); // rotate x degress about the y axis
So if your object is a globe with the polar axis running along the y axis then the pole will always be vertical (except for the degenerate case where you're looking straight down on the pole).
|
|
|
| |
|
|
|
 |
 |
|
 |
|
|
|
|
|

|
|
 |
Forum Rules
|
 |
 |
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
 |
 |
 |
 |
|
 |
|