Skip to content

Commit ee0fdfb

Browse files
committed
new height calc
tweaks to height calculations
1 parent d01336b commit ee0fdfb

File tree

4 files changed

+73
-69
lines changed

4 files changed

+73
-69
lines changed

osrs/position/map/map.simba

Lines changed: 55 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,9 @@ WriteLn Map.Height();
368368
```
369369
*)
370370
function TRSMap.Height(pt: TPoint = [0,0]; global: Boolean = True): Single;
371+
var
372+
neighbours: TPointArray;
373+
p: TPoint;
371374
begin
372375
if Self.DisableHeightmap or not Assigned(Self.Loader.Heightmap) then
373376
Exit(0.0);
@@ -382,11 +385,52 @@ begin
382385
if global then
383386
pt := Self.Loader.GetLocal(Self.RegionIndex, pt);
384387

385-
Result := RSTranslator.Color2Height(Self.Loader.Heightmap.Pixel[pt.X,pt.Y]) +
386-
RSTranslator.Color2Height(Self.Loader.Heightmap.Pixel[pt.X,pt.Y + 1]) +
387-
RSTranslator.Color2Height(Self.Loader.Heightmap.Pixel[pt.X + 1,pt.Y]) +
388-
RSTranslator.Color2Height(Self.Loader.Heightmap.Pixel[pt.X + 1,pt.Y + 1]);
389-
Result := Result/4;
388+
neighbours := [
389+
pt, pt.Offset(-1,-1), pt.Offset(1,-1), pt.Offset(-1,1), pt.Offset(1,1)
390+
];
391+
392+
for p in neighbours do
393+
begin
394+
if Self.Loader.Heightmap.InImage(p.X, p.Y) then
395+
Result += RSTranslator.Color2Height(Self.Loader.Heightmap.Pixel[p.X,p.Y])
396+
else if Self.Loader.Heightmap.InImage(pt.X, pt.Y) then
397+
Result += RSTranslator.Color2Height(Self.Loader.Heightmap.Pixel[pt.X,pt.Y]);
398+
end;
399+
400+
Result := Result/Length(neighbours);
401+
end;
402+
403+
404+
function TRSMap.GetQuad(me, pt: TPoint; angle: Single = $FFFF): TQuad;
405+
var
406+
vector: TVector2;
407+
corners: TVector3Array;
408+
h: Single;
409+
currLoc: TPoint;
410+
arr: TPointArray;
411+
begin
412+
if angle = $FFFF then angle := Minimap.CompassRadians;
413+
vector := Self.Walker.Point2MMVec(me, pt, angle);
414+
pt := vector.ToPoint();
415+
416+
if not Minimap.PointOnZoomQuad(pt) then Exit;
417+
418+
vector := Minimap.NormalizeEx(vector, angle);
419+
me := Self.Loader.GetLocal(me);
420+
421+
h := Self.Height(me, False);
422+
423+
currLoc := me + vector.ToPoint() - Minimap.Center;
424+
425+
corners := [
426+
[vector.X-2, vector.Y-2, Self.Height(currLoc + [-1,-1], False) - h],
427+
[vector.X+2, vector.Y-2, Self.Height(currLoc + [1,-1], False) - h],
428+
[vector.X+2, vector.Y+2, Self.Height(currLoc + [1,1], False) - h],
429+
[vector.X-2, vector.Y+2, Self.Height(currLoc + [-1,1], False) - h]
430+
];
431+
432+
arr := Projection.Run(corners, angle);
433+
Result := [arr[0], arr[1], arr[2], arr[3]];
390434
end;
391435

392436

@@ -541,13 +585,11 @@ begin
541585
angle := Minimap.CompassRadians;
542586

543587
img.DrawColor := $00FF00;
544-
img.DrawAlpha := $77;
588+
img.DrawAlpha := $FF;
545589

546590
Self.Position();
547591
loc := Self.Cache.LocalPosition;
548-
h := Self.Height(loc - [1,3], False) + Self.Height(loc + [3,-3], False) +
549-
Self.Height(loc + [3,1], False) + Self.Height(loc - [1,1], False);
550-
h := h/4;
592+
h := RSTranslator.Color2Height(Self.Loader.Heightmap.Pixel[loc.X,loc.Y]);
551593

552594
for x := Minimap.Center.X - 120 to Minimap.Center.X + 120 with 4 do
553595
for y := Minimap.Center.Y - 120 to Minimap.Center.Y + 120 with 4 do
@@ -566,10 +608,10 @@ begin
566608
currLoc := loc + Point(x,y) - Minimap.Center;
567609

568610
corners := [
569-
[vector.X-2, vector.Y-2, Self.Height(currLoc - [1,3], False) - h],
570-
[vector.X+2, vector.Y-2, Self.Height(currLoc + [3,-3], False) - h],
571-
[vector.X+2, vector.Y+2, Self.Height(currLoc + [3,1], False) - h],
572-
[vector.X-2, vector.Y+2, Self.Height(currLoc - [1,1], False) - h]
611+
[vector.X-2, vector.Y-2, Self.Height(currLoc + [-1,-1], False) - h],
612+
[vector.X+2, vector.Y-2, Self.Height(currLoc + [1,-1], False) - h],
613+
[vector.X+2, vector.Y+2, Self.Height(currLoc + [1,1], False) - h],
614+
[vector.X-2, vector.Y+2, Self.Height(currLoc + [-1,1], False) - h]
573615
];
574616

575617
arr := Projection.Run(corners, angle);
@@ -623,39 +665,6 @@ begin
623665
img.Show();
624666
end;
625667

626-
function TRSMap.GetQuad(me, pt: TPoint; angle: Single = $FFFF): TQuad;
627-
var
628-
vector: TVector2;
629-
corners: TVector3Array;
630-
h: Single;
631-
currLoc: TPoint;
632-
arr: TPointArray;
633-
begin
634-
if angle = $FFFF then angle := Minimap.CompassRadians;
635-
vector := Self.Walker.Point2MMVec(me, pt, angle);
636-
pt := vector.ToPoint();
637-
638-
if not Minimap.PointOnZoomQuad(pt) then Exit;
639-
640-
vector := Minimap.NormalizeEx(vector, angle);
641-
me := Self.Loader.GetLocal(me);
642-
643-
h := Self.Height(me - [1,3], False) + Self.Height(me + [3,-3], False) +
644-
Self.Height(me + [3,1], False) + Self.Height(me - [1,1], False);
645-
h := h/4;
646-
647-
currLoc := me + vector.ToPoint() - Minimap.Center;
648-
649-
corners := [
650-
[vector.X-2, vector.Y-2, Self.Height(currLoc - [1,3], False) - h],
651-
[vector.X+2, vector.Y-2, Self.Height(currLoc + [3,-3], False) - h],
652-
[vector.X+2, vector.Y+2, Self.Height(currLoc + [3,1], False) - h],
653-
[vector.X-2, vector.Y+2, Self.Height(currLoc - [1,1], False) - h]
654-
];
655-
656-
arr := Projection.Run(corners, angle);
657-
Result := [arr[0], arr[1], arr[2], arr[3]];
658-
end;
659668

660669
var
661670
(*

osrs/position/map/objects.simba

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -276,9 +276,7 @@ begin
276276
coordinates := [];
277277
meLocal := Self.Walker^.GetLocal(me);
278278

279-
h := Self.Walker^.Height(meLocal - [1,3], False) + Self.Walker^.Height(meLocal + [3,-3], False) +
280-
Self.Walker^.Height(meLocal + [3,1], False) + Self.Walker^.Height(meLocal - [1,1], False);
281-
h := h/4;
279+
h := Self.Walker^.Height(meLocal, False);
282280

283281
for i := 0 to High(Self.Coordinates) do
284282
begin

osrs/walker.simba

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -212,20 +212,18 @@ begin
212212
vector := vector.Rotate(-radians, Minimap.Center.ToVec2());
213213
me := Self.GetLocal(me);
214214

215-
h := Self.Height(me - [1,3], False) + Self.Height(me + [3,-3], False) +
216-
Self.Height(me + [3,1], False) + Self.Height(me - [1,1], False);
217-
h := h/4;
215+
h := Self.Height(me, False);
218216

219217
currLoc := me + vector.ToPoint() - Minimap.Center;
220218

221219
size.X := size.X*2;
222220
size.Y := size.Y*2;
223221

224222
corners := [
225-
[vector.X-size.X, vector.Y-size.Y, Self.Height(currLoc - [1,3], False) - h],
226-
[vector.X+size.X, vector.Y-size.Y, Self.Height(currLoc + [3,-3], False) - h],
227-
[vector.X+size.X, vector.Y+size.Y, Self.Height(currLoc + [3,1], False) - h],
228-
[vector.X-size.X, vector.Y+size.Y, Self.Height(currLoc - [1,1], False) - h]
223+
[vector.X-size.X, vector.Y-size.Y, Self.Height(currLoc + [-1,-1], False) - h],
224+
[vector.X+size.X, vector.Y-size.Y, Self.Height(currLoc + [1,-1], False) - h],
225+
[vector.X+size.X, vector.Y+size.Y, Self.Height(currLoc + [1,1], False) - h],
226+
[vector.X-size.X, vector.Y+size.Y, Self.Height(currLoc + [-1,1], False) - h]
229227
];
230228

231229
arr := Projection.Run(corners, radians);
@@ -247,24 +245,23 @@ begin
247245
vector := vector.Rotate(-radians, Minimap.Center.ToVec2());
248246
me := Self.GetLocal(me);
249247

250-
h := Self.Height(me - [1,3], False) + Self.Height(me + [3,-3], False) +
251-
Self.Height(me + [3,1], False) + Self.Height(me - [1,1], False);
252-
h := h/4;
248+
h := Self.Height(me, False);
253249

254250
currLoc := me + vector.ToPoint() - Minimap.Center;
255251

256252
size.X := size.X*2;
257253
size.Y := size.Y*2;
258254

259255
corners := [
260-
[vector.X-size.X, vector.Y-size.Y, Self.Height(currLoc - [1,3], False) - h],
261-
[vector.X+size.X, vector.Y-size.Y, Self.Height(currLoc + [3,-3], False) - h],
262-
[vector.X+size.X, vector.Y+size.Y, Self.Height(currLoc + [3,1], False) - h],
263-
[vector.X-size.X, vector.Y+size.Y, Self.Height(currLoc - [1,1], False) - h],
264-
[vector.X-size.X, vector.Y-size.Y, Self.Height(currLoc - [1,3], False) - h+size.Z],
265-
[vector.X+size.X, vector.Y-size.Y, Self.Height(currLoc + [3,-3], False) - h+size.Z],
266-
[vector.X+size.X, vector.Y+size.Y, Self.Height(currLoc + [3,1], False) - h+size.Z],
267-
[vector.X-size.X, vector.Y+size.Y, Self.Height(currLoc - [1,1], False) - h+size.Z]
256+
[vector.X-size.X, vector.Y-size.Y, Self.Height(currLoc + [-1,-1], False) - h],
257+
[vector.X+size.X, vector.Y-size.Y, Self.Height(currLoc + [1,-1], False) - h],
258+
[vector.X+size.X, vector.Y+size.Y, Self.Height(currLoc + [1,1], False) - h],
259+
[vector.X-size.X, vector.Y+size.Y, Self.Height(currLoc + [-1,1], False) - h],
260+
261+
[vector.X-size.X, vector.Y-size.Y, Self.Height(currLoc + [-1,-1], False) - h + size.Z],
262+
[vector.X+size.X, vector.Y-size.Y, Self.Height(currLoc + [1,-1], False) - h + size.Z],
263+
[vector.X+size.X, vector.Y+size.Y, Self.Height(currLoc + [1,1], False) - h + size.Z],
264+
[vector.X-size.X, vector.Y+size.Y, Self.Height(currLoc + [-1,1], False) - h + size.Z]
268265
];
269266

270267
arr := Projection.Run(corners, radians);

utils/math/rstranslator.simba

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,14 +129,14 @@ function TRSTranslator.Height2Color(height: Single): Integer;
129129
const
130130
H_VALUE := Self.MaxHeight / $FFFFFF;
131131
begin
132-
Result := Round((height / H_VALUE) * 29.14);
132+
Result := Round((height / H_VALUE) / 4 * 128);
133133
end;
134134

135135
function TRSTranslator.Color2Height(color: Integer): Single;
136136
const
137137
H_VALUE := Self.MaxHeight / $FFFFFF;
138138
begin
139-
Result := color * H_VALUE / 29.14;
139+
Result := color * H_VALUE * 4 / 128;
140140
end;
141141

142142

0 commit comments

Comments
 (0)