Path: chuka.playstation.co.uk!news From: "SCEE" Newsgroups: scee.yaroze.programming.3d_graphics Subject: Re: Accessing screen translated vertices Date: Wed, 18 Feb 1998 18:09:07 -0000 Organization: PlayStation Net Yaroze (SCEE) Lines: 107 Message-ID: <6cf7ug$beo41@chuka.playstation.co.uk> References: <345BFB81.51488BFC@ibm.net> <345C1288.E288E7A@ibm.net> <345C279D.BD5E35D4@chat.carleton.ca> <345CEAA2.446B@peace.co.nz> NNTP-Posting-Host: 194.203.13.10 X-Newsreader: Microsoft Outlook Express 4.71.1712.3 X-MimeOLE: Produced By Microsoft MimeOLE V4.71.1712.3 Hi James, I think the lib function ApplyMatrix/SV/LV does this for you. If you look at the chrome demo ( somewhere on our site ) Stuart did, he used this to perform the environment mapping for each poly's uv's. Cheers, Colin. James Russell wrote in message <345CEAA2.446B@peace.co.nz>... >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.