Sorry for long code posting, but…
I am using having a problem with the rotation function in my MFC SDI App…
The App loads 3D models and allows the user to perform Panning, Zooming, and Trackball Rotation. All three functions work perfectly EXCEPT…
When tracking or panning, if my app window loses focus and has to refocus (i.e. I open another window and go back to my app window, or if I minimize then restore) the model rotates/pans back to a previous position until I click and start moving my mouse again. Then it continues as normal.
I have never programmed an OpenGL app at all, so this code is a result of converting from OpenGL functions called in legacy C code with a different GUI package. I was wondering if someone could review my View.cpp file to see if I am doing something inherently wrong or if it is just a small fix.
REMOVED LONG CODE
[This message has been edited by mandyV (edited 03-06-2002).]
wow thats a lot of code!!!
The code was too long for me to read through, so I can only give you generic advice.
Look for glLoadIdentity in your OnSize() code or any code that it calls. That resets the model view matrix and removes any transforms (rotation, translation, etc) you may have done before. If you find any and you don’t want to loose your matrix do a glPushMatrix() before you call glLoadIdentity() and do a glPopMatrix() when you want to get back your old matrix.
See if you have any related code in an OnBlur message handler (or any other called when you get or loose focus). You’re looking for the same thing as you did in 1).
Check for transforms and changes to your rotation variables that are conditional. It may be that one of your message handlers changes a state which causes your rendering function to behave differently (like calling glRotate() or glPopMatrix() when it should not).
Finally, check if you accidentally have any assignments to your rotation variables where you should have had comparisons. People tend to make that mistake in if statements, etc.
I know it sounds tedious, but you have to take the time if you want to do a good job.
Thanks for the tips…
What I had to do was add the OnActivateWindow handler and (sort of like the blur thing) and in that method, reset my angles and panning values to 0.