Last active
January 25, 2024 15:37
-
-
Save an01f01/c5beda63e17ae86589719863812f90e9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ 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