PDA

View Full Version : MMToMS etc



ReadySteadyGo
01-22-2012, 06:46 AM
http://i.imgur.com/PanUV.png

program new;
{$DEFINE SMART}
{$i SRL/SRL.simba}
{$i SRL/SRL/misc/paintsmart.simba}

const
TILE = 12;

type
TPoint3D = record
x, y, z: Extended;
end;

TRotation = TPoint3D;
ATPoint3D = Array of TPoint3D;

TMatrix = record
Data: Array of Extended;
end;

TScene = record
TilePosition, PlayerTile, CameraPosition: TPoint3D;
TileRotation, CameraRotation: TRotation;
end;

function Point3D(x, y, z: Extended): TPoint3D;
begin
Result.x := x;
Result.y := y;
Result.z := z;
end;

function Rotation(xpheta, ypheta, zpheta: Extended): TRotation;
begin
Result.x := xpheta;
Result.y := ypheta;
Result.z := zpheta;
end;

function Multiply_Point3D_Matrix3x3(p: TPoint3D; m: TMatrix): TPoint3D;
begin
Result.x := (m.Data[0] * p.x) + (m.Data[1] * p.y) + (m.Data[2] * p.z);
Result.y := (m.Data[3] * p.x) + (m.Data[4] * p.y) + (m.Data[5] * p.z);
Result.z := (m.Data[6] * p.x) + (m.Data[7] * p.y) + (m.Data[8] * p.z);
end;

procedure TranslatePoints3D(var p: ATPoint3D; v: TPoint3D);
var
Len, i: Integer;
begin
Len := Length(p);
for i := 0 to Len-1 do
p[i] := Point3D(p[i].x + v.x, p[i].y + v.y, p[i].z + v.z);
end;

function RotatePoints3D(Points: ATPoint3D; rp: TPoint3D; r: TRotation): Array of TPoint3D;
var
m: TMatrix;
Len, i: Integer;
begin
R.x := radians(R.x);
R.Y := radians(R.Y);
r.z := radians(R.z);
SetLength(m.Data, 9);
m.Data := [Cos(r.y)*Cos(r.z), -Cos(r.x)*Sin(r.z) + Sin(r.x)*Sin(r.y)*Cos(r.z), Sin(r.x)*Sin(r.z)+Cos(r.x)*Sin(r.y)*Cos(r.z),
Cos(r.y)*Sin(r.z), Cos(r.x)*Cos(r.z) + Sin(r.x)*Sin(r.y)*Sin(r.z), -Sin(r.x)*Cos(r.z)+Cos(r.x)*Sin(r.y)*Sin(r.z),
-Sin(r.y), Sin(r.x)*Cos(r.y), Cos(r.x)*Cos(r.y)];

Len := Length(Points);
SetLength(Result, Len);

TranslatePoints3D(Points, Point3D(-rp.x, -rp.y, -rp.z));
for i := 0 to Len-1 do
Result[i] := Multiply_Point3D_Matrix3x3(Points[i], m);
TranslatePoints3D(Result, rp);
end;

function PerspectiveProject(p: ATPoint3D; cPos:TPoint3D): TPointArray;
var
Len, i: Integer;
begin
Len := Length(p);
SetLength(Result, Len);
for i := 0 to Len-1 do
begin
if (p[i].z - cPos.z) < 1 then
begin
Result[i].x:= 0;
Result[i].y:= 0;
Exit;
end;
Result[i].x:= Round((p[i].x - cPos.x) * {((512/2) / Tan(33/2))}864 / (p[i].z - cPos.z));
Result[i].y:= Round((p[i].y - cPos.y) * {(512/2) / Tan(33/2)}864 / (p[i].z - cPos.z));
end;
end;

function ProjectTile(var x, y: Integer; s: TScene; DrawColor{-1 to not Draw}: Integer): Boolean;
var
_3DPoints: ATPoint3D;
_2DPoints: TPointArray;
Len, i: Integer;
MSBox: TBox;
tp: TPoint3D;
begin
if DrawColor = -1 then
Len := 2
else
Len := 6;

SetLength(_3DPoints, Len);
SetLength(_2DPoints, Len);

tp := s.TilePosition;

