Sign in to follow this  

Map map coordinates into grid reference id

Recommended Posts

lucky6969b    1330

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++?



Edited by lucky6969b

Share this post

Link to post
Share on other sites
vinterberg    1236

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this