Wierd camera spin redux ^10

Started by
6 comments, last by Arch@on 20 years, 12 months ago
Today I was experimenting with some stuff(implemented the type of camera described in OpenGL super bible) and found out that if I move my mouse enough when not using loadIdentity instead of loadMatrix my camera starts to spin vigorously. Is this called Gimbal lock? Is there any easy way to prevent this other than limiting view range? If I use: glLoadMatrix(view); glRotatef(orientation[0], view[0], view[4], view[8] glRotatef(orientation[0], view[1], view[5], view[9] glTranslate(pos[0], pos[1], pos[2]); glGetFloatv(modelview_matrix, view); I don''t get that spin, but the camera behaviour changes and instead of camera rotation around own axis, I get extremely retarded camera rotation around point. Can someone explain this behaviour?
Advertisement
you found that in opengl super bible? can somebody shoot me? thats the book i used to get into opengl and why did i have to come up with something myself that was already there? which chapter? please tell me one of sweets (which i skiped after a few.. terrible explanations and some of his examples wouldnt even work). though this seems to use a little less work by not using a camera transformation but a view matrix and translate rather than doing it yourself with a few dotproducts..

is position a change in position? is it seperate from view?
are you sure you want to rotate orientation[0] degree around both axes? is this value reset, only used after input was made or applied each frame without being set to 0 after applying it?
else i''d have to the see more of the code.. maybe the whole rendering loop
f@dzhttp://festini.device-zero.de
Ahem, I figured the one myself(sort of looking through examples), but when I browsed through book, that is explained on page 631 opengl super bible second edition.

The first rotation is supposed to be orientation[1], which is y.

Actually I figured it out. The spin disappears, if I use the cardinal axes as the "direction" of rotation instead of using the last matrice as the direction of rotation.

So correct version is:

gl.loadIdentity();
gl.rotatef(orientation[1], 0, 1, 0);
gl.rotatef(orientation[0], 1, 0, 0); gl.translatef(-displacement[0],-displacement[1],-displacement[2]);

and then perhaps getFloatv if you want the matrix. At least it *seems* to work fine.
phew.. looked at it and its the "just rotate the cam somehow using some angles"-approach... its fine for fps cameras, as you just rotate around the global y and the local x axis.

if you dont want to roll or fly a plane with it thats as easy as it will get ,-)

your first code rotated abouot local y and x, so if you wanted fps style movement it might look wrong. if you rotate left/right while looking up/down..

whats happening to the position is quite easy. if position holds your current position, then youre adding it all the time. gltranslate will change the matrix, then you read it back into view, next time you apply the translation again, additional to the translation already stored in the view matrix.

and of course orientation should (like position) only contain the last change in angle/position and the angle/position itself. then its euler angles again and they will lose the order in which you transformed the camera which will never work when things get more than "quite simple" (like fps style for example)
f@dzhttp://festini.device-zero.de
Actually, it is easy to modify to get more than simple FPS camera as you can replace cameras matrix with the object''s matrix to get "around" object rotation. Basically I''d say this is a good camera start, although far away from complete camera.
right... for 3rd person you could just copy the objects matrix, rotate left/right and up/down and then move back. you''ll only get into trouble if you start rotating alot
f@dzhttp://festini.device-zero.de
I dont think that rotates for the cam stuff is a good idea on FPS
its not exactly the most efficient way.. but easy to understand and implement and... doing it once per frame for the camera makes the point of efficiency extremely obsolete.

except you also meant first person shooter with fps.. in that case i wouldnt know what you want to say.

[edited by - Trienco on April 29, 2003 12:50:55 PM]
f@dzhttp://festini.device-zero.de

This topic is closed to new replies.

Advertisement