_3DPoints[0] := s.PlayerTile;
_3DPoints[1] := Point3D(tp.x + TILE/2, tp.y + TILE, tp.z + TILE/2); // Center of input Tile

if DrawColor <> -1 then
begin
_3DPoints[2] := Point3D(tp.x + TILE, tp.y + TILE, tp.z);
_3DPoints[3] := Point3D(tp.x, tp.y + TILE, tp.z);
_3DPoints[4] := Point3D(tp.x + TILE, tp.y + TILE, tp.z + TILE);
_3DPoints[5] := Point3D(tp.x, tp.y + TILE, tp.z + TILE);
end;

TranslatePoints3D(_3DPoints, Point3D(-TILE/2, -TILE/2, 0));

_3DPoints := RotatePoints3D(_3DPoints, _3DPoints[0], s.TileRotation);

_3DPoints := RotatePoints3D(_3DPoints, s.CameraPosition, s.CameraRotation);
_2DPoints := PerspectiveProject(_3DPoints, s.CameraPosition);

MSBox.X1 := MSX1;
MSBox.Y1 := MSY1;
MSBox.X2 := MSX2;
MSBox.Y2 := MSY2;

for i := 0 to Len-1 do
begin
_2DPoints[i].x := _2DPoints[i].x + {(511/2) + 4}260;
_2DPoints[i].y := _2DPoints[i].y + {(334/2) - 4}163;
if not PointInBox(_2DPoints[i], MSBox) then
begin
Result := False;
Exit;
end;
end;

if DrawColor <> -1 then
begin
SMART_DrawLine(False, _2DPoints[2], _2DPoints[3], DrawColor);
SMART_DrawLine(False, _2DPoints[4], _2DPoints[5], DrawColor);
SMART_DrawLine(False, _2DPoints[3], _2DPoints[5], DrawColor);
SMART_DrawLine(False, _2DPoints[2], _2DPoints[4], DrawColor);
end;

x := _2DPoints[1].x;
y := _2DPoints[1].y;
Result := True;
end;

function GetTile(var x, y: Integer; tx, tz: Integer; Draw: Boolean; Color: Integer): Boolean;
var
s: TScene;
begin
with s do
begin
PlayerTile := Point3D(TILE/2, 20 + TILE, (TILE*10) - 8 + TILE/2);
TilePosition := Point3D((tx*TILE)-(8*TILE), 23, (tz*TILE) + (2*TILE)-8);
TileRotation := Rotation(0, (Round(0-rs_GetCompassAngleDegrees)), 0);
CameraPosition := Point3D(0, -233, 0);
CameraRotation := Rotation(65, 0, 0);
end;
if (not Draw) then
Color := -1;
Result := ProjectTile(x, y, s, Color);
end;

function MMToMSTileEx(var x, y: Integer; MMx, MMy:Integer; Draw: Boolean; Color: Integer): Boolean;
var
p: TPoint;
begin
p := RotatePoint(Point(MMx, MMy), rs_GetCompassAngleRadians, MMCX, MMCY);
p.x := Floor((p.x - (MMCX - 33)) / 4.0);
p.y := 17- Floor((p.y - (MMCY - 37)) / 4.0);

Result := GetTile(x, y, p.x, p.y, Draw, Color);
end;

function MMToMSTile(var x, y: Integer; MMx, MMy: Integer): Boolean;
begin
Result := MMToMSTileEx(x, y, MMx, MMy, False, 0);
end;


procedure ProjectTiles;
var i, j, x, y: Integer;
begin
for i := 0 to 16 do
for j := 0 to 16 do
GetTile(x, y, i, j, True, clGray);
end;

function GetMMDotsOnMS2(WhatDot: String; ShowGrid:Boolean): TPointArray;
var
x, y, Len, i, c, Col: Integer;
p: TPointArray;
begin
if ShowGrid then
ProjectTiles;
p := GetMiniMapDots(WhatDot);

case LowerCase(WhatDot) of
'npc', 'n', 'yellow', 'y': Col := clYellow;
'item', 'i', 'red', 'r': Col := clRed;
'player', 'p', 'white', 'w': Col := clWhite;
'friend', 'f', 'green', 'g': Col := clFriend;
'team', 't', 'blue', 'b', 'cape': Col := clBlue;
end;

