LSL Wiki Mirror 10-5-2006: GlobalCoordinate

HomePage :: PageIndex :: RecentChanges :: RecentlyCommented :: UserSettings ::

Global Coordinates


Global coordinates are used to describe a position relative to one point on the entire Second Life world, hence the word "global". This means that every place on the grid has a different vector value when represented in global coordinates. This allows global coordinates to describe a position without adverse effects occuring when a sim border is crossed.

A region coordinate can be converted into a global coordinate by adding to it the region corner of the simulator the coordinate is relative to.

vector currentGlobalPos = llGetRegionCorner() + llGetPos();

Using global coordinates, it's easy to create an object that can traverse the world. llSetPos and llMoveToTarget use region coordiantes; to use these functions to travel to a particular global coordinate, pass the result of subtracting the current region's corner from the global coordinate to the function. This converts the global coordinate into a region coordinate.

Example:
// Pass a global position to this function, and the object
// will move there. 
setGlobalPos(vector globalDest) {
    vector localDest;
    do {
        localDest = globalDest - llGetRegionCorner();
        llSetPos(localDest);
    } while (llVecDist(llGetPos(), localDest) > 0.1);
}

default {
    state_entry() {
        vector DABOOM_CORNER = <256000, 256000, 0>; // DaBoom's region corner.
        setGlobalPos(DABOOM_CORNER + <128, 128, 128>); // Travel to <128,128,128> in DaBoom.
    }
}

Q & A:


Q: Is the global coordinate origin point (<0, 0, 0>) located somewhere in the sim Da Boom?
A: No, Da Boom is merely the sim from which it all started. See coordinate.

Q: How do I convert the landmark positions (retrieved using llRequestInventoryData) to global coordinates?
A: Add the dataserver's return value to llGetRegionCorner before moving; the coordinate is relative to the simulator where you made the dataserver request.

Now to complicate things. Say you want to move a prim from one sim into another sim that is diagonal from it. An example situation would be calling llSetPos(<257,257,50>); from <254,254,50>. Your prim will first transfer into the sim on the x axis of the move and then into the sim on the y axis. If there is no sim on the x axis your prim will go offworld. So if you move a prim from Tan to Kissling it will go off world. But if you move a prim from Kissling to Tan it won't. -BW

(map)


Coordinates | Local Coordinates | Region Coordinates | Region Corner | Grid/World
There are 7 comments on this page. [Display comments/form]