Problem with gluLookAt

Started by amoeba, August 12, 2004, 15:22:57

Previous topic - Next topic

amoeba

I just cant get the bugger working.

I want a 2d type view, but be able to zoom in and out like Grand Theft Auto. I try using gluLookAt, but if I change the camera Z coord it does not effect the distance of the drawn objects - it just draws nothing when its negative.

Would anyone mind looking at my project/code and tell me what I am doing wrong please? I've been tearing my hair out all day over this, and you get a cool little game to fiddle with :) !

www.alexjascott.demon.co.uk/trek.zip

Kokoni

Hi amoeba,

Maybe I'm wrong cause I'm not a opengl expert,  but do you increase the back face of your frustum in the gluPerspective methode ? If you move back your camera, the frustum will move back too, so the far objects will be out and they will not appear.

Try to increase the last parameter of the gluPerspective methode for growing your frustum each time you move back the camera.


I hope it helps you,

Kokoni.

amoeba

Its already set to 1000, and I dont move that much so it should be fine.

Thanks for looking though, I think its going to be something fiddly that only a opengl expert or someone who has experienced the problem before will spot.

amoeba

Can you even change camera z axis position when using ortho mode?

princec

Changing z in ortho project has absolutely no perspective effect. That's why it's called orthographic mode. You need a perspective projection.

Cas :)

amoeba

Thats what I thought, but if I remove the gluOrtho2d it now draws nothing - any ideas?

Jonbca1

Hey, my guess for why nothing is showing up on screen is thatl, since it's now in perspective mode, you have to add the z component. Basically, change all your GL11.glVertex2i(x,y) to GL11.glVertex3f(x,y,z). Im not a pro, but thats my guess.

amoeba

Everything bar my font blitter uses glvertex3 already, with the Z coord set to 0.

princec

You should use glVertex2f (or 2i) for 2D graphics; the 0 z coord is implicit.

The perspective projection matrix for Alien Flux looks like this:
GL11.glMatrixMode(GL11.GL_PROJECTION);
		GL11.glPushMatrix();
		GL11.glLoadIdentity();
		GL11.glFrustum(
			- Game.WIDTH / 64.0,
			Game.WIDTH / 64.0,
			- Game.HEIGHT / 64.0,
			Game.HEIGHT / 64.0,
			8,
			65536);
		GL11.glMatrixMode(GL11.GL_MODELVIEW);
		GL11.glLoadIdentity();

which is a weird way of doing it (I calculated the frustum in my head somehow) but it works, and on the z=0 plane, it's orthographic. You can zoom in and out of it by simply using glTranslatef on the z coordinate.

Cas :)

amoeba

Thanks guys, I managed to get it working in the end. Not quite sure what it was - re-wrote the whole render() procedure in the end.