Skip to content

Commit 10730ef

Browse files
committed
fix: read notes
- TRSCamera and TMM2MS now have their own variables as RSCamera and MM2MS - TProjection defaults to use RSCamera now, for certain tasks where MM2MS just does better, MM2MS is used (normalization, reverse runs - MM2MS now caches it's math for the current compass angle
1 parent dc40db4 commit 10730ef

File tree

4 files changed

+122
-153
lines changed

4 files changed

+122
-153
lines changed

osrs/interfaces/setup.simba

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,9 @@ begin
7979
if RSClient.Mode = ERSMode.UNKNOWN then
8080
RSClient.Mode := ERSMode.FIXED;
8181

82-
Projection.MM2MSProjector.SetupProjection(RSClient.Mode);
82+
MM2MS.Setup(RSClient.Mode);
8383
if Options.ZoomLevel > -1 then
84-
Projection.MM2MSProjector.UpdateZoom(Options.ZoomLevel);
84+
MM2MS.Update(Options.ZoomLevel, Minimap.CompassRadians);
8585
SetupInterfaces();
8686
end;
8787
{$H+}
@@ -165,7 +165,6 @@ begin
165165
SetLength(Minimap.Orbs, Ord(High(ERSMinimapOrb))+1);
166166

167167
Options.Setup();
168-
Projection.MM2MSProjector.RSZoom := -1;
169168
RSMouseZoom.ZoomLevel := -1;
170169
RSMouseZoom.Enabled := True;
171170
WorldSwitcher.Setup();

osrs/projection/camera.simba

Lines changed: 23 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,20 @@ type
1010
Record responsible of handling projection, similar to {ref}`MM2MS`.
1111
*)
1212
TRSCamera = record
13-
X, Y, Z, Pitch, Yaw, Scale, MinScale, MaxScale, ZOffset: Integer;
13+
X, Y, Z, Pitch, Yaw, Scale, MinScale, MaxScale,
14+
ZOffset, MinZ, MaxZ, ReverseZ: Integer;
1415
Player, Center, Camera, Offset, ViewportOffset, Origin: TPoint;
1516
Sines, Cosines: array [0..2047] of Int32;
1617
ZoomScale, Radians: Single;
18+
Bounds: TBox;
1719
const MIN_PITCH: Integer = 128;
1820
const MAX_PITCH: Integer = 383;
1921
end;
2022

2123
procedure TRSCamera.Setup();
2224
var
2325
i: Integer;
24-
percent: Double;
26+
percent: Single;
2527
begin
2628
Self.ZoomScale := -1;
2729
Self.Radians := -1;
@@ -50,6 +52,8 @@ begin
5052
Self.Offset := [4,4];
5153
Self.MinScale := 181;
5254
Self.MaxScale := 1448;
55+
Self.MaxZ := 1851;
56+
Self.MinZ := 1782;
5357
end;
5458
ERSMode.RESIZABLE..ERSMode.MODERN_WIDE:
5559
begin
@@ -60,6 +64,8 @@ begin
6064
percent := (MainScreen.Bounds.Height - 503) / (1061-503);
6165
Self.MinScale := 272+Round((574-272) * percent);
6266
Self.MaxScale := 2180+Round((4599-2180) * percent);
67+
Self.MaxZ := 2289;
68+
Self.MinZ := 2219;
6369
end;
6470
end;
6571

@@ -82,6 +88,7 @@ begin
8288
Self.Z := Self.ZOffset + Round(1237 * (Self.MAX_PITCH - Self.Pitch) / (Self.MAX_PITCH - Self.MIN_PITCH) - (zoom/100) * 75);
8389
Self.ZoomScale := ZOOM2RSZOOM[zoom];
8490
Self.Scale := Round(Self.MinScale + Self.ZoomScale * (Self.MaxScale-Self.MinScale));
91+
Self.ReverseZ := Round(Self.MinZ + Self.ZoomScale * (Self.MaxZ-Self.MinZ));
8592
end;
8693

8794
if Self.Radians <> rads then
@@ -91,6 +98,12 @@ begin
9198
Self.Camera.Y := Round(Self.Center.Y + Sin(rads) * (Self.X - Self.Center.X) + Cos(rads) * (Self.Y - Self.Center.Y));
9299
Self.Origin.X := Self.Camera.X - Self.Player.X;
93100
Self.Origin.Y := Self.Camera.Y - Self.Player.Y;
101+
102+
Self.Bounds.X1 := ((-5120 + Self.Origin.X) div 128 * 4) + Minimap.Center.X;
103+
Self.Bounds.Y1 := ((-5120 + Self.Origin.Y) div 128 * 4) + Minimap.Center.Y;
104+
Self.Bounds.X2 := ((18432 + Self.Origin.X) div 128 * 4) + Minimap.Center.X;
105+
Self.Bounds.Y2 := ((18432 + Self.Origin.Y) div 128 * 4) + Minimap.Center.Y;
106+
94107
Self.Radians := rads;
95108
end;
96109
end;
@@ -99,14 +112,14 @@ end;
99112
function TRSCamera.MinimapOffset(constref coordinate: TVector3): TVector3;
100113
begin
101114
Result.X := (coordinate.X-Minimap.Center.X)/4*128 - Self.Origin.X;
102-
Result.Y := (coordinate.Y-Minimap.Center.Y)/4*128 - Self.Origin.Y;
115+
Result.Y := -(coordinate.Y-Minimap.Center.Y)/4*128 - Self.Origin.Y;
103116
Result.Z := -coordinate.Z/4*128 - Self.Z;
104117
end;
105118

