OpenMetaverse.Helpers.GlobalPosToRegionHandle C# (CSharp) Method

GlobalPosToRegionHandle() public static method

Given an X/Y location in absolute (grid-relative) terms, a region handle is returned along with the local X/Y location in that region
public static GlobalPosToRegionHandle ( float globalX, float globalY, float &localX, float &localY ) : ulong
globalX float The absolute X location, a number such as /// 255360.35
globalY float The absolute Y location, a number such as /// 255360.35
localX float The sim-local X position of the global X /// position, a value from 0.0 to 256.0
localY float The sim-local Y position of the global Y /// position, a value from 0.0 to 256.0
return ulong
        public static ulong GlobalPosToRegionHandle(float globalX, float globalY, out float localX, out float localY)
        {
            uint x = ((uint)globalX / 256) * 256;
            uint y = ((uint)globalY / 256) * 256;
            localX = globalX - (float)x;
            localY = globalY - (float)y;
            return Utils.UIntsToLong(x, y);
        }

Usage Example

Beispiel #1
0
        /// <summary>Process an incoming packet and raise the appropriate events</summary>
        /// <param name="sender">The sender</param>
        /// <param name="e">The EventArgs object containing the packet data</param>
        public void OnFindAgentReplyHandler(object sender, PacketReceivedEventArgs e)
        {
            if (m_FriendFound != null)
            {
                Packet          packet = e.Packet;
                FindAgentPacket reply  = (FindAgentPacket)packet;

                float x, y;
                UUID  prey         = reply.AgentBlock.Prey;
                ulong regionHandle = Helpers.GlobalPosToRegionHandle((float)reply.LocationBlock[0].GlobalX,
                                                                     (float)reply.LocationBlock[0].GlobalY, out x, out y);
                Vector3 xyz = new Vector3(x, y, 0f);

                OnFriendFoundReply(new FriendFoundReplyEventArgs(prey, regionHandle, xyz));
            }
        }
All Usage Examples Of OpenMetaverse.Helpers::GlobalPosToRegionHandle