llregionhandle.h

Go to the documentation of this file.
00001 
00032 #ifndef LL_LLREGIONHANDLE_H
00033 #define LL_LLREGIONHANDLE_H
00034 
00035 #include "indra_constants.h"
00036 #include "v3math.h"
00037 #include "v3dmath.h"
00038 
00039 inline U64 to_region_handle(const U32 x_origin, const U32 y_origin)
00040 {
00041         U64 region_handle;
00042         region_handle =  ((U64)x_origin) << 32;
00043         region_handle |= (U64) y_origin;
00044         return region_handle;
00045 }
00046 
00047 inline U64 to_region_handle(const LLVector3d& pos_global)
00048 {
00049         U32 global_x = (U32)pos_global.mdV[VX];
00050         global_x -= global_x % 256;
00051 
00052         U32 global_y = (U32)pos_global.mdV[VY];
00053         global_y -= global_y % 256;
00054 
00055         return to_region_handle(global_x, global_y);
00056 }
00057 
00058 inline U64 to_region_handle_global(const F32 x_global, const F32 y_global)
00059 {
00060         // Round down to the nearest origin
00061         U32 x_origin = (U32)x_global;
00062         x_origin -= x_origin % REGION_WIDTH_U32;
00063         U32 y_origin = (U32)y_global;
00064         y_origin -= y_origin % REGION_WIDTH_U32;
00065         U64 region_handle;
00066         region_handle =  ((U64)x_origin) << 32;
00067         region_handle |= (U64) y_origin;
00068         return region_handle;
00069 }
00070 
00071 inline BOOL to_region_handle(const F32 x_pos, const F32 y_pos, U64 *region_handle)
00072 {
00073         U32 x_int, y_int;
00074         if (x_pos < 0.f)
00075         {
00076 //              llwarns << "to_region_handle:Clamping negative x position " << x_pos << " to zero!" << llendl;
00077                 return FALSE;
00078         }
00079         else
00080         {
00081                 x_int = (U32)llround(x_pos);
00082         }
00083         if (y_pos < 0.f)
00084         {
00085 //              llwarns << "to_region_handle:Clamping negative y position " << y_pos << " to zero!" << llendl;
00086                 return FALSE;
00087         }
00088         else
00089         {
00090                 y_int = (U32)llround(y_pos);
00091         }
00092         *region_handle = to_region_handle(x_int, y_int);
00093         return TRUE;
00094 }
00095 
00096 // stuff the word-frame XY location of sim's SouthWest corner in x_pos, y_pos
00097 inline void from_region_handle(const U64 &region_handle, F32 *x_pos, F32 *y_pos)
00098 {
00099         *x_pos = (F32)((U32)(region_handle >> 32));
00100         *y_pos = (F32)((U32)(region_handle & 0xFFFFFFFF));
00101 }
00102 
00103 // stuff the word-frame XY location of sim's SouthWest corner in x_pos, y_pos
00104 inline void from_region_handle(const U64 &region_handle, U32 *x_pos, U32 *y_pos)
00105 {
00106         *x_pos = ((U32)(region_handle >> 32));
00107         *y_pos = ((U32)(region_handle & 0xFFFFFFFF));
00108 }
00109 
00110 // return the word-frame XY location of sim's SouthWest corner in LLVector3d
00111 inline LLVector3d from_region_handle(const U64 &region_handle)
00112 {
00113         return LLVector3d(((U32)(region_handle >> 32)), (U32)(region_handle & 0xFFFFFFFF), 0.f);
00114 }
00115 
00116 // grid-based region handle encoding. pass in a grid position
00117 // (eg: 1000,1000) and this will return the region handle.
00118 inline U64 grid_to_region_handle(U32 grid_x, U32 grid_y)
00119 {
00120         return to_region_handle(grid_x * REGION_WIDTH_UNITS,
00121                                                         grid_y * REGION_WIDTH_UNITS);
00122 }
00123 
00124 inline void grid_from_region_handle(const U64& region_handle, U32* grid_x, U32* grid_y)
00125 {
00126         from_region_handle(region_handle, grid_x, grid_y);
00127         *grid_x /= REGION_WIDTH_UNITS;
00128         *grid_y /= REGION_WIDTH_UNITS;
00129 }
00130         
00131 #endif

Generated on Thu Jul 1 06:09:04 2010 for Second Life Viewer by  doxygen 1.4.7