SRL Archive - Discussions and Debates

Need help explaining DDTM Weirdness


WT-Fakawi

2012-09-15 04:58:49

As you know, i have away for some time. but lately got some spare to kill. Been reading through a lot of the forums, started scripting, and most of the old scripts still work. So that is good!

But, in trying to make a proper DDTM around Draynor Centre, I came across a very weird coord situation with FindDtmRotated .
This has been there (for me at least) for some time. but now I took some time to properly investigate.

This is the situation: I made a DDTM from the Plant (which is a unique color combi on the MM). Mainpoint is centre of MM, and the four point represent the outer edges:




Procedure AssemblePlantDTM;                                                     
var
DTMSubPoints: array[0..3] of TDTMPointDef;
DTMMainPoint: TDTMPointDef;
TempTDTM: TDTM;

begin
Writeln('Assembling plant...');
DTMMainPoint.x:=MMCx;
DTMMainPoint.y:=MMCy;
DTMMainPoint.areasize:=1;
DTMMainPoint.areashape:=0;
DTMMainPoint.color:=16777215;
DTMMainPoint.tolerance:=255;

DTMSubPoints[0].x:=593;
DTMSubPoints[0].y:=109;
DTMSubPoints[0].areasize:=1;
DTMSubPoints[0].areashape:=0;
DTMSubPoints[0].color:=PlantColor;
DTMSubPoints[0].tolerance:=0;

DTMSubPoints[1].x:=593;
DTMSubPoints[1].y:=106;
DTMSubPoints[1].areasize:=1;
DTMSubPoints[1].areashape:=0;
DTMSubPoints[1].color:=PlantColor;
DTMSubPoints[1].tolerance:=0;

DTMSubPoints[2].x:=599;
DTMSubPoints[2].y:=104;
DTMSubPoints[2].areasize:=1;
DTMSubPoints[2].areashape:=0;
DTMSubPoints[2].color:=PlantColor;
DTMSubPoints[2].tolerance:=0;

DTMSubPoints[3].x:=600;
DTMSubPoints[3].y:=107;
DTMSubPoints[3].areasize:=1;
DTMSubPoints[3].areashape:=0;
DTMSubPoints[3].color:=PlantColor;
DTMSubPoints[3].tolerance:=0;

TempTDTM.MainPoint := DTMMainPoint;
TempTDTM.SubPoints := DTMSubPoints;
PlantDTM := AddDTM(TempTDTM);
Writeln('Assembling plant... Done.');
end;


The PlantColor coords make sense, the Distance to DDTM makes sense, only the values returned from FindDtmRotated are puzzling. The make only sense if you interprete them as up-side-down. Below is the readout:


PlantColor = (593, 100)
Dis2DDTM = 2
Pos2DDTM = (627, 83)

I have attached my testscript. Stand at Dranyor Centre and run it. Can anyone explain to me what I am doing wrong in finding the correct x and y readout for FindDtmRotated?

Thanks!

litoris

2012-09-15 06:27:11

The combination forms a rectangle, and it seems like the points are found in the reverse order. I think you could just use FindDTM instead of the rotated version.

P1ng

2012-09-15 07:23:37

I would assume that it is returning as if it was found upside down because you are searching for the DTM starting at a negative rotation (-6.0, 6.0). Perhaps if you changed this to (0, 12.0) this would search the same rotation area but it would begin at 0 and thus return the values you would expect.

WT-Fakawi

2012-09-15 07:49:05

From: P1ng
I would assume that it is returning as if it was found upside down because you are searching for the DTM starting at a negative rotation (-6.0, 6.0). Perhaps if you changed this to (0, 12.0) this would search the same rotation area but it would begin at 0 and thus return the values you would expect.


It used to be
  if FindDtmRotated(PlantDTM, x, y, MMX1, MMY1, MMX2, MMY2,
rs_GetCompassAngleRadians-pi/4, rs_GetCompassAngleRadians+pi/4, 0.05,
WhichAngle) then

which is fine because it searches the arc around. I changed it to approx. -2Pi to 2Pi to see if it made any difference. This is not the problem.

@litoris: It needs to be a DDTM, and I need it to search it rotated, otherwise it will never find it :) And as far as I know, there has never been an issue with order-of-points inside a DTM.

Brandon

2012-09-15 08:06:58

Just saw this. Are you sure the angles it takes are in degrees? It seems like radians to me :S

Maybe: -Pi/4, Pi/4, Pi/60 ??

