SA-MP Forums Archive
Geting center position of gtasa map - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: Other (https://sampforum.blast.hk/forumdisplay.php?fid=7)
+--- Forum: Everything and Nothing (https://sampforum.blast.hk/forumdisplay.php?fid=23)
+--- Thread: Geting center position of gtasa map (/showthread.php?tid=94299)



Geting center position of gtasa map - StrickenKid - 29.08.2009

Im making a mapper app and it gets the coords from the image but how do i actually get the coords from the image? :S

The x and y positions start at the top left corner and go to the bottom right, i need it so it goes from the center out, how samp works...

Anyone know?

Thanks.


Re: Geting center position of gtasa map - XPlatform - 29.08.2009

Basically, all I can think of is using some math to figure out the coordinate based on the top left.

If you want the coordinate from the center out, subtract half the SA:MP X-axis to the X-axis value, and add half the SA:MP Y-axis from the Y-axis.

So, the SA:MP map is roughly 6000x6000.
Based on what you have described, the top left of your screen is 0,0. In SA:MP world, this is -3000,3000.
Basically, to make your top left be what it should be, you subtract 3000 from your X-axis value, and add 3000 to your Y-axis value.

As an example, lets say that in your app you have the coordinate 4412,-2316. If you want the SA:MP coordinate, you do this:
Код:
 4412 - 3000 = 1412
-2316 + 3000 = 1316
Giving you the correct SA:MP map position of 1412,1316.

You can easily make a function or two to convert these as needed.

I hope I helped,

CodeMatrix



Re: Geting center position of gtasa map - [MM]Murphy - 29.08.2009

Quote:
Originally Posted by CodeMatrix
Basically, all I can think of is using some math to figure out the coordinate based on the top left.

If you want the coordinate from the center out, subtract half the SA:MP X-axis to the X-axis value, and add half the SA:MP Y-axis from the Y-axis.

So, the SA:MP map is roughly 6000x6000.
Based on what you have described, the top left of your screen is 0,0. In SA:MP world, this is -3000,3000.
Basically, to make your top left be what it should be, you subtract 3000 from your X-axis value, and add 3000 to your Y-axis value.

As an example, lets say that in your app you have the coordinate 4412,-2316. If you want the SA:MP coordinate, you do this:
Код:
 4412 - 3000 = 1412
-2316 + 3000 = 1316
Giving you the correct SA:MP map position of 1412,1316.

You can easily make a function or two to convert these as needed.

I hope I helped,

CodeMatrix
Wouldnt the bold written be like this:

0,0 on his screen = 6000,0


Re: Geting center position of gtasa map - Westie - 29.08.2009

Murphy, no. (0, 0, 0) is actually at Blueberry Acres, so what you said is wrong.

Код:
iImagePosX = (eClick.offsetX ? eClick.offsetX : eClick.pageX - eElement.offsetLeft);
iImagePosY = (eClick.offsetY ? eClick.offsetY : eClick.pageY - eElement.offsetTop);
iRelativeX = Math.round(((iImagePosX / iImageWidth) * 6000) - 3000);
iRelativeY = Math.round((6000 - (iImagePosY / iImageHeight) * 6000) - 3000);
This is what I use in Javascript to get the GTA:SA relative location. Note that if your image is smaller than 6000 pixels, then you'll have to take that into consideration.


Re: Geting center position of gtasa map - StrickenKid - 29.08.2009

Alright thanks, I will go ahead and try that code.

Hmm, The only problem is that i just started scripting c# yesterday so i don't know much, so im not actually sure how to convert the java script to c#.

Ill just trial and error I guess.


Re: Geting center position of gtasa map - StrickenKid - 30.08.2009

Alright, well after allot of testing I finally got it, I looked at some live map scripts which also helped.

So this is the code that works:

Код:
      Xpos = (-(((e.X * -1) + (pictureBox.Width / 2)) / 2) * (pictureBox.Width / (pictureBox.Width / 2)));
      Ypos = ((((e.Y * -1) + (pictureBox.Height / 2)) / 2) * (pictureBox.Height / (pictureBox.Height / 2)));
Now, I need to figure out how to get the mouse pos to read in decimals, eg 3223.4322 instead of just 3223.


Re: Geting center position of gtasa map - Westie - 30.08.2009

Did you assign Xpos and Ypos to be integers?


Re: Geting center position of gtasa map - StrickenKid - 30.08.2009

Quote:
Originally Posted by /^We(stie|z+[e|a
r)$/ ]
Did you assign Xpos and Ypos to be integers?
No, floats.


Re: Geting center position of gtasa map - StrickenKid - 30.08.2009

What do you mean? It is accurate, I've tested it and the positions from the map and in game are almost exact, maybe off by 1 but it is accurate...

If you know a better way of doing this you can tell us...


Re: Geting center position of gtasa map - Redirect Left - 30.08.2009

Also, there are already mapping applications like that

http://forum.sa-mp.com/index.php?topic=14702.0