Cas' magical perspective matrix

Started by Orangy Tang, January 06, 2005, 13:45:39

Previous topic - Next topic

Orangy Tang

Damnit, I'm sure this is lurking in the depths of the forums somewhere, but I canne find it anywhere. Cas mentioned his perspective projection matrix he used for 'Flux which has 1:1 pixel ratio of the z=0 plane, does anybody still have the code snippet lying around?

Cheers.

princec

float div = 1.0f / 64.0f;
			GL11.glFrustum(
				- Game.WIDTH * div,
				Game.WIDTH * div,
				- Game.HEIGHT * div,
				Game.HEIGHT * div,
				8,
				65536);


Cas :)

elias4444

So, what's the advantage of this vs glOrtho?
=-=-=-=-=-======-=-=-=-=-=-
http://www.tommytwisters.com

princec

Coz you can fiddle with the Z coordinate and get cool 3D :)

Cas :)

elias4444

Does it convert easily from glOrtho?
=-=-=-=-=-======-=-=-=-=-=-
http://www.tommytwisters.com

princec


elias4444

Meaning, in glOrtho you setup your board to draw 0 to width of screen, and 0 to height of screen (the cullfacing stuff also acts a bit funny). How do you use glFrustum instead? Do you have to completely convert your coordinate system?
=-=-=-=-=-======-=-=-=-=-=-
http://www.tommytwisters.com

princec

No, the whole point of that particular frustum setup is that if Z=0.0 then you've actually got an orthographic projection!

Cas :)

elias4444

Hmmm... I went ahead and tried it in place of my glOrtho command:
GL11.glOrtho(0, WIDTH, HEIGHT, 0, -2000, 2000);

No go however. I just get a blank screen.
=-=-=-=-=-======-=-=-=-=-=-
http://www.tommytwisters.com

princec

One subtle difference: 0,0 is in the middle of the screen I think.

elias4444

I've been trying to do this, but something is strange. I can't seem to zoom out, away from the playing board. I've been trying to use gluLookat to set my position and perspective, but it's not working. Any ideas?

My textures and things are still being rendered for orthographic mode with the full size being used (i.e., when I draw a sprite, I'm drawing it from 0,0 to 0,30, etc.). Do I need to shrink my stuff down to fractional sizes for this to work?
=-=-=-=-=-======-=-=-=-=-=-
http://www.tommytwisters.com

elias4444

Just doing some more experimenting, it seems that the gluLookAt command simply doesn't work on the z-axis.

Cas, what Z-level do you draw things on? I have to  glTranslatef(0,0,-800f) to start seeing things.
=-=-=-=-=-======-=-=-=-=-=-
http://www.tommytwisters.com

Chman

I've tested this "magical matrix" too, it works well but I must call a glTranslatef(0,0,-10) if I want to start seeing things...

I'm not very familiar with the glFrustrum method, so maybe I'm doing something wrong as elias4444 do...

Chman

elias4444

Something I'm noticing is that it seems to work better if you use fractions for your sizes and points rather than large "resolution" type numbers (i.e., 0.2f rather than 200f).
=-=-=-=-=-======-=-=-=-=-=-
http://www.tommytwisters.com

elias4444

I found this site talking about all the different perspectives... Personally, I've always needed pictures to help me understand something. This site did a great job:

http://mecadserv1.technion.ac.il/public_html/LabCourses/interActiveGraphics/ogl_course/ogl_lab/ogl_trans.htm
=-=-=-=-=-======-=-=-=-=-=-
http://www.tommytwisters.com