This library contains a function that will project any UI point down onto the world. It requires knowing the player's camera target, distance, yaw, pitch, roll, fov and their resolution. Additionally it assumes the terrain is flat. Arbitrary terrain could be done with tracelines.
It's original purpose as a mouse tracker has been made obsolete but one person has requested it. The inverse function, mapping world to UI coordinates has more uses and I'll see if I can get that up soon [EDIT: Done].
Notes
Added World to UI Projection. See picture below
Added an intialization function that must be run every time camera position or orientation changes
The example map uses the mouse coordinates to pick the UI point to project onto the world to place the baneling under the cursor. It is not using the Mouse World Pos. Also the baneling's position is updated regardless if the mouse is moved, so moving the camera with arrow keys will also move the baneling to the correct position. Camera orientation can be altered with holding right click, distance with W/S, field of view with Q/E, height offset with mouse side buttons and roll with A/D.
After placing the unit, a dialog is moved to the location of the baneling. This function is not using the MouseUI X/Y but the World -> UI projection from the calculated position of the unit. The same is done for a tank unit on the map.
Great work. The code looks pretty clean, too. I don't think that further optimization is needed (I don't know if Galaxy has some sort of auto-optimization, but I guess not), because it is already nearly as fast as using "Mouse World Pos". Maybe it can be changed, so that the cos() and sin() values are only recomputed, when the angle of the camera axis actually changes, otherwise there are only few multiplications to save.
Projecting world to UI coordinates sounds more interesting indeed. I played with the thought of using this once for an UI that pops up "on top" of a unit, but that idea had some disadvantages. I would be interesting what people would come up with.
Out of interest, if you already have the Mouse World Coordinate (from mouse tracking), what is the minimum code required to project this world coordinate to the UI?
I have a dummy unit moving with the mouse, but can't think of a simple way to translate that to the UI.
Out of interest, if you already have the Mouse World Coordinate (from mouse tracking), what is the minimum code required to project this world coordinate to the UI?
I have a dummy unit moving with the mouse, but can't think of a simple way to translate that to the UI.
The mouse already does this; you can get both it's world and UI coordinates. I only use the baneling example to show how accurate the functions are. This library is useful if you don't/can't use the mouse for that purpose.
For instance, in the example map I have an arrow that points at the siege tank no matter where it is. Since I'm not following the siege tank with the mouse, there is no easy way to know it's position on the screen and that's where the library comes in.
Additionally you can know where the mouse is pointing on the world even if you don't move it, such as if the camera moves but the mouse doesn't.
You'd want to use this library any time you want UI elements that interact with elements in the world, such as by having custom unit bars or have a command card appear on top of a unit.
The mouse already does this; you can get both it's world and UI coordinates
Really? Can you suggest how to get the mouse UI coordinates when I am using a mouse move event? I must be missing something, I couldn't find anything built in for this.
All I want to do is move a dialogue around attached to the mouse cursor while the mouse move event is active,
Really? Can you suggest how to get the mouse UI coordinates when I am using a mouse move event? I must be missing something, I couldn't find anything built in for this.
All I want to do is move a dialogue around attached to the mouse cursor while the mouse move event is active,
Here is how you get the UI coordinates from the mouse moved event. To move the dialog to the exact cursor's position, you need to know the player's resolution. Simply using the Mouse UI coordinates will not work because dialogs are scaled down in-game depending on the player's resolution and aspect ratio.
Thanks, the world coords being in real and the UI being int was why I couldn't find it.
Anyhow it's too laggy online so I'm going to do something else. There just doesn't seem to be a non-laggy way to have something following the mouse cursor online.
Battle.net has an inherent lag to it, you can't do anything about it. When you move the mouse or camera, there is going to be a delay before the values in the triggers update.
What optimizing the library does is allow you run many more projections before a noticeable slow down (that's not due to battle.net lag) is apparent.
This library contains a function that will project any UI point down onto the world. It requires knowing the player's camera target, distance, yaw, pitch, roll, fov and their resolution. Additionally it assumes the terrain is flat. Arbitrary terrain could be done with tracelines.
It's original purpose as a mouse tracker has been made obsolete but one person has requested it. The inverse function, mapping world to UI coordinates has more uses and I'll see if I can get that up soon [EDIT: Done].
Notes
Library
http://static.sc2mapster.com/content/files/505/331/Screen_To_World_Projection.SC2Lib
Example Map
http://static.sc2mapster.com/content/files/505/332/UI_Screen_To_World_Projection.SC2Map
The example map uses the mouse coordinates to pick the UI point to project onto the world to place the baneling under the cursor. It is not using the Mouse World Pos. Also the baneling's position is updated regardless if the mouse is moved, so moving the camera with arrow keys will also move the baneling to the correct position. Camera orientation can be altered with holding right click, distance with W/S, field of view with Q/E, height offset with mouse side buttons and roll with A/D.
After placing the unit, a dialog is moved to the location of the baneling. This function is not using the MouseUI X/Y but the World -> UI projection from the calculated position of the unit. The same is done for a tank unit on the map.
Great work. The code looks pretty clean, too. I don't think that further optimization is needed (I don't know if Galaxy has some sort of auto-optimization, but I guess not), because it is already nearly as fast as using "Mouse World Pos". Maybe it can be changed, so that the cos() and sin() values are only recomputed, when the angle of the camera axis actually changes, otherwise there are only few multiplications to save.
Projecting world to UI coordinates sounds more interesting indeed. I played with the thought of using this once for an UI that pops up "on top" of a unit, but that idea had some disadvantages. I would be interesting what people would come up with.
Updated the library. Now has World to UI Projection. This works on any terrain (with a few restrictions).
Out of interest, if you already have the Mouse World Coordinate (from mouse tracking), what is the minimum code required to project this world coordinate to the UI?
I have a dummy unit moving with the mouse, but can't think of a simple way to translate that to the UI.
Why not use the UI coordinates of the mouse directly (those are integers)?
The mouse already does this; you can get both it's world and UI coordinates. I only use the baneling example to show how accurate the functions are. This library is useful if you don't/can't use the mouse for that purpose.
For instance, in the example map I have an arrow that points at the siege tank no matter where it is. Since I'm not following the siege tank with the mouse, there is no easy way to know it's position on the screen and that's where the library comes in.
Additionally you can know where the mouse is pointing on the world even if you don't move it, such as if the camera moves but the mouse doesn't.
You'd want to use this library any time you want UI elements that interact with elements in the world, such as by having custom unit bars or have a command card appear on top of a unit.
Really? Can you suggest how to get the mouse UI coordinates when I am using a mouse move event? I must be missing something, I couldn't find anything built in for this.
All I want to do is move a dialogue around attached to the mouse cursor while the mouse move event is active,
@SexLethal: Go
Really cool library SexLethal, great job. This has a lot of potential.
Here is how you get the UI coordinates from the mouse moved event. To move the dialog to the exact cursor's position, you need to know the player's resolution. Simply using the Mouse UI coordinates will not work because dialogs are scaled down in-game depending on the player's resolution and aspect ratio.
Thanks, the world coords being in real and the UI being int was why I couldn't find it.
Anyhow it's too laggy online so I'm going to do something else. There just doesn't seem to be a non-laggy way to have something following the mouse cursor online.
Updated Library, should run much faster now.
Does it make a difference online though? I tried it online and it had the same lagginess that using the mousemove event did ;(
@KratsAU: Go
Battle.net has an inherent lag to it, you can't do anything about it. When you move the mouse or camera, there is going to be a delay before the values in the triggers update.
What optimizing the library does is allow you run many more projections before a noticeable slow down (that's not due to battle.net lag) is apparent.
No worries thanks, I thought as much just wanted to make sure incase I was doing something wrong :).
If they eventually give us the ability to initiate targetted abilities from triggers it will solve most of my problems.