Log in

View Full Version : Dtm location finding



boffysworld
01-13-2012, 06:22 PM
Really new to this so please bare with my lack of knowledge.
I have Dtm array of locations and im trying to find which is closest when i first login.
By checking each point , seeing which it finds and storing distance of those in an array.
Then sorting list closest first.
And im having no luck.


Procedure Find_player;
var
place,f:Integer;
Dist:TIntegerarray;
begin
SetDTM;
SetLength(Dist,High(Q));
For f:=0 to High(Q) do
If FindDTMRotated(Q[f], x, y, MMX1, MMY1, MMX2, MMY2, -Pi/4, Pi/4, Pi/60, aFound) then
begin
place:= Distance(x, y, MMCX, MMCY);
Dist[f]:=Place;
WriteLn(IntToStr(Dist[f])+(' location ')+InttoStr(f));
end;
FrDTM;
Quicksort(Dist);
WriteLn(IntToStr(Dist[0])+('You are at location ')+InttoStr(f));
End;

Brandon
01-13-2012, 06:40 PM
Why not make a TPA of the values? instead of an array of distances..


Procedure Find_player;
var
F: Integer;
Dist, Q: TIntegerarray;
aFound: T2DExtendedArray;
TPA, TTPA: TpointArray;
begin
//SetDTM;
SetLength(Dist,High(Q));
For F:=0 to High(Q) do
If FindDTMsRotatedAlternating(Q[F], TPA, MMX1, MMY1, MMX2, MMY2, -Pi/4, Pi/4, Pi/60, aFound) then
begin
Dist[F]:= Distance(TPA[F].X, TPA[F].Y, MMCX, MMCY);
WriteLn(IntToStr(Dist[F])+(' location ')+InttoStr(F));

TTPA:= TPA;
SortTPAFrom(TTPA, Point(MMCX, MMCY));
WriteLn(IntToStr(Dist[0])+('You are at location ')+InttoStr(F));
Count:= Count + 1;
end;
//FrDTM;
End;

boffysworld
01-13-2012, 06:54 PM
Nice one.. u make it seem so easy.
I have alot to learn.

boffysworld
01-13-2012, 09:07 PM
Not sure if this is the best way , but less code and returns the correct variable each time.
Is this the correct way to write it?



Procedure Find_player(var e:Integer);
var
place,f,d:Integer;
begin
d :=75; // Max distance from center point
For f:=0 to High(Q) do
If FindDTMRotated(Q[f], x, y, MMX1, MMY1, MMX2, MMY2, -Pi/4, Pi/4, Pi/60, aFound) then
begin
place:= Distance(x, y, MMCX, MMCY);
WriteLn(IntToStr(place)+(' pixels away ,location ')+InttoStr(f));
If (place< d) Then
Begin
d:=place;
e:=f;
end;
end;
WriteLn(' You are at location ')+InttoStr(e));