Debian Codegraph @

src/transform/castletransform_miscellaneous_globals.inc

raw
1 {%MainUnit castletransform.pas}
2 {
3 Copyright 2017-2022 Michalis Kamburelis.
4
5 This file is part of "Castle Game Engine".
6
7 "Castle Game Engine" is free software; see the file COPYING.txt,
8 included in this distribution, for details about the copyright.
9
10 "Castle Game Engine" is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13
14 ----------------------------------------------------------------------------
15 }
16
17 {$ifdef read_interface}
18
19 type
20 TSceneManagerWorld = TCastleAbstractRootTransform deprecated 'use TCastleRootTransform';
21
22 procedure TransformMatricesMult(var Transform, InverseTransform: TMatrix4;
23 const Center: TVector3;
24 const Rotation: TVector4;
25 const Scale: TVector3;
26 const ScaleOrientation: TVector4;
27 const Translation: TVector3);
28 deprecated 'use TTransformation.Multiply';
29
30 const
31 rfOffScreen = rfRenderedTexture deprecated 'use rfRenderedTexture';
32
33 function StrToOrientationType(const S: String): TOrientationType;
34
35 var
36 InternalGizmoBoundingBox: Cardinal;
37
38 {$endif read_interface}
39
40 {$ifdef read_implementation}
41
42 { global routines ------------------------------------------------------------ }
43
44 { TransformMatricesMult ------------------------------------------------------ }
45
46 { Workaround FPC bug on Darwin for AArch64 (not on other platforms),
47 causes "Fatal: Internal error 2014121702".
48 Occurs with 3.0.4 and with 3.3.1 (r44333 from 2020/03/22). }
49 {$if defined(DARWIN) and defined(CPUAARCH64)}
50 {$define COMPILER_BUGGY_PARAMETERS}
51 {$endif}
52
53 procedure TransformMatricesMult(var Transform, InverseTransform: TMatrix4;
54 const Center: TVector3;
55 const Rotation: TVector4;
56 const Scale: TVector3;
57 const ScaleOrientation: TVector4;
58 const Translation: TVector3);
59
60 {$ifdef COMPILER_BUGGY_PARAMETERS}
61 type
62 TTransformData = record
63 Transform, InverseTransform: TMatrix4;
64 Center: TVector3;
65 Rotation: TVector4;
66 Scale: TVector3;
67 ScaleOrientation: TVector4;
68 Translation: TVector3;
69 end;
70
71 procedure MultiplyWorkaround(var T: TTransformation; const TransformData: TTransformData);
72 begin
73 T.Multiply(
74 TransformData.Center,
75 TransformData.Rotation,
76 TransformData.Scale,
77 TransformData.ScaleOrientation,
78 TransformData.Translation);
79 end;
80
81 var
82 TransformData: TTransformData;
83 {$endif COMPILER_BUGGY_PARAMETERS}
84
85 var
86 T: TTransformation;
87 begin
88 T.Transform := Transform;
89 T.InverseTransform := InverseTransform;
90 // T.Scale := 1; // doesn't matter
91 {$ifdef COMPILER_BUGGY_PARAMETERS}
92 TransformData.Center := Center;
93 TransformData.Rotation := Rotation;
94 TransformData.Scale := Scale;
95 TransformData.ScaleOrientation := ScaleOrientation;
96 TransformData.Translation := Translation;
97 MultiplyWorkaround(T, TransformData);
98 {$else}
99 T.Multiply(
100 Center,
101 Rotation,
102 Scale,
103 ScaleOrientation,
104 Translation);
105 {$endif}
106 Transform := T.Transform;
107 InverseTransform := T.InverseTransform;
108 end;
109
110 const
111 OrientationNames: array [TOrientationType] of String = (
112 'up:y,direction:-z',
113 'up:y,direction:z',
114 'up:z,direction:-y',
115 'up:z,direction:x'
116 );
117
118 function StrToOrientationType(const S: String): TOrientationType;
119 begin
120 if S = 'default' then
121 Exit(TCastleTransform.DefaultOrientation);
122 for Result := Low(TOrientationType) to High(TOrientationType) do
123 if OrientationNames[Result] = S then
124 Exit;
125 raise Exception.CreateFmt('Invalid orientation name "%s"', [S]);
126 end;
127
128 {$endif read_implementation}