- Home /
Set GUI within 4 points - Matrix Rotation/Distortion
Hi, I have four corner gameobjects(top left(x1,y1), top right(x2,y1), bottom left(x1,y2), bottom right(x2,y2)). Now I would like to display the GUI within these 4 points. I already got the position and scale part, but i have really now idea how to start with the rotation/distortion part. Is that even possible? And how?
My code till now:
// Calc correct GUI Matrix within 4 points
public GameObject tl;
public GameObject tr;
public GameObject bl;
public GameObject br;
public Camera camera;
private Matrix4x4 CalcMatrix()
{
// Get ScreenPosition of the points
Vector3 tlsp = camera.WorldToScreenPoint(tl.transform.position);
tlsp.y = Screen.height - tlsp.y;
Vector3 brsp = camera.WorldToScreenPoint(br.transform.position);
brsp.y = Screen.height - brsp.y;
Vector3 trsp = camera.WorldToScreenPoint(tl.transform.position);
trsp.y = Screen.height - trsp.y;
Vector3 blsp = camera.WorldToScreenPoint(br.transform.position);
blsp.y = Screen.height - blsp.y;
// Calculate Values
Vector3 Pos = new Vector3(tlsp.x, tlsp.y, 1.0f);
Vector3 Scale = new Vector3(((brsp.x - tlsp.x) / Screen.width) * Screen.width / 800,
((brsp.y - tlsp.y) / Screen.height)*Screen.height/600,
1.0f);
return Matrix4x4.TRS(Pos, Quaternion.Euler(new Vector3(0, 0, 0)), Scale);
}
Comment