SRL Archive - Jr. Member General Help and Discussion

Camera movement (help!)


Torol

2015-01-15 05:43:14

I'm writing a woodcutter script, and I'm looking for a way to turn my camera towards the closest tree (as a failsafe). I can detect the tree with DTMs on the minimap, but after that I'm stuck. How could I move the camera? If you could link a script which uses a similar option that would be great too.
Thanks,
Torol

riwu

2015-01-15 06:07:13

You can move compass with TRSMinimap.setAngle()
if the tree has an icon on the minimap, you can determine the exact angle with simple trigonometry (compare position of minimap centre to the icon)

The Mayor

2015-01-15 06:09:53

@cosmasjdz;

Torol

2015-01-15 10:06:10

From: riwu
You can move compass with TRSMinimap.setAngle()
if the tree has an icon on the minimap, you can determine the exact angle with simple trigonometry (compare position of minimap centre to the icon)


It's easier to say than to do :D Could you help me? I still need a variable, but I don't know how to get it.


minimap.findDTMs(MapleDTM, TPA);
t := minimap.getCenterPoint;

ATPA := TPA.toATPA(8, 8);
ATPA.sortFromMidPoint(minimap.getCenterPoint);
p := middleTPA(ATPA[0]);

dist := distance(t.x, t.y, p.x, p.y);

riwu

2015-01-15 10:13:20

(x1, y1) == coordinate of tree
(x2, y2) == coordinate of minimap centre
to get the angle delta, u just need 2 of the lengths (u can find all 3)

p.s. i have a major in arts, hence the awesome drawing ^^

EDIT: width&height calculations are wrong..see #9

Torol

2015-01-15 10:18:45

Opps you are right. Sorry :D I didn't realize I can calculate the lengths from the coordinates

riwu

2015-01-15 10:22:35

From trigonometry:
tan(angle) = Opposite / Adjacent
so
angle:= ArcTan((x1-x2)/(y1-y2))

Turpinator

2015-01-15 10:24:33

From: riwu
(x1, y1) == coordinate of tree
(x2, y2) == coordinate of minimap centre
to get the angle delta, u just need 2 of the lengths (u can find all 3)

p.s. i have a major in arts, hence the awesome drawing ^^


Your Xs make me cringe.

riwu

2015-01-15 10:32:18

From: Turpinator
Your Xs make me cringe.