Len := Length(p);
SetLength(Result, Len);
c := 0;
for i := 0 to Len-1 do
if MMToMSTileEx(x, y, p[i].x, p[i].y, True, Col) then
begin
Result[i] := Point(x, y);
Inc(c);
end;
SetLength(Result, c);
end;

var x, y: Integer;
begin
ClearDebug();
Smart_Server := 1;
SetupSRL();
SMART_SetupDebug;
SMART_ClearCanvas;

GetMMDotsOnMS2('Red', True);
GetMMDotsOnMS2('White', False);
GetMMDotsOnMS2('Yellow', False);
end.

Main
01-22-2012, 06:50 AM
sweett, but does it has to be highest camera angle?

senrath
01-22-2012, 06:53 AM
Even with the one box being a bit off, that is really impressive. Good job.

ReadySteadyGo
01-22-2012, 06:53 AM
Yes, I could add lowest camera angle trivally, but unless anyone knows a way to work out the angles in between, they are not possible.

Thanks senrath, yes it could do with a bit of tweeking. I made it a while ago and just cleaned it up today. I haven't really had a chance to play around with it. :)

NZ John
01-22-2012, 06:57 AM
Top of image.. "meatspin.com"... What're you upto? lol

ReadySteadyGo
01-22-2012, 07:00 AM
ask #srl

Harry
01-22-2012, 07:04 AM
Top of image..
Welcome to #SRL IRC.

Really neat. Basic autofighter PoC code with that would be a useful intermediate tutorial for newbies who want to make more accurate object findings based off the NPC dot.

Flight
01-22-2012, 07:23 AM
A bit off but I like where it's going. Really nice job. :) I want to see this improved.

Richard
01-22-2012, 11:33 AM
Yes, I could add lowest camera angle trivally, but unless anyone knows a way to work out the angles in between, they are not possible.

Thanks senrath, yes it could do with a bit of tweeking. I made it a while ago and just cleaned it up today. I haven't really had a chance to play around with it. :)

I'm currently working on something that can get the pitch. Might not be hugely reliable, relying on the character standing in a certain place etc.

This is great work, would you mind if I worked on this a bit? Science building on the shoulders of giants and all that.

Zyt3x
01-22-2012, 12:09 PM
Woah, that is near to perfect, ReadySteadyGo! I love it!

Home
01-22-2012, 12:23 PM
Please improve it more! Looks awsome!


~Home

loser69
01-22-2012, 12:44 PM
Wow looks neat.

nokkasiili
01-22-2012, 01:44 PM
Look like tileview from javabots very nice that you was able do that color

ReadySteadyGo
01-22-2012, 02:54 PM
Unfortunately, we are limited as to how accurate it can be, due to the 3 Camera views all being randomised slightly differently (MM, Compass, and MS). It can be improved slightly though. You can see in my screenshot that the FOV is ever so slightly off, ruining the perspective of the tiles closer to the viewer.

I need to find away to plug in information that I work out, rather than fiddling around to get it right. This is worked out with a UVN Camera system, so if I implement that to determine the camera position and pitch (rather than my current technique of fiddling with it almost manually), it will technically be perfect.

Thank you everyone for your comments, I will do my best to make this more accurate. Richard, of course, please go ahead.

Harry
01-22-2012, 09:31 PM
You could try that console command that gives your camera angle, and do some maths with that? Open dev console and type "help".

ReadySteadyGo
01-22-2012, 09:40 PM
Only problem is that I don't understand the output, the height seems to change a lot even without moving the compass or pitch. I'm assuming they use something along the lines of http://gra-phic.blogspot.com/2011/08/u-v-n-system.html

To get the values I currently use, I just used photo match in Google Sketch up, which is incredible. You can then use the ruby console to get information about the camera setup, but I must be botching something with my calculations because I can't replicate it exactly.

Shatterhand
01-30-2012, 10:10 PM
The picture looks cool, but could you give me some explanataion?

ReadySteadyGo
01-31-2012, 05:33 PM
Hi hunt3rx3

I have actually released a tutorial today which uses this. Check out http://villavu.com/forum/showthread.php?p=911890

If you were enquiring how it actually works, let me know and I'll write up an explanation.

Flight
03-27-2012, 01:59 PM
I'm bumping this. I personally think it should be added to the library. Anyways, if it's OK by you, RSG, I'll be using most of this in an Essence-Mining script.

