menu
-
CGWorldFrame::GetScreenCoordinates
bool __thiscall CGWorldFrame::GetScreenCoordinates(C3Vector const&, C3Vector*, CGWorldFrame::SCREEN_RESULT *, bool *)
0x004C97A0 (Rebased)
Has anyone worked with this function before? I'm trying to use it in place of a big WorldToScreen function. When I try to use it, I get strange numbers in the out vector, normally -2 to +2 for X and Y, and around 10 to 40 for Z. The return bool value is whether the position is in the screen. It's always correct.
I've tried looking into exactly what the function does after it gets the coordinates but can't find the exact math/functions I need to use. I could use a hand here 
Thanks in advance.
-
Contributor
Don't know if it gets you any further... but the SCREEN_RESULT has flag 8 set when the x coordinate is in the viewport and flag 4 set when y is in the viewport. Flags 1 and 2 are always set, if the vector passes the near plane clip. If so, the out bool is set to false, meaning basically clippedAway. The return value of the function returns true if the flags are (or would be) set to 15.
You can get the projection matrix from [worlframe + 668] currently. The NDC viewport (4 floats) is at 648, another viewport-ish values are used from 104 before exit.
They project like this: Get the vector relative to camera or eye position (prob eye). Get the transformed vector (with added w coordinate ofc) by multiplying with the matrix. If the result's z is lower than nearclip, discard. Then normalize the vector by its w component.
My computer graphics math isn't that fresh, but you should check here if you have your result.
Else go further and do some strange stuff: add 1 to both x and y and divide by 2 (like (x+1)/2), multiply with the NDC viewport width/height (for x/y) and perform the NDCToDDC conversion (normalized device coordinates to whatever-blizz-means-by-the-first-D device coordinates), which currently only multiplies x by 0.8 and y by 0.6.
Regarding the last quarter of the function I can't say anything with certainty... here comes the second DDC viewport I mentioned into play.
Also, I found the function at 004E0360 in the database from 15595
Edit: I actually worked with an old mac build too and failed at spotting the right offset in the current version, so the matrix should be at [worldframe + 664].
Last edited by Bananenbrot; 06-03-2012 at 03:06 PM.
-
Yeah I am actually using that offset as well. I accidentally wrote the one from the 15508 debug build. Thanks for the info, I'll let you know how I go.