DrthM

03-13-2010, 09:27 AM

Hi there,

i have three real, fully calibrated Webcams, which should be represendet virtually. The Positions, FOV's, LookAt und Up-Vectors are given.

To confirm the Position optically, i render a single frame of the camera in front of it in 1 Unit Distance, according to the rotation (Up & right vectors) and FOV.

I use gluLookAt to render the original View of the camera. Afterwards, i grab the matrices for reprojecting purposes.

Now the problemdescription: If i set my Cameraperspektive with gluLookAt to the exact Settings of one of cameras, there is always a slight abberance. This becomes apparent, if the rendered frame (as mentioned before) does not fit exactly in the new Viewport.

Thats how i draw the Picture in front of each cam, all vectors except the Position are normalized.

GetFOV returns the horizontal Viewangle in radians.

float PixelSize=tan(GetFOV(...)/2.f)/(CAMRES_X/2.f);

//Defining the 4 corners of the projected Image

D1=CamPos+LookAt+PixelSize*CAMRES_Y/2*Up-PixelSize*CAMRES_X/2*Right;

D2=D1+(PixelSize*CAMRES_X)*Right;

U1=D1-(PixelSize*CAMRES_Y)*Up;

U2=D1+(PixelSize*CAMRES_X)*Right-(PixelSize*CAMRES_Y)*Up;

glColor3f(1,1,1);

glDisable(GL_COLOR_MATERIAL);

glEnable(GL_TEXTURE_2D);

Game.TextureManager->ActivateTexture(...);

glBegin(GL_QUADS);

glTexCoord2f(1.0f, 0.0f); glVertex3f(U2.x, U2.y, U2.z);

glTexCoord2f(1.0f, 1.0f); glVertex3f(D2.x, D2.y, D2.z);

glTexCoord2f(0.0f, 1.0f); glVertex3f(D1.x, D1.y, D1.z);

glTexCoord2f(0.0f, 0.0f); glVertex3f(U1.x, U1.y, U1.z);

glEnd();

And now the part, where it comes to the perspective issue:

glMatrixMode(GL_PROJECTION);

glLoadIdentity();

float degFOV=FOV/(2*PI)*360;

gluPerspective(degFOV*3/4,4.f/3.f,0.01,500.0); //3/4 because gluPerspective takes the horizontal angle

glMatrixMode(GL_MODELVIEW);

glLoadIdentity();

gluLookAt(Pos.x,Pos.y,Pos.z,

Look.x+Pos.x,Look.y+Pos.y,Look.z+Pos.z,

Up.x,Up.y,Up.z);

As i said, it works with a small imprecision. It seems like the perspective set by GLU has a too small view angle and the camera is a bit rotated around the LookAt axis.

Thanks in advance.

i have three real, fully calibrated Webcams, which should be represendet virtually. The Positions, FOV's, LookAt und Up-Vectors are given.

To confirm the Position optically, i render a single frame of the camera in front of it in 1 Unit Distance, according to the rotation (Up & right vectors) and FOV.

I use gluLookAt to render the original View of the camera. Afterwards, i grab the matrices for reprojecting purposes.

Now the problemdescription: If i set my Cameraperspektive with gluLookAt to the exact Settings of one of cameras, there is always a slight abberance. This becomes apparent, if the rendered frame (as mentioned before) does not fit exactly in the new Viewport.

Thats how i draw the Picture in front of each cam, all vectors except the Position are normalized.

GetFOV returns the horizontal Viewangle in radians.

float PixelSize=tan(GetFOV(...)/2.f)/(CAMRES_X/2.f);

//Defining the 4 corners of the projected Image

D1=CamPos+LookAt+PixelSize*CAMRES_Y/2*Up-PixelSize*CAMRES_X/2*Right;

D2=D1+(PixelSize*CAMRES_X)*Right;

U1=D1-(PixelSize*CAMRES_Y)*Up;

U2=D1+(PixelSize*CAMRES_X)*Right-(PixelSize*CAMRES_Y)*Up;

glColor3f(1,1,1);

glDisable(GL_COLOR_MATERIAL);

glEnable(GL_TEXTURE_2D);

Game.TextureManager->ActivateTexture(...);

glBegin(GL_QUADS);

glTexCoord2f(1.0f, 0.0f); glVertex3f(U2.x, U2.y, U2.z);

glTexCoord2f(1.0f, 1.0f); glVertex3f(D2.x, D2.y, D2.z);

glTexCoord2f(0.0f, 1.0f); glVertex3f(D1.x, D1.y, D1.z);

glTexCoord2f(0.0f, 0.0f); glVertex3f(U1.x, U1.y, U1.z);

glEnd();

And now the part, where it comes to the perspective issue:

glMatrixMode(GL_PROJECTION);

glLoadIdentity();

float degFOV=FOV/(2*PI)*360;

gluPerspective(degFOV*3/4,4.f/3.f,0.01,500.0); //3/4 because gluPerspective takes the horizontal angle

glMatrixMode(GL_MODELVIEW);

glLoadIdentity();

gluLookAt(Pos.x,Pos.y,Pos.z,

Look.x+Pos.x,Look.y+Pos.y,Look.z+Pos.z,

Up.x,Up.y,Up.z);

As i said, it works with a small imprecision. It seems like the perspective set by GLU has a too small view angle and the camera is a bit rotated around the LookAt axis.

Thanks in advance.