Path: chuka.playstation.co.uk!news From: James Russell Newsgroups: scee.yaroze.programming.3d_graphics Subject: Re: Accessing screen translated vertices Date: Mon, 03 Nov 1997 10:03:30 +1300 Organization: Peace Computers NZ Ltd Lines: 87 Message-ID: <345CEAA2.446B@peace.co.nz> References: <345BFB81.51488BFC@ibm.net> <345C1288.E288E7A@ibm.net> <345C279D.BD5E35D4@chat.carleton.ca> NNTP-Posting-Host: intro.peace.co.nz Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Mailer: Mozilla 3.0Gold (X11; I; IRIX 6.2 IP22) Tim O'Neil wrote: > > Well, you're right, the process (in theory) is sorta complicated, but > really its very simple to do. I managed to get it working by doing the calculation manually (although I didn't realize that when you get a RotMatrix, each value is multiplied by "ONE" (4096). So you have to divide by 4096 when you're done. Essentially my code does this now (of course, it's optimised much more than this): Xo = vertex.x // Copy the (X,Y,Z) of this vertex. Yo = vertex.y Zo = vertex.z rotate.x = pitch; rotate.y = heading; rotate.z = roll; RotMatrix(&rotate, &RotationMatrix); // Creates a rotation matrix from my heading, pitch and roll RotationMatrix.t[0] = translateX; // Move the object around. RotationMatrix.t[1] = translateY; RotationMatrix.t[3] = translateZ; RM = &RotationMatrix; Xw = (RM->m[0][0] * Xo + RM->m[0][1] * Yo + RM->m[0][2] * Zo) / 4096 + RM->t[0]; // Calculate World space coords Yw = (RM->m[1][0] * Xo + RM->m[1][1] * Yo + RM->m[1][2] * Zo) / 4096 + RM->t[0]; Zw = (RM->m[2][0] * Xo + RM->m[2][1] * Yo + RM->m[2][2] * Zo) / 4096 + RM->t[0]; // Screen space is the same as world space for me, except the viewpoint is at (0,0,-1000) Zw -= -1000; // Move everything forward 1000, which is the same as the viewpoint moving BACK 1000. Using this handy little ASCII art diagram of similar triangles: Screen Point (Ys)| ___---+ (Yw,Zw) ___---+- | __--- | | +___________+_______+_ Z axis +ve -> Eye Origin <----------> Projection distance (h) We see that (using similar triangles): Ys Yw -- = -------- h (Zw + h) Therefore: Ys = (h * Yw) / (Zw + h); (There are nicer ways of doing this, but they're just optimisations). Finally: Xscreen = (PROJECTION_DISTANCE * Xw) / (Zw + PROJECTION_DISTANCE); Yscreen = (PROJECTION_DISTANCE * Yw) / (Zw + PROJECTION_DISTANCE); Yay! I finally got the coordinates I was looking for. Of course, this only works if your screen space is the same as World space Something unusual though - The aspect ratio of these points is different to what I'd expect - so I guess the Yaroze does some scaling to counter the effects of different screen resolutions. I haven't got my Foley-Van Damme book in front of me so I can't check - but isn't the transpose of a Rotation Matrix the inverse of that matrix? If it is, this would help if I ever wanted to use a dynamic screen space. Cheers, J -- ==PEACE COMPUTERS ==James.Russell@peace.co.nz - 64(9)3730400 -Fax 64(9)3730401 Make like a shepherd and get the flock out of here.