Jump to content
  • Advertisement
Sign in to follow this  
lucky6969b

Map map coordinates into grid reference id

This topic is 1019 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I want to squeeze down the range of ids that identify individual cells of the map.

Like this as follows:

-10,30 (0,0)  0,30 (1,0)   10,30(2,0)
-10,20 (0,1)  0,20 (1,1)   10,20(2,1)
-10,10 (0,2)  0,10 (1,2)   10,10(2,2)
-10,  0 (0,3)  0, 0 (1,3)    10,0 (2,3)

My purpose of this move is to simplify the astar distance between nodes

Say if the true distance is 10.0 units (-10,30) to (0,30), I just want 1

Hope you get what I mean...

How do I go about doing that in C++?

Thanks

Jack

Edited by lucky6969b

Share this post


Link to post
Share on other sites
Advertisement

I find my map is not perfectly squared at 1:1

newX = (oldX + 10) / 10

newY = (30 - oldY) / 9

okay?

Thanks

Jack

Edited by lucky6969b

Share this post


Link to post
Share on other sites

Set a reference point ((-10, 30) in your example),  and calculate the delta values, then divide them by 10 :)

int refX = -10;
int refY = -30;

int simpleX = (mapX - refX) / 10;
int simpleY = (mapY - refY) / 10;

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!