Coh3n
03-27-2012, 11:00 PM
Doesn't the grid functions Narcle added a while back do the same thing?

Zyt3x
03-27-2012, 11:39 PM
Doesn't the grid functions Narcle added a while back do the same thing?type
TPoint3D = record
x, y, z: Extended;
end;

This one uses a 3D engine for more accurate results, so no. Not the same thing

Narcle
03-28-2012, 12:19 AM
type
TPoint3D = record
x, y, z: Extended;
end;

This one uses a 3D engine for more accurate results, so no. Not the same thing

Umm the Z axis is unknown so it can't be accurate, its just a guess. However his uses the compass so it can be used at more compass angles but doesn't mean its accurate. Same with mine its just a 'guess'.

ReadySteadyGo
03-29-2012, 11:36 AM
I'm bumping this. I personally think it should be added to the library. Anyways, if it's OK by you, RSG, I'll be using most of this in an Essence-Mining script.

Yes of course, please go ahead. :)

Adding to what Narcle said. Yeah if there is overly bumpy terrain it will not be able to account for this. I don't see why people shouldn't try this out though, I've got some rather accurate results with this, and although the camera does need to be at its highest point, it really allows the minimap information to be utilised at any angle.

It is also very fast. I have found it actually reduced the time searching for objects because it cuts down the possible locations of the object considerably.

There is also the potential to map out things that you know the height of, a table for instance (I used this when I was working on a Dungeoneer).

Flight
03-29-2012, 11:50 AM
There is also the potential to map out things that you know the height of, a table for instance (I used this when I was working on a Dungeoneer).

I was thinking about this as well. The higher an object, the further away from the center of the MS it would appear.

Yes it does give very accurate results. In my essence-miner I use this for searching for the exit portals in the mine. I grab the teleport MM symbol, get the middle point of that and plug it into your MMToMSEx to get an (wonderfully) accurate starting point, then split the screen into 35x35 boxes and count pixelshift in each. I search each box with a high count starting from your MMToMSEx point. Never fails me. ;)

ReadySteadyGo
03-29-2012, 11:52 AM
I was thinking about this as well. The higher an object, the further away from the center of the MS it would appear.

Yes it does give very accurate results. In my essence-miner I use this for searching for the exit portals in the mine. I grab the teleport MM symbol, get the middle point of that and plug it into your MMToMSEx to get an (wonderfully) accurate starting point, then split the screen into 35x35 boxes and count pixelshift in each. I search each box with a high count starting from your MMToMSEx point. Never fails me. ;)

That sounds ridiculously sexy, can't wait to see it. :)

Also, you don't even need to worry about the MS at all, you just modify the z value and it will calculate it for you.

Wetish
03-30-2012, 02:32 AM
This looks amazing. Like reflection but color

euphemism
03-30-2012, 02:05 PM
This looks amazing. Like reflection but color

It's more like math than reflection. In fact, it isn't reflection or color, it IS math. So, it is much cooler.

Flight
03-30-2012, 02:14 PM
It's more like math than reflection. In fact, it isn't reflection or color, it IS math. So, it is much cooler.

Exactly what makes it so interesting.

Er1k
03-30-2012, 02:20 PM
Exactly what makes it so interesting.

I thought only the grid16 functions was implemented? Is this one we're talking about a far more accurate one?

I know this can forever change the way of object finding because being able to convert a MM point to a MS point allows for many crazy applications, e.g. using SPS/DTM/ODTM/NPCDots/etc to locate an object. It will save so many efforts in some of the traditionally difficult areas in color object finding, the most important being doors :D

Coh3n
03-30-2012, 05:09 PM
Has anyone tried using this in combination with SPS to find an object on the MS? It will be more accurate with SPS2.0, but I'm just wondering if it's possible.

ReadySteadyGo
03-30-2012, 06:53 PM
Has anyone tried using this in combination with SPS to find an object on the MS? It will be more accurate with SPS2.0, but I'm just wondering if it's possible.

I'm not familiar with SPS but I've used this with TPA colour finding for doors etc so assuming SPS can give you a minimap co-ord that is visible on the minimap, it's definitely possible.

Abu
03-30-2012, 07:21 PM
Looks amazing :)

