#148835 - iainprice - Thu Jan 10, 2008 11:08 pm
I have a game loop. I have the following code:
[code]
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(35, 256.0 / 192.0, 0.1, 40);
gluLookAt(0.0, 0.05, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
glMatrixMode(GL_MODELVIEW);
//model stuff here
[/code]
but it messes up, moving the camera......
am I setting the mode correctly?
#148837 - DiscoStew - Thu Jan 10, 2008 11:39 pm
Not being at my own computer makes this hard for me to check, but...
Do you mean moving the camera to a position you don't want, or continually moving the camera each frame? Dunno about the latter, but for the former, your gluLookAt call is showing that you are moving the camera slightly positive in the Y direction, and a fulll unit in the Z direction.
Later on today, I'll be at my computer, so perhaps I can look into it further. Until then, you may need to offer a bit more information, as well as some more code. Not saying to expose your project, no way, but having only a little bit of code to go by makes it hard for us to help if the problem is deeper than shown.
_________________
DS - It's all about DiscoStew
#148845 - zeruda - Fri Jan 11, 2008 4:11 am
iainprice wrote: |
I have a game loop. I have the following code:
Code: |
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(35, 256.0 / 192.0, 0.1, 40);
gluLookAt(0.0, 0.05, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
glMatrixMode(GL_MODELVIEW);
//model stuff here
|
but it messes up, moving the camera......
am I setting the mode correctly? |
Your glulookat should come after your setting the matrix mode to GL_MODELVIEW
#148875 - iainprice - Fri Jan 11, 2008 5:06 pm
Does
gluLookAt(0.0, 0.05, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
mean that it moves the camera by 0.05 and 1.0 each time it is called?
or does it put it to the co-ordinates 0, 0.05, 1.0?
I moved the model view to before but it still seems to move the camera even time it is called in the loop. I thought I needed the projection matrix as I was dealing with the camera......
#148891 - Rajveer - Fri Jan 11, 2008 7:04 pm
It doesn't offset those coordinates every frame, it sets and keeps it to whatever coords you set it to. So in your case it will keep it at (0, 0.5, 1). When you moved glMatrixMode(MODELVIEW) to before, did you load the identity matrix before gluLookAt()?
The projection matrix deals with projecting the image onto the screen, the modelview matrix is a combination of the older matrices for model (object manipulation) and view (camera movement). They realised that moving the camera and moving models are the same thing, so these matrices were combined to a single modelview matrix which deals with moving both models and the camera.
#148903 - iainprice - Fri Jan 11, 2008 8:08 pm
Does this mean that my moving the objects is also moving the camera.......
before I move my objects I push the matrix and at the end i pop it..... I think this movement must be effecting the camera....
hmmm.....
#148909 - M3d10n - Fri Jan 11, 2008 9:08 pm
First calculate your camera position (using variables) and then pass that to gluLookAt() as the camera position.