Skip to content
This repository has been archived by the owner on Dec 24, 2020. It is now read-only.

Commit

Permalink
Use MainCamera if UICanvas uses CameraSpace without camera specified
Browse files Browse the repository at this point in the history
  • Loading branch information
mafiesto4 committed Mar 27, 2019
1 parent 6ade128 commit 6637769
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions FlaxEngine/API/Actors/UICanvas.cs
Original file line number Diff line number Diff line change
Expand Up @@ -270,23 +270,26 @@ public void GetWorldMatrix(out Matrix world)
// In 3D world
GetLocalToWorldMatrix(out world);
}
else if (_renderMode == CanvasRenderMode.CameraSpace && RenderCamera)
else if (_renderMode == CanvasRenderMode.CameraSpace)
{
Matrix tmp1, tmp2;

// Use default camera is not specified
var camera = RenderCamera ?? Camera.MainCamera;

// Adjust GUI size to the viewport size at the given distance form the camera
var viewport = RenderCamera.Viewport;
if (RenderCamera.UsePerspective)
var viewport = camera.Viewport;
if (camera.UsePerspective)
{
Matrix tmp3;
RenderCamera.GetMatrices(out tmp1, out tmp3, ref viewport);
camera.GetMatrices(out tmp1, out tmp3, ref viewport);
Matrix.Multiply(ref tmp1, ref tmp3, out tmp2);
var frustum = new BoundingFrustum(tmp2);
_guiRoot.Size = new Vector2(frustum.GetWidthAtDepth(Distance), frustum.GetHeightAtDepth(Distance));
}
else
{
_guiRoot.Size = viewport.Size * RenderCamera.OrthographicScale;
_guiRoot.Size = viewport.Size * camera.OrthographicScale;
}

// Center viewport (and flip)
Expand All @@ -295,8 +298,8 @@ public void GetWorldMatrix(out Matrix world)
Matrix.Multiply(ref world, ref tmp2, out tmp1);

// In front of the camera
var viewPos = RenderCamera.Position;
var viewRot = RenderCamera.Orientation;
var viewPos = camera.Position;
var viewRot = camera.Orientation;
var viewUp = Vector3.Up * viewRot;
var viewForward = Vector3.Forward * viewRot;
var pos = viewPos + viewForward * Distance;
Expand Down

0 comments on commit 6637769

Please sign in to comment.