Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: Seroster on December 17, 2014, 01:08:20 PM

Title: Figuring out the size of an NGUI widget in a perspective view
Post by: Seroster on December 17, 2014, 01:08:20 PM
I know this is more of a 3D question, but if anyone has any ideas about this it would be awesome.

Here's the situation:
- I have an NGUI UITexture that I am positioning in 3D on a map to indicate a point of interest.  I'm doing this so it can be occluded, maintains its position when the map is rotated, etc.  (So, the UITexture is on a special layer which is seen by a camera which sees the 3D stuff, and the special layer, but not the rest of my UI)
- I've got a script to always orient this texture towards the camera (which works!)

However, I've been asked to make this texture keep its size on screen the same as if it was being shown by an orthographic 2D camera.
*pounds head on desk*

I'm not that much of a 3D guy.  I know I can use camera.WorldToScreenPoint() to figure out the location of a point in 3D, on the screen, so I can figure out where the centre of the texture is.  But I can't figure out the position of the corners without knowing the extent of the texture in 3D (which is not its pixel size) and that confuses the heck out of me.

What I need to do though, is either
- figure out the size of the texture on the screen currently, compare with the actual pixel size of the texture, and then calculate a scale to apply, OR
- figure out based on the vector from the camera to the texture, what the scale of the texture is at that distance.  I guess that might only be an approximation?

Any ideas?