Can't wait to see what this can lead to...

tls
03-30-2012, 07:57 PM
It's more like math than reflection. In fact, it isn't reflection or color, it IS math. So, it is much cooler.

Reflection used math...it converted certain information from the client to an x, y point on the screen.

Aegis
03-30-2012, 08:34 PM
Woah, this looks awesome! I'm tempted to implement this in the script I'm working on right now!

Zyt3x
03-30-2012, 09:06 PM
Reflection used math...it converted certain information from the client to an x, y point on the screen.I was just about to say this, reflection used reflection + math, we use color + math :)

Joe
03-30-2012, 11:06 PM
Top of image.. "meatspin.com"... What're you upto? lol

I had to do a double-take... L-0h-freakin-L

Imagine
04-09-2012, 01:35 AM
So if I was to use this, what would be a sample "short" function implementing this?

Would I first copy the whole code above the mainloop, and then just use the GetMMDotsOnMS2
and use the returned points to search for a specified monster/item from that point?

ReadySteadyGo
04-10-2012, 01:41 PM
So if I was to use this, what would be a sample "short" function implementing this?

Would I first copy the whole code above the mainloop, and then just use the GetMMDotsOnMS2
and use the returned points to search for a specified monster/item from that point?

I've written a tutorial which includes a sample script using the include.
http://villavu.com/forum/showthread.php?p=911890

Imagine
04-10-2012, 10:51 PM
^ Thank you, I'm reading it now :)

m34tcode
04-13-2012, 04:33 AM
This really should be included in the srl include. While it may not be accurate enough to click small objects, it is clearly good enough to use for sorting tpas. Could enhance the speed of scripts incredibly.

I can see that being used in agility courses

bg5
04-23-2012, 01:33 PM
Hi, your project is very impressive.
I have been playing with it in dungeon for some time. I modificated it a bit to get 4 corners of tile as output and than search inside tile for objects with canny core. It has potential to be very powerfull tool:
http://puu.sh/r4h8

However I noticed few things:
- sometimes it misses dots ,when they are close to each other (like in screen below and above) ,but I think it rather has to do with GetMiniMapDots SRL function.
- it's rarery losing accuracy
http://puu.sh/r4zT
- only one-way conversion MM->MS. Would it be hard to add conversion in opposite direction? ;)

Olly
04-23-2012, 09:01 PM
Hi, your project is very impressive.
I have been playing with it in dungeon for some time. I modificated it a bit to get 4 corners of tile as output and than search inside tile for objects with canny core. It has potential to be very powerfull tool:
http://puu.sh/r4h8

However I noticed few things:
- sometimes it misses dots ,when they are close to each other (like in screen below and above) ,but I think it rather has to do with GetMiniMapDots SRL function.
- it's rarery losing accuracy
http://puu.sh/r4zT
- only one-way conversion MM->MS. Would it be hard to add conversion in opposite direction? ;)

Now that sir looks very promising. +rep!

Narcle
04-23-2012, 09:10 PM
- sometimes it misses dots ,when they are close to each other (like in screen below and above) ,but I think it rather has to do with GetMiniMapDots SRL function.


Its the way they show the dots on the mini map. The dots are distorted so they aren't actually in the correct place they should be (this is obviously done on purpose by Jagex). GetMiniMapDots works as it should, its the game distorting the location so you can't use it perfectly.

So as in your case the distorting will change 2 dots to be in each other, even though they shouldn't be.

