Hi folks,
I’d like to say that while this is my first post, the forums have been an invaluable resource for a project I’ve been working on for the past few months. Many great answers to difficult questions; thank you all.
I’ve come across a problem that I can’t solve on my own - at the risk of rehashing the GUI.Matrix questions…
I’ve developed a gui system, made to scale to resolution using
GUI.matrix = Matrix4x4.TRS (Vector3(0, 0, 0), Quaternion.identity, Vector3 (Screen.height / VertRes, Screen.height / VertRes, 1));
Where VertRes is 1024 (based on 1280x1024).
For the mapping system, i am using an overhead secondary camera, who’s viewport is manually adjusted for the change in GUI so that it continues to fit in the “frame” provided for it.
radRect.x = radarPanel.panelRect.x * Screen.height/VertRes;
radRect.y = radarPanel.panelRect.y * Screen.height/VertRes;
radRect.width = radarPanel.panelRect.width * Screen.height/VertRes;
radRect.height = radarPanel.panelRect.height * Screen.height/VertRes;
radarCam.pixelRect = radRect;
radarCam.pixelRect.y = Screen.height - radRect.y - radRect.height;
This allows it to follow properly with changing resolution.
To make this mapping system act as a radar, I’ve used a WorldToViewportPoint call on the objects I need “blips” for.
var blipPos = radarCam.WorldToViewportPoint(obj.transform.position);
Then adjust for the actual width of the viewport to make the positions follow correctly
blipPos.x = blipPos.x * radRect.width ;
blipPos.y = (r.height) - (blipPos.y * radRect.height);
So, the problem is that the “blips” being drawn over the viewport are slightly skewed - When the object is near the left side of the viewport, the blips are drawn to the left of the object - when on the right, the blips are drawn to the right - same for top and bottom. The object directly in the middle of the viewport has its blip centered correctly.
So, the question is why the WorldToViewportPoint call isn’t aligning textures correctly.
I’ve tried changing the cameras projection matrix and aspect, though this didn’t cause a change. Ive changed the camera to orthographic, this still provided the same problem.
This problem does not seem to occur when the screen is at its full size (1280x1024), so I believe it to be an issue with the GUI.Matrix call. Can anyone confirm this?
On the same note, is there any way to get the runtime modified Rect values after they’ve been changed by the GUI.Matrix function?
Thanks for any help on this! I promise I’ll have at least one awesome chunk of code to give back soon!