I was taught to write x (when used in algebra) as )(, is that not the standard practice?

also @OP u have to determine which quadrant the tree is at to manipulate the angle to one that u can pass to TRSMinimap.setAngle().
There are quite a few ways to do this, one simple way i can think of now is: if x1>x2 it's at right side; if y1>y2, it's at bottom.

Also just realize i got the subtractions all wrong in the drawing lol
height should be y2-y1, width x1-x2

Turpinator

2015-01-15 10:44:09

From: riwu
I was taught to write x (when used in algebra) as )(, is that not the standard practice?

also @OP u have to determine which quadrant the tree is at to manipulate the angle to one that u can pass to TRSMinimap.setAngle().
There are quite a few ways to do this, one simple way i can think of now is: if x1>x2 it's at right side; if y1>y2, it's at bottom.

Also just realize i got the subtractions all wrong in the drawing lol
height should be y2-y1, width x1-x2


I guess they teach you to do it fancily not to confuse it with the x as a multiplication symbol. buut… later on people get lazy and start using dots to avoid any confusion between a multiplication x and the variable x.

Annyway. rather than playing around with x1>x2 and y1>y2 to get the quadrant, just use atan2(y,x) as it will return angles between -180 and 180 deg (which can easily be fed to minimpap.setAngle() [once you add 90 to it, because 0 degrees is at north, right?])

riwu

2015-01-15 10:51:02

From: Turpinator
I guess they teach you to do it fancily not to confuse it with the x as a multiplication symbol. buut… later on people get lazy and start using dots (?) to avoid any confusion between a multiplication x and the variable x.

Annyway. rather than playing around with x1>x2 and y1>y2 to get the quadrant, just use atan2(y,x) as it will return angles between -180 and 180 deg (which can easily be fed to minimpap.setAngle() [once you add 90 to it, because 0 degrees is at north, right?])

Ahh indeed that's more direct. Haven't been practicing trigonometry for a long time…

cosmasjdz

2015-01-15 11:57:20

From: Torol
I'm writing a woodcutter script, and I'm looking for a way to turn my camera towards the closest tree (as a failsafe). I can detect the tree with DTMs on the minimap, but after that I'm stuck. How could I move the camera? If you could link a script which uses a similar option that would be great too.
Thanks,
Torol


This is my function mayor mentioned of. It targets closest yellow dot. You need to change colors thats it.

It turn mainscreen to the certain angle of the screen. For example nusitaiko(45); would turn screen to the closest yellow dot on the minimap to be at 45 degrees in my mainscreen. I usually use 45,135 angles because in those angles in the corners you see more further than in the 90 degree for example.


function nusitaiko(kampas: integer):boolean;
var
x, y,i : integer;
TPA: TPointArray;
ATPA: T2DPointArray;
t: tpoint;
k,m: extended;
xv,yv,ml: integer;
begin
result:=false;
findColorsSpiralTolerance(x, y, TPA, 518375, minimap.getbounds(), 12, colorSetting(2,0.23, 0.74));
if length(TPA) < 1 then exit;
ATPA := TPA.toATPA(2, 2);
if length(ATPA)< 1 then exit;
ATPA.sortFromMidPoint(minimap.getCenterPoint());
ml:=kampas;
t:=minimap.getCenterPoint();
SortTPAFrom(TPA, t); // i sort dots from closest
xv:=tpa[0].x-t.x;// anfd use closest one parameters to count angles
yv:=t.y-tpa[0].y;
k:=degrees(ArcTan2(yv,xv)); // counts dot angle on the minimap
m:=(minimap.getangledegrees()); // gets minimap angle
minimap.setangle(trunc(k+m-90+ml)); // this line sets closest found dot to be on the certain angle of mainscreen using both angles
writeln('Succesfully rotated');
result:=true;
end;


EDIT: Dang same name wrong second function. But yeah you can even after setting screen to closest point that dot from minimap to mainscreen also and blindly grab tree or try to grab. Would be good antiban like feature. For example my dragon script at the moment in combination with Nusitaiko() uses these functions to minimize search areas so grabs faster moving dragons.

Torol

2015-01-15 13:02:13

From: cosmasjdz
This is my function mayor mentioned of. It targets closest yellow dot. You need to change colors thats it.


I already made it, but thank you very much! :)
Here is mine, and as I tested, it works pretty well:

procedure rotateCam();
var
angle : Integer;
p, t : TPoint;
TPA : TPointArray;
ATPA : T2DPointArray;
begin
writeDebug('Rotating camera.');
minimap.findDTMs(MapleDTM, TPA);
t := minimap.getCenterPoint;

ATPA := TPA.toATPA(7, 7);
ATPA.sortFromMidPoint(t);
p := middleTPA(ATPA[0]);

angle := (round(t.getAngleTo(p))) - round(minimap.getAngleDegrees());

minimap.setAngle(-angle);
end;

It needs a failsafe if it can't find the DTMs tho… but feel free to use it.

Torol

2015-01-15 14:10:07

I have an other question about camera movement. Are there any way to just partially change the vertical position? Like the setZoom()? Because with setAngle() I can only set it high or down, but I would need an inbetween position.

Turpinator

2015-01-15 14:18:34

From: Torol
I have an other question about camera movement. Are there any way to just partially change the vertical position? Like the setZoom()? Because with setAngle() I can only set it high or down, but I would need an inbetween position.

keyDown(38);  // up arrow
wait(some time);
keyUp(38); //up arrow
Down arrow is 40 i believe.

Torol

2015-01-15 15:34:36

Thanks, @Turpinator, one more question: are there any way to get the current camera status of how much we are zoomed in, or vertically where is our camera?

Turpinator

2015-01-15 16:47:45

From: Torol
Thanks, @Turpinator, one more question: are there any way to get the current camera status of how much we are zoomed in, or vertically where is our camera?


Nope, and nope.
(at least not with color)
The zoom… might be able to be gotten with GLX, but probably not.
The pitch though… you can get it with GLX, though GLX currently is not compatible with the existing SRL-6 include and requires a different version of the OGL plugin used with SMART (and is OGL only).

Obscurity

