Apologies if I’m asking a very stupid question that’s handled by some other unit but…
I want to design a nice looking UI, a sort of HUD, for my project and as I’m using 3D anyway all UI components can start off as being planes (for flat buttons) or rectangular boxes (3d controls).
Here’s my basic plan, I want to create a Scene to hold the UI elements then use BeforeRender to position the scene so it remains fixed relative to the camera (and by association the viewport). I can then detect user interaction with the Key / Mouse / Touch events and respond accordingly.
Two simple questions and then one problem…
-
Where do I get the extent of the ViewPort from? e.g. running full screen on my laptop I want it to return at least something like 1920, 1080. I’ve looked but this simple detail’s answer eludes me.
-
Make my UI always be drawn? I guess this is like giving it a draw distance of zero. One concern here I have is rounding errors - they could potentially glitch a part of an observed scene in front of the UI.
And the problem…
I tried out using the following code to test…
procedure TForm1.CastleControlBase1BeforeRender(Sender: TObject);
var
ZPlane: Single;
Projection: TVector3;
begin
ZPlane := -1;
if Viewport.PositionToWorldPlane(Vector2(128, 72), True, Zplane, Projection) then
stateNotifications.Show( 'X : ' + FloatToStr(Projection.X) +
', Y : ' + FloatToStr(Projection.Y) + ', Z : ' + FloatToStr(Projection.Z))
else
stateNotifications.Show('Not possible');
end;
StateNotification is just a global TCastleNotifications so I can see what’s going on.
I sorta thought this would fail as it’s not taking the camera into account and it does indeed go wrong at certain rotations (I can see why now - everything’s world relative).
I’m obviously using the wrong function - this was just a quick first stab.
So I’m looking for something similar to PositionToWorldPlane that uses the Camera for the calculations.