diff options
Diffstat (limited to 'OpenSim')
-rw-r--r-- | OpenSim/Framework/Util.cs | 34 |
1 files changed, 17 insertions, 17 deletions
diff --git a/OpenSim/Framework/Util.cs b/OpenSim/Framework/Util.cs index ccbe75e..5250d30 100644 --- a/OpenSim/Framework/Util.cs +++ b/OpenSim/Framework/Util.cs | |||
@@ -368,13 +368,16 @@ namespace OpenSim.Framework | |||
368 | return Utils.UIntsToLong(X, Y); | 368 | return Utils.UIntsToLong(X, Y); |
369 | } | 369 | } |
370 | 370 | ||
371 | // Regions are identified with a 'handle' made up of its region coordinates packed into a ulong. | 371 | // Regions are identified with a 'handle' made up of its world coordinates packed into a ulong. |
372 | // Several places rely on the ability to extract a region's location from its handle. | 372 | // Region handles are based on the coordinate of the region corner with lower X and Y |
373 | // Note the location is in 'world coordinates' (see below). | 373 | // var regions need more work than this to get that right corner from a generic world position |
374 | // Region handles are based on the lowest coordinate of the region so trim the passed x,y to be the regions 0,0. | 374 | // this corner must be on a grid point |
375 | public static ulong RegionWorldLocToHandle(uint X, uint Y) | 375 | public static ulong RegionWorldLocToHandle(uint X, uint Y) |
376 | { | 376 | { |
377 | return Utils.UIntsToLong(X, Y); | 377 | ulong handle = X & 0xffffff00; // make sure it matchs grid coord points. |
378 | handle <<= 32; // to higher half | ||
379 | handle |= (Y & 0xffffff00); | ||
380 | return handle; | ||
378 | } | 381 | } |
379 | 382 | ||
380 | public static ulong RegionGridLocToHandle(uint X, uint Y) | 383 | public static ulong RegionGridLocToHandle(uint X, uint Y) |
@@ -387,30 +390,27 @@ namespace OpenSim.Framework | |||
387 | public static void RegionHandleToWorldLoc(ulong handle, out uint X, out uint Y) | 390 | public static void RegionHandleToWorldLoc(ulong handle, out uint X, out uint Y) |
388 | { | 391 | { |
389 | X = (uint)(handle >> 32); | 392 | X = (uint)(handle >> 32); |
390 | Y = (uint)(handle & (ulong)uint.MaxValue); | 393 | Y = (uint)(handle & 0xfffffffful); |
391 | } | 394 | } |
392 | 395 | ||
393 | public static void RegionHandleToRegionLoc(ulong handle, out uint X, out uint Y) | 396 | public static void RegionHandleToRegionLoc(ulong handle, out uint X, out uint Y) |
394 | { | 397 | { |
395 | uint worldX, worldY; | 398 | X = (uint)(handle >> 40) & 0x00ffffffu; // bring from higher half, divide by 256 and clean |
396 | RegionHandleToWorldLoc(handle, out worldX, out worldY); | 399 | Y = (uint)(handle >> 8) & 0x00ffffffu; // divide by 256 and clean |
397 | X = WorldToRegionLoc(worldX); | 400 | // if you trust the uint cast then the clean can be removed. |
398 | Y = WorldToRegionLoc(worldY); | ||
399 | } | 401 | } |
400 | 402 | ||
401 | // A region location can be 'world coordinates' (meters from zero) or 'region coordinates' | 403 | // A region location can be 'world coordinates' (meters) or 'region grid coordinates' |
402 | // (number of regions from zero). This measurement of regions relies on the legacy 256 region size. | 404 | // grid coordinates have a fixed step of 256m as defined by viewers |
403 | // These routines exist to make what is being converted explicit so the next person knows what was meant. | ||
404 | // Convert a region's 'world coordinate' to its 'region coordinate'. | ||
405 | public static uint WorldToRegionLoc(uint worldCoord) | 405 | public static uint WorldToRegionLoc(uint worldCoord) |
406 | { | 406 | { |
407 | return worldCoord / Constants.RegionSize; | 407 | return worldCoord >> 8; |
408 | } | 408 | } |
409 | 409 | ||
410 | // Convert a region's 'region coordinate' to its 'world coordinate'. | 410 | // Convert a region's 'region grid coordinate' to its 'world coordinate'. |
411 | public static uint RegionToWorldLoc(uint regionCoord) | 411 | public static uint RegionToWorldLoc(uint regionCoord) |
412 | { | 412 | { |
413 | return regionCoord * Constants.RegionSize; | 413 | return regionCoord << 8; |
414 | } | 414 | } |
415 | 415 | ||
416 | public static T Clamp<T>(T x, T min, T max) | 416 | public static T Clamp<T>(T x, T min, T max) |