PDA

View Full Version : How to set up proper perspective?



betwixt
03-08-2010, 10:29 AM
Hello, I am making an augmented reality application, without object recoqnition on Android platform. I am drawing OpenGL layer over camera preview. I want to set up real world units to match the units in OpenGL layer.

When I draw a plane with width 1f to a distance of 1f then it matches on the camera the width of a door at distance of 1 meter. The doors width however is ~0.5 meters.

http://betwixt.kirves.pri.ee/Stuff/1mDoor3D.JPG
http://betwixt.kirves.pri.ee/Stuff/1mDoorOnTop.JPG

Currently I set up the perspective and viewport like this:

gl.glViewport(0, 0, width, height);
gl.glMatrixMode(GL10.GL_PROJECTION);
gl.glLoadIdentity();
GLU.gluPerspective(gl, 52.0f, (float)viewWidth / (float)viewHeight, 0.1f, 100f);
gl.glMatrixMode(GL10.GL_MODELVIEW);
gl.glLoadIdentity();

Where 52.0f is approximately the maximum degree that I measured that my camera can view horizontally. viewWidth and viewHeight are the width and height of the camera view.

How can I set up the OpenGL layer so that a OpenGL plane with a width 0.5f at the distance 1f would appear the same with as the door at the distance of 1 meter with width 0.5f? Should I play with fovy or the aspect ratio? Or should I use glFrustum instead?

One more thing: Can You please tell me why the red plane on the picture covers the white lines, but is partially transparent to the camera image?

Tim Moore
03-08-2010, 12:06 PM
Hello, I am making an augmented reality application, without object recoqnition on Android platform. I am drawing OpenGL layer over camera preview. I want to set up real world units to match the units in OpenGL layer.

When I draw a plane with width 1f to a distance of 1f then it matches on the camera the width of a door at distance of 1 meter. The doors width however is ~0.5 meters.

Currently I set up the perspective and viewport like this:

gl.glViewport(0, 0, width, height);
gl.glMatrixMode(GL10.GL_PROJECTION);
gl.glLoadIdentity();
GLU.gluPerspective(gl, 52.0f, (float)viewWidth / (float)viewHeight, 0.1f, 100f);
gl.glMatrixMode(GL10.GL_MODELVIEW);
gl.glLoadIdentity();

Where 52.0f is approximately the maximum degree that I measured that my camera can view horizontally. viewWidth and viewHeight are the width and height of the camera view.


The field of view argument to gluPerspective is the vertical field of view, not the horizontal field of view.

Tim

betwixt
03-08-2010, 01:09 PM
Thank You Tim! I spent days trying to figure it out. It's ok now :). I measured the vertical view angle, was about 33,5 degrees and put it to gluPerspective. Now the units match :)

Pziko
03-08-2010, 01:37 PM
Beer, is there anything it can't do? :)

betwixt
03-08-2010, 04:06 PM
Me not understanding what I was doing wrong has unfortunately nothing to do with beer :). These are my roommates beer bottles. I don't drink beer. xP