SRL Archive - SRL Archives

function findsrlcompassangle:integer;


masquerader

2006-10-03 18:42:17

so, i finally got around to figuring out why freddy's functions didnt work, and it turned out to be because i didnt have setupsrl; in there :duh:

i got that working and quick rewrote the compass function i had in the other topic

seeing as its half the size and a lot quicker now, i might add it to srl

would you use it, or does makecompass do it for you?

program New;
{.include srl/srl.scar}

function findsrlcompassangle:integer;
//returns degrees counter-clockwise compass is rotated
//by masquerader
var
tics:array[0..2] of tpoint;
skip:tboxarray;
x,y,i,j,found,south:integer;
begin
setarraylength(skip,1);
skip[0]:=cbox2(559,11,573, 28);

for i:=0 to 2 do
begin
if(findcolorskipboxarray(tics[i].x,tics[i].y,920735,547, 2,584, 39,skip))then
begin
found:=found+1;
j:=getarraylength(skip);
setarraylength(skip,j+1);
skip[j]:=cbox2(tics[i].x-4,tics[i].y-4,tics[i].x+4,tics[i].y+4);
end;
end;

if(found<>3)then
writeln('something went wrong, couldnt find the 3 compass tics');

if(distance(tics[0].x,tics[0].y,tics[1].x,tics[1].y)>22)then
south:=2
else
if(distance(tics[0].x,tics[0].y,tics[2].x,tics[2].y)>22)then
south:=1
else
south:=0;

x:=tics[south].x-566;
y:=tics[south].y-21;

result:=round(degrees(arctan2(y,x)))-90;

if(((x>0)and(y>0))or((x<0)and(y<0)))then
result:=result*-1;
if(((x>0)and(y<0))or((x<0)and(y>0)))then
result:=result-90;

result:=trunc(fixd(result));
end;

begin
setupsrl;
writeln(inttostr(findsrlcompassangle));
end.

WT-Fakawi

2006-10-03 18:58:50

Definately add it to SRL. Rename it to function Compass(degree:integer): boolean, no?

masquerader

2006-10-03 21:38:25

From: WT-Fakawi
Definately add it to SRL. Rename it to function Compass(degree:integer): boolean, no?

lol,i was trying to make it at least as long and ridiculus as

DetectRS2MinimapCompassAngle

but i guess that works too

i'll probably make it return -1 like the other one instead of being boolean

Wizzup?

2006-10-04 02:42:30

This would indeed be nice for a MakeCompassDegree function. :D

Sumilion

2006-10-04 09:30:43

From: Wizzup?
This would indeed be nice for a MakeCompassDegree function. :D


=O, you 'stole' my function name =P, i made a MakeCompassDegree from the old MakeCompass. I doubt it will work now ;), it's somewhere on srl :)

Wizzup?

2006-10-04 10:10:20

From: Sumilion
=O, you 'stole' my function name =P, i made a MakeCompassDegree from the old MakeCompass. I doubt it will work now ;), it's somewhere on srl :)


I know you made it.. thats why I brought it up.

Yakman

2006-10-04 10:40:11

very nice, i was trying to make something like this when the new compass came out, but it used DTMs, it didnt work of course :duh:

does anyone still have the old MakeCompass? with this you could just plug it in and it would work :D

EDIT: oh w8 it cant because this one returns degrees, not radians

Dark_Sniper

2006-10-11 20:38:57

From: Yakman
very nice, i was trying to make something like this when the new compass came out, but it used DTMs, it didnt work of course :duh:

does anyone still have the old MakeCompass? with this you could just plug it in and it would work :D

EDIT: oh w8 it cant because this one returns degrees, not radians


I made one with DTMs :\ and it works its also a lil dif then this.

procedure Northy;
var North, xx1, yy1 : Integer;
begin
North := DTMFromString('78DA6334636260E06500034608C5D0CCC5CDC' +
'00AE5FF07024613A01A365435869AB270356071901A6E026A2C80' +
'6A388950C38A5F0D00BD3907DD');
if ( not (FindDTM(North, xx1, yy1, 557, 2, 575, 16))) then
begin
repeat
SendArrowSilentWait(1, 100)
until(FindDTM(North, xx1, yy1, 557, 2, 575, 16))
end;
end;