106119
function TRSCamera.Transform(constref coordinate: TVector3): TVector2;
107120
var
108121
x1, y1, y2, z1, x, y, z: Int32;
109-
scale: Double;
122+
scale: Single;
110123
begin
111124
x := Round(coordinate.X);
112125
y := Round(coordinate.Y);
@@ -115,7 +128,7 @@ begin
115128
y1 := Sar(y * Self.Cosines[Self.Yaw] - x * Self.Sines[Self.Yaw], 16);
116129
z1 := Sar(y1 * Self.Cosines[Self.Pitch] + z * Self.Sines[Self.Pitch], 16);
117130

118-
//if z1 < 50 then Exit;
131+
WriteLn z1;
119132
if z1 = 0 then z1 := 1;
120133

121134
x1 := Sar(x * Self.Cosines[Self.Yaw] + y * Self.Sines[Self.Yaw], 16);
@@ -147,52 +160,9 @@ begin
147160
Result := Self.Run([coordinate]).First;
148161
end;
149162

150-
151-
//MS2MM not working
152-
function TRSCamera.ReverseMinimapOffset(constref transformed: TVector3): TVector3;
153-
begin
154-
Result.X := (transformed.X + Self.Origin.X)*4/128 + Minimap.Center.X;
155-
Result.Y := (transformed.Y + Self.Origin.Y)*4/128 + Minimap.Center.Y;
156-
Result.Z := -(transformed.Z + Self.Z)*4/128;
157-
end;
158-
159-
function TRSCamera.ReverseTransform(constref screen: TVector3): TVector3;
160163
var
161-
x1, y1, y2, z1, x, y, z: Double;
162-
begin
163-
z1 := screen.Z;
164-
165-
x1 := (screen.X - Self.ViewportOffset.X) * z1 / Self.Scale;
166-
y2 := (screen.Y - Self.ViewportOffset.Y) * z1 / Self.Scale;
167-
168-
y1 := (z1 * Self.Cosines[Self.Pitch] - y2 * Self.Sines[Self.Pitch]) / 65536;
169-
z := (z1 * Self.Sines[Self.Pitch] + y2 * Self.Cosines[Self.Pitch]) / 65536;
170-
171-
x := (x1 * Self.Cosines[Self.Yaw] - y1 * Self.Sines[Self.Yaw]) / 65536;
172-
y := (x1 * Self.Sines[Self.Yaw] + y1 * Self.Cosines[Self.Yaw]) / 65536;
173-
174-
Result.X := x;
175-
Result.Y := y;
176-
Result.Z := z;
177-
end;
178-
179-
function TRSCamera.ReverseRunEx(coordinates: TVector3Array): TVector2Array;
180-
var
181-
i: Integer;
182-
begin
183-
for i := 0 to High(coordinates) do
184-
Result += Self.ReverseMinimapOffset(Self.ReverseTransform(coordinates[i])).ToVec2();
185-
end;
186-
187-
function TRSCamera.ReverseRun(coordinates: TVector3Array): TPointArray;
188-
var
189-
i: Integer;
190-
begin
191-
for i := 0 to High(coordinates) do
192-
Result += Self.ReverseMinimapOffset(Self.ReverseTransform(coordinates[i])).ToPoint();
193-
end;
194-
195-
function TRSCamera.ReverseRun(coordinate: TVector3): TPoint; overload;
196-
begin
197-
Result := Self.ReverseRun([coordinate]).First;
198-
end;
164+
(*
165+
## RSCamera variable
166+
Global {ref}`TRSCamera` variable.
167+
*)
168+
RSCamera: TRSCamera;

osrs/projection/mm2ms.simba

Lines changed: 78 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,10 @@ type
5151
Main 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;
182182
end;
183183

184-
property TMM2MS.InvertedWorld(rotation: TVector3): TMatrix4;
184+
property TMM2MS.InvertedWorld(constref world: TMatrix4): TMatrix4;
185185
var
186186
vector: TVector3;
187-
matrix: TMatrix4;
188187
begin
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;
213211
end;
214212

215-
procedure TMM2MS.SetupProjection(mode: ERSMode);
213+
procedure TMM2MS.Setup(mode: ERSMode);
216214
begin
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
261261
end;
262262

263263

264-
procedure TMM2MS.UpdateZoom(zoom: Integer);
264+
procedure TMM2MS.Update(zoom: Integer; rads: Single);
265265
var
266266
scale: Double;
267+
world: TMatrix4;
267268
begin
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;
279287
end;
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;
283296
begin
284297
with coord.Transform(matrix) do
285298
begin
@@ -288,7 +301,30 @@ begin
288301
end;
289302
end;
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;
292328
var
293329
ndcX, ndcY, scale, yOff: Double;
294330
nearNDC, farNDC, worldNear, worldFar: TVector3;
@@ -312,26 +348,25 @@ begin
312348
Result.Z := 0.0;
313349
end;
314350

315-
316-
function TMM2MS.Run(coords: TVector3Array; rotation: TVector3): TVector2Array;
351+
function TMM2MS.ReverseRun(constref coords: TVector3Array): TVector2Array;
317352
var
318353
i: Integer;
319-
transformMatrix: TMatrix4;
320354
begin
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));
325357
end;
326358

327-
function TMM2MS.InvertRun(coords: TVector3Array; rotation: TVector3): TVector2Array;
359+
function TMM2MS.ReverseRun(constref coords: TVector3Array): TPointArray; overload;
328360
var
329361
i: Integer;
330-
transformMatrix: TMatrix4;
331362
begin
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();
336365
end;
337366

367+
var
368+
(*
369+
## MM2MS variable
370+
Global {ref}`TMM2MS` variable.
371+
*)
372+
MM2MS: TMM2MS;

0 commit comments

Comments
 (0)