Gala
04-26-2012, 10:47 AM
I am using this in a script I am writing right now and it is really accurate.
(It detects small npc's moving non-stop without any problems.)

Shatterhand
05-12-2012, 02:05 PM
Ok I put this into a repeat ... until False circle and its very fast and accurate! Will make more tests!

Shatterhand
05-16-2012, 09:40 PM
I made some further tests. The drawing is nice. But getting the points of them is not working well.
TPA := GetMMDotsOnMS2('red',false);
Writeln(IntToStr(High(TPA)));
for i:=0 to High(TPA) do
begin
Mouse(TPA[i].x,TPA[i].y,0,0,mouse_right);
Wait(1000);
end;
I tried this and while like 4 red boxes were painted on the screen, it only right clicked on one of them. Am I doing something wrong? That TPA return value isnt the middle points of the painted red boxes?

ReadySteadyGo
05-16-2012, 10:05 PM
Hi, it might actually be an issue with SRLs GetMiniMapDots, not sure right now though. It's being discussed in another thread.

http://villavu.com/forum/showthread.php?t=82510

weizhen
05-28-2012, 02:41 PM
your script of abyss can yousend me teh update version i am james my msn is runescapeplayer@msn.cn

Flight
05-28-2012, 02:52 PM
your script of abyss can yousend me teh update version i am james my msn is runescapeplayer@msn.cn

Mate, you're better off contacting him directly rather than posting such messages publicly on a completely different post he made. Atleast use your PM system; it is there for a reason.

Gala
05-28-2012, 06:01 PM
your script of abyss can yousend me teh update version i am james my msn is runescapeplayer@msn.cn

So "James", let me guess. You are NOT a chinese goldfarmer looking for a way to learn script and to be a part of the community.

@topic
What is the main differnece to narcle's MMToMS?

John
06-04-2012, 06:36 AM
Awesome
http://puu.sh/yJwl
In theory you could make it recognise the Obj-DTM's on the MM like
These?
http://puu.sh/yJy9

footballjds
03-28-2013, 03:53 PM
ready, gravedig, steady, update this for zoom?

Olly
03-28-2013, 05:38 PM
ready, gravedig, steady, update this for zoom?

Given up on Narcle i see :p, I don't think rsg is active either.. at-least i never see him on irc anymore. :(

footballjds
03-28-2013, 05:47 PM
Given up on Narcle i see :p, I don't think rsg is active either.. at-least i never see him on irc anymore. :(

I haven't gotten a reply PM from Narcle in over a month or so. Not given up, just looking for something faster!

Runehack123
03-28-2013, 05:51 PM
YOU TELL EM FOOTBALL you tell em
:d what football said ^ me too I full support on this been talking with footyjrsfootball on other thread about it and HE IS RIGHT
so yeah update pleaaaaaase I will do all sorts of wonderful things to you if you do :d

Olly
03-28-2013, 05:51 PM
I haven't gotten a reply PM from Narcle in over a month or so. Not given up, just looking for something faster!

Well i actually spoke to RSG somewhat recently about this and he said you can change these values;

PlayerTile := Point3D(TILE/2, 20 + TILE, (TILE*10) - 8 + TILE/2);
TilePosition := Point3D((tx*TILE)-(8*TILE), 23, (tz*TILE) + (2*TILE)-8);
TileRotation := Rotation(0, (Round(0-rs_GetCompassAngleDegrees)), 0);
CameraPosition := Point3D(0, -233, 0);
CameraRotation := Rotation(65, 0, 0);

Obviously for me and you its just trial and error :p

Runehack123
03-28-2013, 05:58 PM
Well i actually spoke to RSG somewhat recently about this and he said you can change these values;

PlayerTile := Point3D(TILE/2, 20 + TILE, (TILE*10) - 8 + TILE/2);
TilePosition := Point3D((tx*TILE)-(8*TILE), 23, (tz*TILE) + (2*TILE)-8);
TileRotation := Rotation(0, (Round(0-rs_GetCompassAngleDegrees)), 0);
CameraPosition := Point3D(0, -233, 0);
CameraRotation := Rotation(65, 0, 0);

Obviously for me and you its just trial and error :p
I have NO IDEA what those means hahaha! :o
time for some trial and error like you said

sad times :(

Olly
03-28-2013, 06:00 PM
I mean its obvious what they do, but i have no real clue what changing the values etc would do + i bet you could get the camera postion from runescape directly and "convert" it onto it if you knew how it was done :P

Runehack123
03-28-2013, 06:02 PM
I mean its obvious what they do, but i have no real clue what changing the values etc would do + i bet you could get the camera postion from runescape directly and "convert" it onto it if you knew how it was done :P

because you are god SSRL of scripting you understand I don't even get what tilerotation means
so derp...

Olly
03-28-2013, 06:08 PM
because you are god SSRL of scripting you understand I don't even get what tilerotation means
so derp...

Lol, I wish i was a god but isn't it somewhat common sense?

regular tile, rotated tile (ie how much tile rotation there is), i could be wrong but it makes sense like this.
http://i.imgur.com/V5ll4ui.png