Angus Dorbie (dorbie++at++sgi.com)
Mon, 11 Oct 1999 11:23:05 -0700
Track the point through to eye space then projection coordinates and
then screen.
You could also just try transforming through the matrices in turn to
test your matrices without multiplying the 4x4's together. This will be
faster anyway if you only want to test one or a few points. It will also
let you quickly check to see if you are multiplying correctly.
Posting your whole process and saying it doesn't work is unlikely to
meet with a successfull response, investigate some more, print out the
transformed vertex, and good luck.
Cheers,Angus.
Wilfried Zeise wrote:
>
> 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
--
"One of the best-known folk theorems of software engineering is that
60% to 75% of conventional software projects are either never
completed or rejected by their intended users. If that range is
anywhere near true (and I've never met a manager of any experience
who disputes it) then more projects than not are being aimed at goals
which are either (a) not realistically attainable, or (b) just plain
wrong."
Eric S. Raymond - The Cathedral and The Bazaar
For advanced 3D graphics Performer + OpenGL based examples and tutors:
http://www.dorbie.com/
This archive was generated by hypermail 2.0b2 on Mon Oct 11 1999 - 11:23:11 PDT