Skip to content

Commit e675d60

Browse files
committed
feat: more fixes to rscamera
- now caches zoom and compass
1 parent 9ce43dd commit e675d60

File tree

2 files changed

+32
-22
lines changed

2 files changed

+32
-22
lines changed

osrs/projection/camera.simba

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ Record responsible of handling projection, similar to {ref}`MM2MS`.
1313
X, Y, Z, Pitch, Yaw, Scale, MinScale, MaxScale, ZOffset: Integer;
1414
Player, Center, Camera, Offset, ViewportOffset, Origin: TPoint;
1515
Sines, Cosines: array [0..2047] of Int32;
16+
ZoomScale, Radians: Single;
1617
const MIN_PITCH: Integer = 128;
1718
const MAX_PITCH: Integer = 383;
1819
end;
@@ -22,6 +23,9 @@ var
2223
i: Integer;
2324
percent: Double;
2425
begin
26+
Self.ZoomScale := -1;
27+
Self.Radians := -1;
28+
2529
Self.Pitch := 383;
2630

2731
for i := 0 to 2047 do
@@ -71,19 +75,27 @@ begin
7175
Self.Y := Self.Player.Y - 674 - Round(235 * (Self.MAX_PITCH - value) / (Self.MAX_PITCH - Self.MIN_PITCH));
7276
end;
7377

74-
procedure TRSCamera.Update(zoom: Integer; rads: Double);
78+
procedure TRSCamera.Update(zoom: Integer; rads: Single);
7579
begin
76-
Self.Z := Self.ZOffset + Round(1237 * (Self.MAX_PITCH - Self.Pitch) / (Self.MAX_PITCH - Self.MIN_PITCH) - (zoom/100) * 75);
77-
Self.Yaw := Trunc((rads / TAU) * 2047);
78-
Self.Scale := Round(Self.MinScale + ZOOM2RSZOOM[zoom] * (Self.MaxScale-Self.MinScale));
79-
80-
Self.Camera.X := Round(Self.Center.X + Cos(rads) * (Self.X - Self.Center.X) - Sin(rads) * (Self.Y - Self.Center.Y));
81-
Self.Camera.Y := Round(Self.Center.Y + Sin(rads) * (Self.X - Self.Center.X) + Cos(rads) * (Self.Y - Self.Center.Y));
82-
Self.Origin.X := Self.Camera.X - Self.Player.X;
83-
Self.Origin.Y := Self.Camera.Y - Self.Player.Y;
84-
end;
80+
if Self.ZoomScale <> ZOOM2RSZOOM[zoom] then
81+
begin
82+
Self.Z := Self.ZOffset + Round(1237 * (Self.MAX_PITCH - Self.Pitch) / (Self.MAX_PITCH - Self.MIN_PITCH) - (zoom/100) * 75);
83+
Self.ZoomScale := ZOOM2RSZOOM[zoom];
84+
Self.Scale := Round(Self.MinScale + Self.ZoomScale * (Self.MaxScale-Self.MinScale));
85+
end;
8586

87+
if Self.Radians <> rads then
88+
begin
89+
Self.Yaw := Trunc((rads / TAU) * 2047);
90+
Self.Camera.X := Round(Self.Center.X + Cos(rads) * (Self.X - Self.Center.X) - Sin(rads) * (Self.Y - Self.Center.Y));
91+
Self.Camera.Y := Round(Self.Center.Y + Sin(rads) * (Self.X - Self.Center.X) + Cos(rads) * (Self.Y - Self.Center.Y));
92+
Self.Origin.X := Self.Camera.X - Self.Player.X;
93+
Self.Origin.Y := Self.Camera.Y - Self.Player.Y;
94+
Self.Radians := rads;
95+
end;
96+
end;
8697