EDIT: I see you're using radians already. Ughh have you tried adding a point for the tree stem? Also how come the colours have no tolerance? Also did you mean to put this: PlantColor:= GetMyColorTPA(3632461,20,50, MMx1, MMcy, MMcx, MMy2, 20)

that searches in a line. I saw that your script does that.

litoris

2012-09-15 08:33:09

From: Brandon
Just saw this. Are you sure the angles it takes are in degrees? It seems like radians to me :S

Maybe: -Pi/4, Pi/4, Pi/60 ??

EDIT: I see you're using radians already. Ughh have you tried adding a point for the tree stem? Also how come the colours have no tolerance? Also did you mean to put this: PlantColor:= GetMyColorTPA(3632461,20,50, MMx1, MMcy, MMcx, MMy2, 20)

that searches in a line. I saw that your script does that.

The points don't have any tolerance because their color is autocolored with the function in your post. Because we know their exact color though that, there's no need to give them any tolerance.

Kasi

2012-09-15 20:36:43

In assembleplantdtm, your main point has a tolerance of 255. this means its pretty much the same as every other color, now your plant dtm sub points are in a square shape right? this mean's the correct location can be found at 4 different spots, try it yourself. if you remove the tolerance of 255 on your mainpoint and put your character in the spot you took the ddtm at it would be exactly right. to fix this i would introduce another subpoint. which is static on the map such as the tree next to it or the water?

Nebula

2012-09-15 20:48:27

From: pur3b100d
In assembleplantdtm, your main point has a tolerance of 255. this means its pretty much the same as every other color, now your plant dtm sub points are in a square shape right? this mean's the correct location can be found at 4 different spots, try it yourself. if you remove the tolerance of 255 on your mainpoint and put your character in the spot you took the ddtm at it would be exactly right. to fix this i would introduce another subpoint. which is static on the map such as the tree next to it or the water?


This.

If for whatever reason your heart is set on using that bush, use FindDTMSRotated. Then use RotatePoints with -rs_GetCompassAngleRadians, and use the point thats x coordinate is greater than # and y coordinate that is less than #. If that makes sense. Hard to explain. Basically you'd find the 4 points, rotate them so that it's as if the compass angle is N, then choose the most northeast one.

WT-Fakawi

2012-09-16 02:33:18

Thing is: I have been using this specific technique for years; centrepoint wth any color (though not necesarry,it is always 16777215) and three to five known colors in the mm. Has always worked flawless.

But now, with this new 50 pixel offset thingie, none of my DTMS work anymore. Moreover, they behave as if they are found upsidedown.

pur3b100d: are you saying my DDTM is ill formatted? I'll set mainpoint to 16777215 and tol to 0.

Nebula: FindDDTMSRotated? Never heard of that one…and I didn't quite understand your post :)

litoris

2012-09-16 02:49:01

