Skip to content

Instantly share code, notes, and snippets.

@an01f01
Last active January 25, 2024 15:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save an01f01/c5beda63e17ae86589719863812f90e9 to your computer and use it in GitHub Desktop.
Save an01f01/c5beda63e17ae86589719863812f90e9 to your computer and use it in GitHub Desktop.
{ Obtains device scaling }
function GetScreenScale: Single;
var
ScreenService: IFMXScreenService;
begin
Result := 1;
if TPlatformServices.Current.SupportsPlatformService (IFMXScreenService, IInterface(ScreenService)) then
begin
Result := ScreenService.GetScreenScale;
end;
end;
{ Calculates position and applys screen scaling of devices if necessary }
function CalculateScreenPosition(Context: TContext3D; Point: TPoint3D; Scale: TPoint3D; Rotation: TPoint3D; Translation: TPoint3D; ApplyScreenScale: Boolean = False): TPoint3D;
var
Tmpsp: TPoint3D;
begin
Tmpsp := TPoint3D.Zero;
Tmpsp := Point;
Tmpsp := Tmpsp * TMatrix3D.CreateScaling(Scale);
Tmpsp := Tmpsp * TMatrix3D.CreateRotationX(DegToRad(Rotation.X));
Tmpsp := Tmpsp * TMatrix3D.CreateRotationY(DegToRad(Rotation.Y));
Tmpsp := Tmpsp * TMatrix3D.CreateRotationZ(DegToRad(Rotation.Z));
Tmpsp := Tmpsp * TMatrix3D.CreateTranslation(Translation);
Tmpsp := Context.WorldToScreen(TProjection.Camera,Tmpsp);
if ApplyScreenScale then begin
Tmpsp := Tmpsp / GetScreenScale;
end;
Result := Tmpsp;
end;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment