Author Topic: Cell Coordinates and pathfinding  (Read 393 times)

lordzeon

  • Newbie
  • *
  • Posts: 29
    • View Profile
Cell Coordinates and pathfinding
« on: February 18, 2020, 08:07:56 PM »
Hi, im trying to implement pathfinding in my Globe scene, but im getting a headache with coordinate systems. Im using DOTween library to do local path movements of marker vehicles, for flying vehicles, there was no problem at all, but with pathfinding is not working correctly, using
map.GetWorldSpaceCellCenter(cellindex)
where cell index is map.GetCellAtWorldPos(latLon);
return a very different value to
map.GetSpherePointFromLatLon(latLon);
i think that GetSpherePointFromLatLon is returning local coordinates, and GetWorldSpaceCellCenter is world coordinates, but i cannot convert it correctly, InverseTransformPoint return a very different number.
examples:
GetSpherePointFromLatLon = (cellindex)GetWorldSpaceCellCenter = InverseTransformPoint
(-0.1, 0.4, 0.2) = (85558)(23.9, 7.3, 0.1) = (-44.6, -53.1, 22.4)
(-0.1, 0.4, 0.3) = (86224)(24.2, 6.2, 0.1) = (-45.2, -54.7, 20.9)


also, sometimes no path is found when there is a one, no matter if i set height threshold to 255... no path is found
i´ve tried with map.cells[cellIndex].spherePoint and it is always the same number.

How can i correctly convert the coordinates of the cells to SpherePoints ?

Kronnect

  • Administrator
  • Hero Member
  • *****
  • Posts: 5706
    • View Profile
Re: Cell Coordinates and pathfinding
« Reply #1 on: February 19, 2020, 01:39:06 AM »
Hi,

- GetWorldSpaceCellCenter(cellIndex) returns the center of a cell in world space.

- Conversion.GetSpherePointFromLatLon(latLon) returns the sphere position in local space from any latitude/longitude coordinate.

Can you share the full code sample which is causing you trouble?





lordzeon

  • Newbie
  • *
  • Posts: 29
    • View Profile
Re: Cell Coordinates and pathfinding
« Reply #2 on: February 19, 2020, 10:32:24 AM »
Hi, yes, the problem must be local vs world coordinates, but there is no method to get local coordinates for a cell. The problem is that i need to mix the 2, because if not path is found, the vehicle has to move anyway but without path. Alternatively, how do i convert from Conversion.GetSpherePointFromLatLon(latLon) to World Coordinates?

i attach the file because it is marked as spam... ??

Kronnect

  • Administrator
  • Hero Member
  • *****
  • Posts: 5706
    • View Profile
Re: Cell Coordinates and pathfinding
« Reply #3 on: February 19, 2020, 11:53:35 AM »
I've whitelisted your emali address so you shouldn't have any issues now posting code. Please let me know if problem persists.

To convert from local to world space coordinates, simply use transform.TransformPoint. For example:

Code
Vector3 spherePos = Conversion.GetSpherePointFromLatLon(latLon);
Vector3 worldPosition = map.transform.TransformPoint(spherePos);

lordzeon

  • Newbie
  • *
  • Posts: 29
    • View Profile
Re: Cell Coordinates and pathfinding
« Reply #4 on: February 19, 2020, 02:39:46 PM »
Yes, i've tried that already, but i found the error, i had this code to store coordinates:

Code
void FindCoordinates()
        {
            from = Conversion.GetSpherePointFromLatLon(fromLatLon);
            to = Conversion.GetSpherePointFromLatLon(toLatLon);
            distanciaTramo = WorldMapGlobe.instance.calc.Distance(fromLatLon, toLatLon);
            fromCell = WorldMapGlobe.instance.GetCellAtWorldPos(fromLatLon);
            toCell = WorldMapGlobe.instance.GetCellAtWorldPos(toLatLon);
        }

i was using LatLon as WorldPos to find the cell, that is why the resulting cell was incorrect, so the pathfinding wasn´t working and when it found a cell was a coincidence.

Code
void FindCoordinates()
        {
            from = Conversion.GetSpherePointFromLatLon(fromLatLon);
            to = Conversion.GetSpherePointFromLatLon(toLatLon);
            distanciaTramo = WorldMapGlobe.instance.calc.Distance(fromLatLon, toLatLon);
            fromCell = WorldMapGlobe.instance.GetCellAtWorldPos(from);
            toCell = WorldMapGlobe.instance.GetCellAtWorldPos(to);
        }

It would be cool to have overload for this kind of methods, so Vector2 would be used as LatLon, Vector3 as WorldPos, with optional bool to use SpherePos, because there are too many different ways to store a location and not always a direct way to convert, for example, to add a market, you need SphereLocation, but maybe you have LatLon, or cell index, or World Pos, it could be much simpler with a overload method, and even better if the method distinguish correctly a Vector3 as WorldPos or SpherePos, i think this could be a good addition to any method that take a position as argument.

Another question, there is some way to know if a specific SpherePos is water or land?


Kronnect

  • Administrator
  • Hero Member
  • *****
  • Posts: 5706
    • View Profile
Re: Cell Coordinates and pathfinding
« Reply #5 on: February 20, 2020, 03:24:40 AM »
Well, glad you found the issue.

Rergarding the water check, yes, it could be possible but first, what do you mean by water? I can add a method that checks the Earth heightmap at a given sphere position or lat/lon and return true/false based no that value. Or if you're using the grid mask to make cells invisible, you can use the new IsCellVisible (or just check the cell.visible property).