I don't think you understood my first post, I'm saying that it can be found upside down because the points form a rectangle(though I have no idea why that didn't happen before) and I think you would find it in its normal orientation if you didn't search for it rotated.

Kasi

2012-09-16 08:31:56

From: WT-Fakawi

pur3b100d: are you saying my DDTM is ill formatted? I'll set mainpoint to 16777215 and tol to 0.


Yes sort of, well it isnt ill-formatted but it could do with another point. ill make a sort of demo picture for you to explain it a bit better when i get out of bed -.-

Edit :

this is what i understand your dtm to look like.


now the main point. being above the character is a white color with a tolerance of 255. this means the main point can be found anywhere on the minimap if there were no subpoints. so for the example we will exclude the mainpoint.

firstly if you found the dtm with 0 rotation then it will be like so..


if the compass was say rotated 90Deg clockwise then it would have been found like…


so roughly with any rotation, your mainpoint - the one we excluded would be found anywhere on the following circle providing the subpoints meet up


this is why your dtm might have been found upside down. again to fix this i would apply compass rotation to when im making the points in realtime or add another point or 2. this way you can use finddtm like litoris said and you wouldnt have to rotate. ill show you an example from a script of mine.. look at DDTM1 and WalkPoint1 to test just place char infront of cwars bank.


program new;
{$DEFINE SMART}
{$I SRL/SRL.SIMBA}
{$IFDEF SMART}
{$I SRL/SRL/MISC/SMARTGRAPHICS.SIMBA}
{$ENDIF}

Const
Tol = 25;

Var
tempTB : TBox;
J : Integer;
WaterCol : Integer;

procedure SetAngleEx(Angle, Wai: Integer);
Var
K : Integer;
begin
if ((Angle = SRL_ANGLE_NONE) or (not LoggedIn)) then
Exit;
K := Angle;
if (Angle = 4) then
begin
if RBool then
begin
K := 0;
end else
K := 1;
end;
KeyDown((K * 2) + 38);
Sleep(Wai + RandomRange(-Wai / 2, Wai / 2));
KeyUp((K * 2) + 38);
end;

function FindWaterCol() : Integer;
begin
Result := AutoColorEx(srl_WaterColor).Color;
end;

function DDTM1: Integer;
var
PointDef : Array of TDTMPointDef;
TempTDTM : TDTM;
TPA : TPointArray;
I : Integer;
begin
MakeCompass('random'); // sets the compass to a random angle.
SetAngleEx(4, 600); // sets the high randomly
SetLength(TPA, 5);
TPA := [Point(666, 104), Point(615, 113), Point(661, 70), // tpa stuff for DDTM
Point(660, 48), Point(692, 104)];

SetLength(PointDef, Length(TPA));
for I := 0 to High(TPA) do
begin
TPA[I] := RotatePoint(TPA[I], -rs_GetCompassAngleRadians, MMCX, MMCY); // here we rotate the Point by the -compass angle
// by the minimap centre.
with PointDef[I] do
begin
x := TPA[I].x;
y := TPA[I].y;
AreaSize := 1;
AreaShape := 0; // add the point
Color := WaterCol;
Tolerance := Tol;
end;
end;
TempTDTM.MainPoint := PointDef[0];
SetLength(TempTDTM.SubPoints, Length(PointDef) - 1);
for I := 1 to High(PointDef) do
TempTDTM.SubPoints[I - 1] := PointDef[I];
Result := AddDTM(TempTDTM); // return the point.
end;

function WalkPoint1() : Boolean;
var
GTPA : TPointArray;
GT2DPA : T2DPointArray;
begin
WaterCol := FindWaterCol();
J := DDTM1;
if (FindDTMs(J, GTPA, MMX1, MMY1, MMX2, MMY2)) then // i dont have to apply rotation because when i created
begin // the dtm rotation was already added thus making it more
FreeDTM(J) // accurate
GT2DPA := SplitTPA(GTPA, 9); // all the rest is pretty self explained.
for J := 0 to High(GT2DPA) do
begin
tempTB := GetATPABounds([GT2DPA[J]]);
if (iAbs(tempTB.X1 - tempTB.X2) < 16) and (iAbs(tempTB.Y1 - tempTB.Y2) < 16) then
begin
SMART_DrawBox(tempTB);
SetLength(GTPA, 2);
GTPA[0] := RotatePoint(Point(15, -60), -rs_GetCompassAngleRadians, 0, 0); // offset stuff.
GaussBox(GTPA[1].x, GTPA[1].y, tempTB.X1, tempTB.Y1, tempTB.X2, tempTB.Y2);
GTPA[0] := Point(GTPA[1].x + GTPA[0].x, GTPA[1].y + GTPA[0].y);
if rs_OnMinimap(GTPA[0].x, GTPA[0].y) then
begin
Mouse(GTPA[0].x, GTPA[0].y, 2, 2, 1);
FFlag(0);
Result := True;
Exit;
end;
end;
end;
end;
FreeDTM(J);
end;


begin
SRL_SixHourFix := True;
Smart_FixSpeed := True;
SetupSRL;
WalkPoint1();
end.

Nebula

2012-09-16 10:47:43

Keep the mainpoint tolerance at 255, since the point in the market changes color depending on what's standing/not standing on it.


function FindDTMsRotatedSE(DTM: Integer; var Points: TPointArray; xs, ys, xe, ye: Integer; sAngle, eAngle, aStep: Extended; var aFound: T2DExtendedArray) : Boolean;
Same as FindDTMRotated, but returns every point that matches the DTM instead of just the first one found.

So you have a TPA of the possible points that are at the center of Draynor. You want to use the point that is most northeast when the compass is north. So use RotatePointsWrap on the points with the angle rotated being -rs_GetCompassAngleRadians. This will rotate all the points, making it as if the compass angle is north. Sort the TPA from Point(MMX2, MMY1). So now all ~4 of the points will be sorted from the upper-right corner of the minimap. You want the point that is most northeast, so use the first point in the array (BestPoint := PossiblePoints[0]). Rotate that point by rs_GetCompassAngleRadians so that it is back in its original position.