world 2 screen coordinates

New Message Reply Date view Thread view Subject view Author view

Wilfried Zeise (zeise++at++uni-wuppertal.de)
Mon, 11 Oct 1999 18:36:58 +0200


Hi,

I want to transform a point from world coordinates to screen
coordinates. I used pfChannel::getViewMat to obtain the viewing matrix
(I read that I have to use the inverse of it). I also used
pfFrustum::getGLProjMat for the projection matrix. I wrote a simple
while loop, which looks like this:

while ( t >= 7.4)
{
 float s, c;
 pfCoord view;
 float h, v, near, far;

 // Compute new view position.
 pfSinCos(45.0f*t, &s, &c);
 view.hpr.set(45.0f*t, -5.0f, 0);
 view.xyz.set(2.0f * bsphere.radius * s ,
       -2.0f * bsphere.radius * c -5.0f,
       1.0f);
 // set view position for next frame
 chan->setView(view.xyz, view.hpr);
        if (t >= 8.4) t_plus = -0.016;
        t = t + t_plus;

 // Go to sleep until next frame time.
 pfSync();

 // Initiate cull/draw for this frame.
 pfFrame();

/* create info file to go with image */
 sprintf(str, "tex.%03d.info", counter);
 chan->getViewMat(viewmat);
 invviewmat.invertOrthoN(viewmat);
 frust->getGLProjMat(projmat);
if (fp = fopen(str,"w"))
        {
             fprintf(fp, "Viewing Matrix:\n %f %f %f %f\n %f %f %f %f\n
%f %f %f %f\n %f %f %f %f\n",

viewmat[0][0],viewmat[0][1],viewmat[0][2],viewmat[0][3],

viewmat[1][0],viewmat[1][1],viewmat[1][2],viewmat[1][3],

viewmat[2][0],viewmat[2][1],viewmat[2][2],viewmat[2][3],

viewmat[3][0],viewmat[3][1],viewmat[3][2],viewmat[3][3]);
             fprintf(fp, "Inverse Matrix:\n %f %f %f %f\n %f %f %f %f\n
%f %f %f %f\n %f %f %f %f\n",

invviewmat[0][0],invviewmat[0][1],invviewmat[0][2],invviewmat[0][3],

invviewmat[1][0],invviewmat[1][1],invviewmat[1][2],invviewmat[1][3],

invviewmat[2][0],invviewmat[2][1],invviewmat[2][2],invviewmat[2][3],

invviewmat[3][0],invviewmat[3][1],invviewmat[3][2],invviewmat[3][3]);
             fprintf(fp, "Projection Matrix:\n %f %f %f %f\n %f %f %f
%f\n %f %f %f %f\n %f %f %f %f\n",

projmat[0][0],projmat[0][1],projmat[0][2],projmat[0][3],

projmat[1][0],projmat[1][1],projmat[1][2],projmat[1][3],

projmat[2][0],projmat[2][1],projmat[2][2],projmat[2][3],

projmat[3][0],projmat[3][1],projmat[3][2],projmat[3][3]);
              fclose(fp);
          }
}

Now I tried the following computations:

[X' Y' Z' W'] = [X Y Z W] * viewmat* projmat

[X' Y' Z' W'] = [X Y Z W] * invviewmat* projmat

[X' Y' Z' W'] = [X Y Z W] * viewmat'* projmat

[X' Y' Z' W']' = projmat * viewmat * [X Y Z W] '

[X' Y' Z' W']' = projmat * viewmat' * [X Y Z W] '

and

[X' Y' Z' W']' = projmat * invviewmat * [X Y Z W] '

Nothing worked!!

For the conversion from normalized to screen coordinates I used:

winX = view(0) + view(2) * (X' + 1) / 2

winY = view(1) + view(3) * (Y' + 1) / 2

and

winZ = (v'(2) + 1) / 2

where view means the viewport.

I also tried a 90 degree rotation about X, that means I set X_new=X_old,
Y_new=-Z_old, and Z_new=Y_old.
This didn't work too.
Obviously, I obtained the wrong transformation matrices from my program,
but I can't find any error.

Thanks for any help,

Wilfried

begin:vcard
n:Zeise;Wilfried
x-mozilla-html:FALSE
org:University of Wuppertal
adr:;;Fuhlrottstr. 10;Wuppertal;;42097;Germany
version:2.1
email;internet:zeise++at++uni-wuppertal.de
title:Dipl.-Ing.
tel;fax:+49-202-4392959
tel;work:+49-202-4392961
note;quoted-printable:http://wetnt7.elektro.uni-wuppertal.de/zeise=0D=0A
x-mozilla-cpt:;0
fn:Wilfried Zeise
end:vcard


New Message Reply Date view Thread view Subject view Author view

This archive was generated by hypermail 2.0b2 on Mon Oct 11 1999 - 10:08:57 PDT

This message has been cleansed for anti-spam protection. Replace '++at++' in any mail addresses with the '@' symbol.