Fast World2Screen Transform (Synced/Async)

Fast World2Screen Transform transforms world coordinates to screen coordinates and back, i.e. determine where an object at point (x, y, z) on the map is drawn for a player on the screen.

Because this transformation is dependent on a player's camera position, which is not synced, the resulting screen position will not be synced either. You have, however, the option to use the sync version, which continuously syncs the camera parameters between players, so that the synchronized screen positions can be retrieved without a delay.

World2Screen is extremely fast (~300 nanoseconds) and 99.9% accurate. Screen2World is a bit slower as it has to search for the intersection point of a ray through the world. The Screen2World function will fail if there are multiple intersection points (which usually does not happen for normal camera angles).
Contents

SyncedCamera (Binary)

World2Screen (Binary)

World2ScreenSync (Binary)

World2ScreenTransform (Map)

Reviews
Wrda
Math beyond me, magic numbers, a recipe for great explosion of excitedness. Looks optimized, and works spectacularly. Approved
I've decided to refactor the old mouse position library and made this small snippet that concerns itself only with transforming from world to screen coordinates and back. Because, for purely async mouse screen positions, @moddiemads' system (which I'm sure he'll update any minute now) is superior, my system should be used in a context where either you need to know the screen positions of objects other than the mouse or the mouse positions need to be synced.
 
Level 11
Joined
May 8, 2009
Messages
278
The function works for every camera angle and rotation. The frame not following is probably because of how the mouse natives work; the mouse position only updates when you move the mouse cursor, not when the camera moves. The frame can also not move into the widescreen area.
With a fixed camera, fully zoomed in, these are the results I am getting in the test map:

middle of the screen OK

WC3ScrnShot_093024_220406_000.png

top right (not widescreen area) Invalid
WC3ScrnShot_093024_220401_000.png
bottom left (not widescreen area) Invalid

WC3ScrnShot_093024_220404_000.png

the margin of error increases the further I move from the center of the screen
 
Level 11
Joined
May 8, 2009
Messages
278
The Field of View is in fact different in Reforged than it is in Classic (77° vs. 70°). I tested it with the Reforged field of view and I get an error, but it's actually the opposite of the direction of your error, so I'm even more confused now.

View attachment 490547
That’s interesting and indeed very confusing, also is there a way to detect if the player is using SD or HD graphics?
 
The field of view changes for the Reforged camera as you zoom in and out. It is constant for the SD graphics camera. So, the HD camera zooms in, the SD camera moves the eye closer to the target. So I can set the field of view to different values and try to find the correct magic numbers and then derive the general solution for it.
 
Top