2015-01-15 20:57:06

Use OGL, .closestTo(), obsMakeCompassDeg(), and obsMiniMapMiddle(). ;).

masterBB

2015-01-16 02:51:34

From: riwu
(x1, y1) == coordinate of tree
(x2, y2) == coordinate of minimap centre
to get the angle delta, u just need 2 of the lengths (u can find all 3)

p.s. i have a major in arts, hence the awesome drawing ^^

EDIT: width&height calculations are wrong..see #9


You should always use arctan2: ArcTan2(y,x : extended)


riwu

2015-01-16 03:14:28

From: Obscurity
Use OGL, .closestTo(), obsMakeCompassDeg(), and obsMiniMapMiddle(). ;).

Do u know a way to get extent of camera zoom? (Or just find out if it's at min zoom)
From: masterBB
You should always use arctan2: ArcTan2(y,x : extended)


Yes indeed. I wasn't aware of the existence of this convenient function since it don't exist in scientific calculators :d

Obscurity

2015-01-16 12:18:05

If you could, would you please post that on my OGL thread? It's the only thread I check regularly (am at work now, so will need the reminder). :-P. I'm sure there's a way, and if not I'll write one because I'd like to have that option as well. You

Torol

2015-01-16 16:17:57

From: Obscurity
Use OGL, .closestTo(), obsMakeCompassDeg(), and obsMiniMapMiddle(). ;).


Those are your functions right? I will check them out.

From: Obscurity
If you could, would you please post that on my OGL thread? It's the only thread I check regularly (am at work now, so will need the reminder). :-P. I'm sure there's a way, and if not I'll write one because I'd like to have that option as well. You


That would be great!

Obscurity

2015-01-16 17:08:03

Yes. They can be found in my obscurityLibraryUpload. I was talking to Clarity last night and managed to get this whole request onto a single-line procedure with it. :P.

[SPOILER=Descriptions]
{
========================================
NOTE: The closest methods will return
the closest tPoint, glModel, or
glTexture to a specified point.

EXAMPLES:
----------------------------------------
warpedTortoiseModels:=glGetModels(1535441881);
posititonPlayer:=point(400,300);
writeLN('The closest Warped tortoise is at:');
writeLN(positionPlayer.closest(warpedTortoiseModels));
----------------------------------------
overloadTextures:=glGetTextures([92055,91800]);
positionMouse:=getMousePoint;
writeLN('The fourth closest Overload is at:');
writeLN(positionMouse.closest(overloadTextures,3));
========================================
}
{
========================================
NOTE: The closestTo methods act similar
to the closest methods, only backward.
They also returns a tPointArray sorted
based on distance from the specified
point.

EXAMPLES:
----------------------------------------
warpedTortoiseModels:=glGetModels(1535441881);
posititonPlayer:=point(400,300);
writeLN('The closest Warped tortoise is at:');
writeLN(warpedTortoiseModels.closestTo(positionPlayer)[0]);
----------------------------------------
overloadTextures:=glGetTextures([91800,92055]); //~ Minimap corner textures
positionMouse:=getMousePoint();
writeLN('The fourth closest Overload is at:'+toStr(overloadTextures.closestTo(positionMouse)[3]));
========================================
}
{
========================================
NOTE: The obsMakeCompassDeg function
moves the camera to a desired angle with
a given tolerance. If the camera
sucecssfully reaches the desired angle
by the timeOut, the function returns
true.

Angle | Facing
0 | North
90 | West
180 | South
270 | East
360 | North

EXAMPLES:
----------------------------------------
writeLN('Randomly rotating the camera to face south-east...'));
obsMakeCompassDeg(225);
----------------------------------------
writeLN('Randomly rotating the camera to face north-west...'));
obsMakeCompassDeg(45);
----------------------------------------
writeLN('Randomly rotating the camera to face north...'));
obsMakeCompassDeg('north');
========================================
}
{
========================================
NOTE: The miniMapMiddle functions
return the center point of the minimap.
This is where the player is located.

EXAMPLES:
----------------------------------------
glTextures:=glGetTextures([237147,386460]);
miniMapMiddle:=obsMiniMapMiddle(glTextures);
----------------------------------------
miniMapMiddle:=obsMiniMapMiddle();
========================================
}
[/SPOILER]