Camera class for parallel projection.

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Camera class for parallel projection.

The.Scotsman
I've been working on a 3d graphics app for a while, and I've been utilizing a camera class (gleaned from here and elsewhere) to provide the mouse/keyboard pan/zoom/rotate functionality.

It uses gluPerspective+gluLookAt to provide the transformations, and it's worked fairly well (other than an annoying orientation "flip" during some zoom factors).

However, for other reasons, I need to switch to a parallel projection (i.e. glOrtho + gluLookAt) and:
1) For the life of me, I can't get it to work right.
2) Spent all day searching, and I can't find any examples anywhere (everybody these days uses perspective!)

I would be so grateful if someone would please put me out of my misery and show me where I can find a good working example (no gimble lock, handles large and small near/far values, etc.), suitable for someone who is severely linear algebra challenged...

Many, many thanks.
Reply | Threaded
Open this post in threaded view
|

Re: Camera class for parallel projection.

Wade Walker
Administrator
Well, when I hear someone say they want to avoid gimbal lock, the first thing I think is "use quaternions" :) Which sounds scary, but here's an example of someone doing a camera class with them: http://content.gpwiki.org/index.php/OpenGL:Tutorials:Using_Quaternions_to_represent_rotation
Reply | Threaded
Open this post in threaded view
|

Re: Camera class for parallel projection.

gouessej
Administrator
Quaternions aren't enough, you have to avoid using Eulerian transforms which is easier with quaternions. Otherwise, you have to treat some special cases, the singularities on poles.
Julien Gouesse | Personal blog | Website
Reply | Threaded
Open this post in threaded view
|

Re: Camera class for parallel projection.

The.Scotsman
Thanks for the quick replies guys.

Using quaternions sounds like a good implementation strategy.
Does anyone know where it's been utilized for a JOGL camera class (parallel projection)?
It must have already been invented many times by many people...just can't find one!
(Think CAD viewers)
Reply | Threaded
Open this post in threaded view
|

Re: Camera class for parallel projection.

jmaasing
Another common way to handle the camera is by defining it through 3 vectors (up, forward, right for example). There is no gimbal lock since there are no angles stored but leaves some more calculations to the user of the camera to turn it around et c

There are o.f.c. many camer aimplementations in the scene graph APIs, I'm sure guossej can point to Ardor3D.
Here is libgdx camera.
https://github.com/libgdx/libgdx/blob/master/gdx/src/com/badlogic/gdx/graphics/OrthographicCamera.java

And jMonkeyEngine:
https://github.com/jMonkeyEngine/jmonkeyengine/blob/master/jme3-core/src/main/java/com/jme3/renderer/Camera.java

Hope that gives some inspiration.