98+
//MM2MS
8799
function TRSCamera.MinimapOffset(constref coordinate: TVector3): TVector3;
88100
begin
89101
Result.X := (coordinate.X-Minimap.Center.X)/4*128 - Self.Origin.X;
@@ -103,8 +115,8 @@ begin
103115
y1 := Sar(y * Self.Cosines[Self.Yaw] - x * Self.Sines[Self.Yaw], 16);
104116
z1 := Sar(y1 * Self.Cosines[Self.Pitch] + z * Self.Sines[Self.Pitch], 16);
105117

106-
if z1 < 50 then
107-
Exit;
118+
//if z1 < 50 then Exit;
119+
if z1 = 0 then z1 := 1;
108120

109121
x1 := Sar(x * Self.Cosines[Self.Yaw] + y * Self.Sines[Self.Yaw], 16);
110122
y2 := Sar(z * Self.Cosines[Self.Pitch] - y1 * Self.Sines[Self.Pitch], 16);
@@ -136,6 +148,7 @@ begin
136148
end;
137149

138150

151+
//MS2MM not working
139152
function TRSCamera.ReverseMinimapOffset(constref transformed: TVector3): TVector3;
140153
begin
141154
Result.X := (transformed.X + Self.Origin.X)*4/128 + Minimap.Center.X;

osrs/projection/projection.simba

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ end.
6161
{$INCLUDE_ONCE WaspLib/osrs.simba}
6262

6363
type
64-
EProjector = enum(MM2MS, CAMERA);
64+
EProjector = enum(CAMERA, MM2MS);
6565
(*
6666
## TProjection
6767
Main record responsible for projection.
@@ -121,7 +121,7 @@ begin
121121
end;
122122
end;
123123

124-
function TProjection.InvertedRun(arr: TVector3Array): TPointArray;
124+
function TProjection.ReverseRun(arr: TVector3Array): TPointArray;
125125
var
126126
v: TVector2;
127127
begin
@@ -252,12 +252,8 @@ var
252252
v1, v2: TVector2;
253253
arr: TPointArray;
254254
begin
255-
size.X := 2 * size.X;
256-
size.Y := 2 * size.Y;
257-
258-
vector.X += offset.X;
259-
vector.Y += offset.Y;
260-
vector.Z += offset.Z;
255+
size.X := 2 * size.X; size.Y := 2 * size.Y;
256+
vector.X += offset.X; vector.Y += offset.Y; vector.Z += offset.Z;
261257

262258
with Self.NormalizeEx([vector.X, vector.Y], radians) do
263259
begin
@@ -352,7 +348,7 @@ This is not an exact reversion of what `MM2MS` does but it's very accurate.
352348
*)
353349
function TRSMainScreen.Point2MM(pt: TPoint; height: Single): TPoint;
354350
begin
355-
Result := Projection.InvertedRun([[pt.X, pt.Y, height]])[0];
351+
Result := Projection.ReverseRun([[pt.X, pt.Y, height]])[0];
356352
end;
357353

358354

@@ -387,7 +383,7 @@ begin
387383
if Projection.ZoomQuads[Options.GetZoomLevel(True)] <> Default(TQuad) then
388384
Exit(Projection.ZoomQuads[Options.ZoomLevel]);
389385

390-
tpa := Projection.InvertedRun([
386+
tpa := Projection.ReverseRun([
391387
MainScreen.TopLeft.ToVec3(),
392388
MainScreen.TopRight.ToVec3(),
393389
MainScreen.BottomRight.ToVec3(),
@@ -699,6 +695,7 @@ begin
699695
for pt.X := Self.Center.X - 120 to Self.Center.X + 120 with 4 do
700696
for pt.Y := Self.Center.Y - 120 to Self.Center.Y + 120 with 4 do
701697
begin
698+
//if not Self.PointOnZoomQuad(pt) then Continue;
702699
vector := pt.ToVec3().Rotate(radians, Self.Center);
703700
quad := Self.Vector2MSQuad(vector, radians, [1,1]);
704701
tpa += quad.Corners.Connect();

0 commit comments

Comments
 (0)