@@ -368,6 +368,9 @@ WriteLn Map.Height();
368368```
369369*)
370370function TRSMap.Height(pt: TPoint = [0,0]; global: Boolean = True): Single;
371+ var
372+ neighbours: TPointArray;
373+ p: TPoint;
371374begin
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]];
390434end;
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();
624666end;
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
660669var
661670(*
0 commit comments