5151Main record responsible for {ref}`MM2MS` projection.
5252*)
5353 TMM2MS = record
54- RSZoom: Single;
5554 Mode: ERSMode;
56- ScaleMin, ScaleMax: Single;
57- View, Projection, InvertedView, InvertedProjection: TMatrix4;
55+ RSZoom, Radians, ScaleMin, ScaleMax: Single;
56+ View, Projection, InvertedView, InvertedProjection,
57+ TransformMatrix, InvertedTransformMatrix: TMatrix4;
5858 Transformer: TVector3;
5959
6060 ViewEye, CustomEye, ViewTarget, ViewUp: TVector3;
@@ -181,39 +181,39 @@ begin
181181 Result := TMatrix4.RotationYawPitchRoll(rotation.Y, rotation.X, rotation.Z) * MATRIX_IDENTITY;
182182end;
183183
184- property TMM2MS.InvertedWorld(rotation: TVector3 ): TMatrix4;
184+ property TMM2MS.InvertedWorld(constref world: TMatrix4 ): TMatrix4;
185185var
186186 vector: TVector3;
187- matrix: TMatrix4;
188187begin
189- matrix := Self.World[rotation];
190- vector := [matrix.M41, matrix.M42, matrix.M43];
188+ vector := [world.M41, world.M42, world.M43];
191189
192190 // Transpose rotation into the result’s upper‐left
193- Result.M11 := matrix .M11;
194- Result.M12 := matrix .M21;
195- Result.M13 := matrix .M31;
191+ Result.M11 := world .M11;
192+ Result.M12 := world .M21;
193+ Result.M13 := world .M31;
196194 Result.M14 := 0.0;
197- Result.M21 := matrix .M12;
198- Result.M22 := matrix .M22;
199- Result.M23 := matrix .M32;
195+ Result.M21 := world .M12;
196+ Result.M22 := world .M22;
197+ Result.M23 := world .M32;
200198 Result.M24 := 0.0;
201- Result.M31 := matrix .M13;
202- Result.M32 := matrix .M23;
203- Result.M33 := matrix .M33;
199+ Result.M31 := world .M13;
200+ Result.M32 := world .M23;
201+ Result.M33 := world .M33;
204202 Result.M34 := 0.0;
205203
206204 // Compute inverse translation = -R^T * T
207- Result.M41 := -(matrix .M11*vector.X + matrix .M21*vector.Y + matrix .M31*vector.Z);
208- Result.M42 := -(matrix .M12*vector.X + matrix .M22*vector.Y + matrix .M32*vector.Z);
209- Result.M43 := -(matrix .M13*vector.X + matrix .M23*vector.Y + matrix .M33*vector.Z);
205+ Result.M41 := -(world .M11*vector.X + world .M21*vector.Y + world .M31*vector.Z);
206+ Result.M42 := -(world .M12*vector.X + world .M22*vector.Y + world .M32*vector.Z);
207+ Result.M43 := -(world .M13*vector.X + world .M23*vector.Y + world .M33*vector.Z);
210208
211209 // Bottom‐right stays 1
212210 Result.M44 := 1.0;
213211end;
214212
215- procedure TMM2MS.SetupProjection (mode: ERSMode);
213+ procedure TMM2MS.Setup (mode: ERSMode);
216214begin
215+ Self.RSZoom := -1;
216+ Self.Radians := -1;
217217 // fixed client width & height
218218 if Self.ProjectionWidth = 0 then Self.ProjectionWidth := 765;
219219 if Self.ProjectionHeight = 0 then Self.ProjectionHeight := 503;
@@ -261,25 +261,38 @@ begin
261261end;
262262
263263
264- procedure TMM2MS.UpdateZoom (zoom: Integer);
264+ procedure TMM2MS.Update (zoom: Integer; rads: Single );
265265var
266266 scale: Double;
267+ world: TMatrix4;
267268begin
268- if (Self.RSZoom = ZOOM2RSZOOM[zoom]) and (RSClient.Mode = Self.mode) then
269- Exit;
270-
271- Self.RSZoom := ZOOM2RSZOOM[zoom] ;
269+ if (Self.RSZoom <> ZOOM2RSZOOM[zoom]) or (RSClient.Mode <> Self.mode) then
270+ begin
271+ Self.RSZoom := ZOOM2RSZOOM[zoom];
272+ scale := Self.ScaleMin + Self. RSZoom * (Self.ScaleMax - Self.ScaleMin) ;
272273
273- scale := Self.ScaleMin + Self.RSZoom * (Self.ScaleMax - Self.ScaleMin);
274+ Self.Transformer.X := 513 * scale;
275+ Self.Transformer.Y := 335 * scale;
276+ Self.Transformer.Z := MainScreen.Center.Y + (Self.RSZoom * 24);
277+ Self.UpdateViewMatrix(RSClient.Mode, zoom);
278+ end;
274279
275- Self.Transformer.X := 513 * scale;
276- Self.Transformer.Y := 335 * scale;
277- Self.Transformer.Z := MainScreen.Center.Y + (Self.RSZoom * 24);
278- Self.UpdateViewMatrix(RSClient.Mode, zoom);
280+ if (Self.Radians <> rads) or (RSClient.Mode <> Self.mode) then
281+ begin
282+ Self.Radians := rads;
283+ world := Self.World[[0,0,TAU-rads]];
284+ Self.TransformMatrix := world * Self.View * Self.Projection;
285+ Self.InvertedTransformMatrix := Self.InvertedProjection * Self.InvertedView * Self.InvertedWorld[world];
286+ end;
279287end;
280288
289+ function TMM2MS.MinimapOffset(constref coordinate: TVector3): TVector3;
290+ begin
291+ with Minimap.Center do
292+ Result := [coordinate.X - X, Y - coordinate.Y, coordinate.Z];
293+ end;
281294
282- function TMM2MS.Transform(coord: TVector3; matrix: TMatrix4): TVector3;
295+ function TMM2MS.Transform(constref coord: TVector3; constref matrix: TMatrix4): TVector3;
283296begin
284297 with coord.Transform(matrix) do
285298 begin
@@ -288,7 +301,30 @@ begin
288301 end;
289302end;
290303
291- function TMM2MS.InvertedTransform(coord: TVector3; matrix: TMatrix4): TVector3;
304+ function TMM2MS.Run(constref coords: TVector3Array): TVector2Array;
305+ var
306+ i: Integer;
307+ begin
308+ for i := 0 to High(coords) do
309+ Result += Self.Transform(Self.MinimapOffset(coords[i]), Self.TransformMatrix).ToVec2();
310+ end;
311+
312+ function TMM2MS.Run(constref coords: TVector3Array): TPointArray; overload;
313+ var
314+ i: Integer;
315+ begin
316+ for i := 0 to High(coords) do
317+ Result += Self.Transform(Self.MinimapOffset(coords[i]), Self.TransformMatrix).ToPoint();
318+ end;
319+
320+
321+ function TMM2MS.ReverseMinimapOffset(constref coordinate: TVector3): TVector2;
322+ begin
323+ with Minimap.Center do
324+ Result := [Round(coordinate.X) + X, Y - Round(coordinate.Y)];
325+ end;
326+
327+ function TMM2MS.ReverseTransform(constref coord: TVector3; matrix: TMatrix4): TVector3;
292328var
293329 ndcX, ndcY, scale, yOff: Double;
294330 nearNDC, farNDC, worldNear, worldFar: TVector3;
@@ -312,26 +348,25 @@ begin
312348 Result.Z := 0.0;
313349end;
314350
315-
316- function TMM2MS.Run(coords: TVector3Array; rotation: TVector3): TVector2Array;
351+ function TMM2MS.ReverseRun(constref coords: TVector3Array): TVector2Array;
317352var
318353 i: Integer;
319- transformMatrix: TMatrix4;
320354begin
321- transformMatrix := Self.World[rotation] * Self.View * Self.Projection;
322-
323355 for i := 0 to High(coords) do
324- Result += Self.Transform( coords[i], transformMatrix).ToVec2( );
356+ Result += Self.ReverseMinimapOffset(Self.ReverseTransform( coords[i], Self.InvertedTransformMatrix) );
325357end;
326358
327- function TMM2MS.InvertRun( coords: TVector3Array; rotation: TVector3 ): TVector2Array ;
359+ function TMM2MS.ReverseRun(constref coords: TVector3Array): TPointArray; overload ;
328360var
329361 i: Integer;
330- transformMatrix: TMatrix4;
331362begin
332- transformMatrix := Self.InvertedProjection * Self.InvertedView * Self.InvertedWorld[rotation];
333-
334363 for i := 0 to High(coords) do
335- Result += Self.InvertedTransform( coords[i], transformMatrix).ToVec2 ();
364+ Result += Self.ReverseMinimapOffset(Self.ReverseTransform( coords[i], Self.InvertedTransformMatrix)).ToPoint ();
336365end;
337366
367+ var
368+ (*
369+ ## MM2MS variable
370+ Global {ref}`TMM2MS` variable.
371+ *)
372+ MM2MS: TMM2MS;
0 commit comments