0

I understand the concept behind a frustrum viewing system; it's shaped like a pyramid, and as objects get closer to the center, they get smaller until they're finally clipped off. However, when using a viewing projecting in say, OpenGL (heads up: I don't use deprecated features), you set up your coordinate system like so:

orthoExample(left, right, bottom, top, near, far);

That's all fine, but when it comes to say, perspective, things get a bit strange.

perspectiveExample(field_of_view_y, aspect, near, far);

How do I go about setting up a coordinate system with a function like this?!? It doesn't let me specify a left, right, bottom, top, etc. I know perspective is just a variation of a frustrum projection...

Shokwav
  • 654
  • 8
  • 19
  • Indeed, its not as easy as orthogonal projection. I don't remember the maths, but you can take a look at the gluPerspective command of the GLU library. It simplifies a lot setting up a perspective projection. If you really want to, I can do some research of the maths and post them here (they are not that hard). – Vinícius Gobbo A. de Oliveira Oct 12 '12 at 03:10
  • I would recommend looking at GLM - the OpenGL Math library. It has routines to build all of those - and is geared toward GLSL (eg, non-deprecated features ;) ) http://glm.g-truc.net/ – Mark Stevens Oct 12 '12 at 03:22
  • I wish I could, but I'm using C. I'm using a similar library though, so if you could point me towards the similar GLM methods. @ViníciusGobboA.deOliveira: I'm using an equivalent of that function from a separate library, but I don't understand how to setup the coordinate system through that command? I understand that it uses frustrum internally. – Shokwav Oct 12 '12 at 13:48
  • 1
    I'll remove the dust from my books, and dig how the math is actually done. I have an old project (2009, I think) of a snooker game just for fun. I'll send you the cod snippet (or the whole project, if you want to) that uses gluPerspective to set up the projection. It is not exactly what you want, but it may help us both. – Vinícius Gobbo A. de Oliveira Oct 12 '12 at 23:17

1 Answers1

0

The code found here should clear things up for you.

The Z-axis is taken to be the center of projection. tan(fov_y)*near gives you top (and the negative, bottom). aspect is the ratio of width to height, so multiplying top by aspect gives you right and the negative of that is left.

beaker
  • 16,331
  • 3
  • 32
  • 49