View Full Version : perspective view of model.....
09-28-2002, 01:55 PM
Hello, I am very new to openGl programming and I am trying to set up a window that uses the mouse to control translation rotation and zooming. Similart to a perspective window in a 3d modelling application. I am using glutMouseFunc() and glutMotionFunc(). I have it setup so that when the left mouse butoon is pressed, the mouse movements are contolling rotation, the middle button, controlls the translation, and the right button if for the zooming. Everything works fine, exept, when I translate and rotate an object and release the mouse buttons, then go to rotate the object or move it a little more, the translation and rotation that were there get zeroed out, and rotation and translation then pick up from zero. Does any of this make sense, I am trying to explain as well as I can. Any help in gettin this to work will be greatly appreciated. I basically know that the new rotation and translation values that I apply need to be added to the last translations, but I can'g get it to work....If you need to see source code for a better idea, just let me know and I'll post it...Thanks again.
09-28-2002, 03:37 PM
Its most likely that your values are not global enough and are being reset.
Are you initialising variables in say only the initGL routine with the mouse altering these values.
if leftbutton then gv_rotx++;
if middlebutton then gv_posx++;
If you do something similar to this the values would only reset when you rerun the program or choose to reset them.
Hope that helped you and that I understood the problem.
09-28-2002, 05:08 PM
the variables are actually declared and initialized at the very top of the source file, globally outside all functions...Here is a little of the code...
void display( void )
glClear( GL_COLOR_BUFFER_BIT );
glMatrixMode( GL_MODELVIEW );
glTranslatef( trans_x, trans_y, -5 - zoom );
glRotatef( spin_y, 1.0, 0.0, 0.0 );
glRotatef( spin_x, 0.0, 1.0, 0.0 );
void screen_mouse( int button, int state, int x, int y )
old_x = x;
old_y = y;
void screen_motion( int x, int y )
spin_x = x - old_x;
spin_y = y - old_y;
I deleted all the stuff about the buttons and took out everything that wasn't necessary to post. I saw this code in a tutorial c project from a siggraph class, but thier window does the problem I talked about earlier, with the values being zeroed every time. In the screen motion function, if I change the spin_x assignment to :
spin_x += x - old_x; and the same for the y, it works, as in , adds the new values to the previous values, but it keeps adding the values together and the rotations get very large. Maybe this will reveal the problem, and maybe you can explain to me why they subtract the old_x and y from the new x and y....Please remember, I am very new to openGl and programming in general...Thanks again....
09-28-2002, 05:49 PM
Hmm, I have always used += etc to increment values to be used in these things... and yes I get similar problems with numbers getting too large... so I usually cap it so that visually it looks okay... to me anyway.
I tried out the type of code you are doing in one of my test glut programs and I can see what you are having... however, technically OpenGL programs always reset the scene from what I have read. It is only the values passed to individual functions that tell it how to change it...
debugging the code though shows that once you stop clicking the mouse the variables used are reset to 0 for some reason and only when I use += that it doesn't do this...
However, I can't explain the reason for this problem as I haven't been programming in OpenGL that long, just a few months so hopefully someone else can give a more experienced answer to this problem..
09-28-2002, 07:34 PM
Well thank you, At least you see the problem I am having....I imagine that this is a fairly simple problem to fix for an experienced openGl programmer. Thanks again for the response and Hopefully, If I get this to work correctly, I will post my solution.....
Powered by vBulletin® Version 4.2.2 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.