/// <summary> /// /// </summary> /// <param name="simulator"></param> /// <param name="update"></param> /// <param name="RegionHandle"></param> /// <param name="TimeDilation"></param> protected void FireOnObjectUpdated(Simulator simulator, ObjectUpdate update, ulong RegionHandle, ushort TimeDilation) { if (OnObjectUpdated != null) { try { OnObjectUpdated(simulator, update, RegionHandle, TimeDilation); } catch (Exception e) { Client.Log(e.ToString(), Helpers.LogLevel.Error); } } }
/// <summary> /// A terse object update, used when a transformation matrix or /// velocity/acceleration for an object changes but nothing else /// (scale/position/rotation/acceleration/velocity) /// </summary> /// <param name="packet"></param> /// <param name="simulator"></param> protected void TerseUpdateHandler(Packet packet, Simulator simulator) { ImprovedTerseObjectUpdatePacket terse = (ImprovedTerseObjectUpdatePacket)packet; UpdateDilation(simulator, terse.RegionData.TimeDilation); for (int i = 0; i < terse.ObjectData.Length; i++) { ImprovedTerseObjectUpdatePacket.ObjectDataBlock block = terse.ObjectData[i]; try { int pos = 4; uint localid = Helpers.BytesToUIntBig(block.Data, 0); // Check if we are interested in this update if (!Client.Settings.ALWAYS_DECODE_OBJECTS && localid != Client.Self.localID && OnObjectUpdated == null) continue; #region Decode update data ObjectUpdate update = new ObjectUpdate(); // LocalID update.LocalID = localid; // State update.State = block.Data[pos++]; // Avatar boolean update.Avatar = (block.Data[pos++] != 0); // Collision normal for avatar if (update.Avatar) { update.CollisionPlane = new LLVector4(block.Data, pos); pos += 16; } // Position update.Position = new LLVector3(block.Data, pos); pos += 12; // Velocity update.Velocity = new LLVector3( Helpers.UInt16ToFloat(block.Data, pos, -128.0f, 128.0f), Helpers.UInt16ToFloat(block.Data, pos + 2, -128.0f, 128.0f), Helpers.UInt16ToFloat(block.Data, pos + 4, -128.0f, 128.0f)); pos += 6; // Acceleration update.Acceleration = new LLVector3( Helpers.UInt16ToFloat(block.Data, pos, -64.0f, 64.0f), Helpers.UInt16ToFloat(block.Data, pos + 2, -64.0f, 64.0f), Helpers.UInt16ToFloat(block.Data, pos + 4, -64.0f, 64.0f)); pos += 6; // Rotation (theta) update.Rotation = new LLQuaternion( Helpers.UInt16ToFloat(block.Data, pos, -1.0f, 1.0f), Helpers.UInt16ToFloat(block.Data, pos + 2, -1.0f, 1.0f), Helpers.UInt16ToFloat(block.Data, pos + 4, -1.0f, 1.0f), Helpers.UInt16ToFloat(block.Data, pos + 6, -1.0f, 1.0f)); pos += 8; // Angular velocity update.AngularVelocity = new LLVector3( Helpers.UInt16ToFloat(block.Data, pos, -64.0f, 64.0f), Helpers.UInt16ToFloat(block.Data, pos + 2, -64.0f, 64.0f), Helpers.UInt16ToFloat(block.Data, pos + 4, -64.0f, 64.0f)); pos += 6; // Textures // FIXME: Why are we ignoring the first four bytes here? if (block.TextureEntry.Length != 0) update.Textures = new LLObject.TextureEntry(block.TextureEntry, 4, block.TextureEntry.Length - 4); #endregion Decode update data LLObject obj = (update.Avatar) ? (LLObject)GetAvatar(simulator, update.LocalID, null): (LLObject)GetPrimitive(simulator, update.LocalID, null); #region Update Client.Self if (update.LocalID == Client.Self.localID) { Client.Self.collisionPlane = update.CollisionPlane; Client.Self.relativePosition = update.Position; Client.Self.velocity = update.Velocity; Client.Self.acceleration = update.Acceleration; Client.Self.relativeRotation = update.Rotation; Client.Self.angularVelocity = update.AngularVelocity; } #endregion Update Client.Self obj.Acceleration = update.Acceleration; obj.AngularVelocity = update.AngularVelocity; obj.CollisionPlane = update.CollisionPlane; obj.Position = update.Position; obj.Rotation = update.Rotation; obj.Velocity = update.Velocity; if (update.Textures != null) obj.Textures = update.Textures; // Fire the callback FireOnObjectUpdated(simulator, update, terse.RegionData.RegionHandle, terse.RegionData.TimeDilation); } catch (Exception e) { Client.Log(e.ToString(), Helpers.LogLevel.Warning); } } }
private void Objects_OnObjectUpdated(Simulator simulator, ObjectUpdate update, ulong regionHandle, ushort timeDilation) { regionX = (int)(regionHandle >> 32); regionY = (int)(regionHandle & 0xFFFFFFFF); if (update.Avatar) { lock (AvatarList) { // TODO: We really need a solid avatar and object tracker in Utilities to use here if (AvatarList.ContainsKey(update.LocalID)) { AvatarList[update.LocalID].CollisionPlane = update.CollisionPlane; AvatarList[update.LocalID].Position = update.Position; AvatarList[update.LocalID].Velocity = update.Velocity; AvatarList[update.LocalID].Acceleration = update.Acceleration; AvatarList[update.LocalID].Rotation = update.Rotation; AvatarList[update.LocalID].AngularVelocity = update.AngularVelocity; AvatarList[update.LocalID].Textures = update.Textures; } } } else { lock (SimPrims) { if (SimPrims.ContainsKey(simulator) && SimPrims[simulator].ContainsKey(update.LocalID)) { SimPrims[simulator][update.LocalID].Position = update.Position; SimPrims[simulator][update.LocalID].Velocity = update.Velocity; SimPrims[simulator][update.LocalID].Acceleration = update.Acceleration; SimPrims[simulator][update.LocalID].Rotation = update.Rotation; SimPrims[simulator][update.LocalID].AngularVelocity = update.AngularVelocity; SimPrims[simulator][update.LocalID].Textures = update.Textures; } } } }
/// <summary> /// /// </summary> /// <param name="simulator"></param> /// <param name="update"></param> /// <param name="RegionHandle"></param> /// <param name="TimeDilation"></param> protected void FireOnObjectUpdated(Simulator simulator, ObjectUpdate update, ulong RegionHandle, ushort TimeDilation) { if (OnObjectUpdated != null) { try { OnObjectUpdated(simulator, update, RegionHandle, TimeDilation); } catch (Exception e) { Logger.Log(e.Message, Helpers.LogLevel.Error, Client, e); } } }
void Objects_OnObjectUpdated(Simulator simulator, ObjectUpdate update, ulong regionHandle, ushort timeDilation) { if (!update.Avatar) return; if (update.LocalID == m_owner_local_id) { AutoPilotLocal(update.Position.X, update.Position.Y, update.Position.Z); } }
private void Objects_OnObjectUpdated(Simulator simulator, ObjectUpdate update, ulong regionHandle, ushort timeDilation) { if (!update.Avatar) return; if (!following) return; Avatar av; client.Network.CurrentSim.ObjectsAvatars.TryGetValue(update.LocalID, out av); if (av == null) return; if (av.Name == followName) { LLVector3 pos; if (av.SittingOn == 0) { pos = av.Position; } else { Primitive prim; client.Network.CurrentSim.ObjectsPrimitives.TryGetValue(av.SittingOn, out prim); if (prim == null) pos = client.Self.SimPosition; else pos = prim.Position + av.Position; } if (LLVector3.Dist(pos, client.Self.SimPosition) > followDistance) { int followRegionX = (int)(regionHandle >> 32); int followRegionY = (int)(regionHandle & 0xFFFFFFFF); ulong x = (ulong)(pos.X + followRegionX); ulong y = (ulong)(pos.Y + followRegionY); client.Self.AutoPilotCancel(); client.Self.AutoPilot(x, y, pos.Z); } } }