LWJGL Forum

Programming => Lightweight Java Gaming Library => Topic started by: Orangy Tang on January 06, 2005, 13:45:39

Title: Cas' magical perspective matrix
Post by: Orangy Tang on January 06, 2005, 13:45:39
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.
Title: Cas' magical perspective matrix
Post by: princec on January 06, 2005, 17:49:28

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


Cas :)
Title: Cas' magical perspective matrix
Post by: elias4444 on January 20, 2005, 21:56:15
So, what's the advantage of this vs glOrtho?
Title: Cas' magical perspective matrix
Post by: princec on January 20, 2005, 21:58:58
Coz you can fiddle with the Z coordinate and get cool 3D :)

Cas :)
Title: Cas' magical perspective matrix
Post by: elias4444 on January 20, 2005, 22:09:27
Does it convert easily from glOrtho?
Title: Cas' magical perspective matrix
Post by: princec on January 20, 2005, 22:19:32
Convert what?

Cas :)
Title: Cas' magical perspective matrix
Post by: elias4444 on January 20, 2005, 22:24:11
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?
Title: Cas' magical perspective matrix
Post by: princec on January 20, 2005, 22:33:40
No, the whole point of that particular frustum setup is that if Z=0.0 then you've actually got an orthographic projection!

Cas :)
Title: Cas' magical perspective matrix
Post by: elias4444 on January 20, 2005, 22:51:18
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.
Title: Cas' magical perspective matrix
Post by: princec on January 20, 2005, 23:02:08
One subtle difference: 0,0 is in the middle of the screen I think.
Title: Cas' magical perspective matrix
Post by: elias4444 on January 21, 2005, 16:18:30
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?
Title: Cas' magical perspective matrix
Post by: elias4444 on January 21, 2005, 19:47:23
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.
Title: Cas' magical perspective matrix
Post by: Chman on January 21, 2005, 21:31:32
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
Title: Cas' magical perspective matrix
Post by: elias4444 on January 21, 2005, 21:42:58
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).
Title: Cas' magical perspective matrix
Post by: elias4444 on January 21, 2005, 21:59:38
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