procedure AngleCompass(Dir : Integer);
begin
Northy;
Dir:=Dir*100;
SendArrowSilentWait(1, Dir)
end;

begin
Northy;
AngleCompass(1)
end.

now how to use

anglecompass(dir) doesent use the N E S W it uses nums… so like 0 is the lowest(no rotation) and 37 is the highest(full rotation) and you can use it to get anywhere on the compass…

see the northy makes is perfect north everytime(tested like 100 times most ive seen it go around in circles is 3) see might be easier than degrees and radians for the newbies :p.

(and this northy uses a dtm :p)

masquerader

2006-10-11 21:36:38

haha, heres a version with 1337 debugging powers :f: :f:

{*******************************************************************************
function CompassRadians: Extended;
By: Masquerader
Description: returns radians clockwise compass is rotated
identical use to detectrs2minimapcompassangle
returns -1 if compass not found
*******************************************************************************}
function CompassRadians:extended;
var
tics:array[0..2] of tpoint;
skip:tboxarray;
x,y,i,j,found,south:integer;
debug:boolean;
debugcanvas:tcanvas;
w,h,client,clear:integer;
begin
debug:=true;
if(debug)then
begin
debugcanvas:=getdebugcanvas;
w:=583-550;
h:=37-4;
displaydebugimgwindow(3*w,3*h);
client:=bitmapfromstring(w,h,'');
copyclienttobitmap(client,550, 4,583, 37);
copycanvas(getbitmapcanvas(client),debugcanvas,0,0,w,h,0,0,3*w,3*h);
wait(2000);
clear:=bitmapfromstring(1,1,'');
fastdrawclear(clear,16777215);
end;

setarraylength(skip,1);
skip[0]:=cbox2(558,13,575, 27);

if(debug)then
begin
fastdrawsizetransparent(skip[0].x1-550,skip[0].y1-4,skip[0].x2-550,skip[0].y2-4,clear,client);
copycanvas(getbitmapcanvas(client),debugcanvas,0,0,w,h,0,0,3*w,3*h);
wait(2000);
end;


for i:=0 to 2 do
begin
if(findcolorskipboxarray(tics[i].x,tics[i].y,920735,547, 2,584, 39,skip))then
begin
found:=found+1;
j:=getarraylength(skip);
setarraylength(skip,j+1);
skip[j]:=cbox2(tics[i].x-4,tics[i].y-4,tics[i].x+4,tics[i].y+4);
if(debug)then
begin
fastdrawsizetransparent(skip[j].x1-550,skip[j].y1-4,skip[j].x2-550,skip[j].y2-4,clear,client);
copycanvas(getbitmapcanvas(client),debugcanvas,0,0,w,h,0,0,3*w,3*h);
wait(2000);
end;
end;
end;

freebitmap(client);
freebitmap(clear);

if(found<>3)then
begin
writeln('something went wrong, couldnt find the 3 compass tics')
result:=-1;
exit;
end;

if(distance(tics[0].x,tics[0].y,tics[1].x,tics[1].y)>22)then
south:=2
else
if(distance(tics[0].x,tics[0].y,tics[2].x,tics[2].y)>22)then
south:=1
else
south:=0;

x:=tics[south].x-566;
y:=tics[south].y-21;

result:=arctan2(y,x)

if(((x>0)and(y>0))or((x<0)and(y<0)))then
result:=result-pi/2;

if(((x>0)and(y<0))or((x<0)and(y>0)))then
result:=result*-1-pi;

result:=fixr(result);
end;

{*******************************************************************************
function Compass: Integer;
By: Masquerader
Description: returns degrees clockwise compass is rotated
returns -1 if compass not found
*******************************************************************************}
function compass:integer;
var
r:extended;
begin
r:=compassradians;
if(r<>-1)then
result:=round(degrees(r))
else
result:=-1;
end;

(im not gonna put the debug version in SRL :tongue:, but its cool to look at

Home

2006-10-12 06:54:12

Thanks! :) <3 :D:D