/// <summary> /// Teleport agent to another region /// </summary> /// <param name="regionHandle">handle of region to teleport agent to</param> /// <param name="position"><seealso cref="Vector3"/> position in destination sim to teleport to</param> /// <returns>true on success, false on failure</returns> /// <remarks>This call is blocking</remarks> public bool Teleport(ulong regionHandle, Vector3f position) { return Teleport(regionHandle, position, Vector3f.UnitZ); }
/// <summary> /// Get sim time from the appropriate packet /// </summary> /// <param name="packet">Incoming SimulatorViewerTimeMessagePacket from SL</param> /// <param name="simulator">Unused</param> private void TimeMessageHandler(Packet packet, Simulator simulator) { SimulatorViewerTimeMessagePacket time = (SimulatorViewerTimeMessagePacket)packet; sunPhase = time.TimeInfo.SunPhase; sunDirection = time.TimeInfo.SunDirection; sunAngVelocity = time.TimeInfo.SunAngVelocity; // TODO: Does anyone have a use for the time stuff? }
/// <summary> /// Rez an object from inventory /// </summary> /// <param name="simulator">Simulator to place object in</param> /// <param name="rotation">Rotation of the object when rezzed</param> /// <param name="position">Vector of where to place object</param> /// <param name="item">InventoryObject object containing item details</param> /// <param name="groupOwner">Guid of group to own the object</param> public Guid RequestRezFromInventory(Simulator simulator, Quaternionf rotation, Vector3f position, InventoryObject item, Guid groupOwner) { return RequestRezFromInventory(simulator, rotation, position, item, groupOwner, Guid.NewGuid(), false); }
public void LookAt(Vector3f origin, Vector3f target) { LookAt(origin, target, new Vector3f(0f, 0f, 1f)); }
protected void Orthonormalize() { // Make sure the axis are orthagonal and normalized xAxis.Normalize(); yAxis -= xAxis * (xAxis * yAxis); yAxis.Normalize(); zAxis = xAxis.Cross(ref yAxis); }
public void Rotate(float angle, Vector3f rotationAxis) { Quaternionf q = new Quaternionf(); q.FromAxisAngle(rotationAxis, angle); Rotate(q); }
public void LookDirection(Vector3f at) { LookDirection(at, Z_AXIS); }
private void Network_OnLoginResponse(bool loginSuccess, bool redirect, string message, string reason, LoginResponseData reply) { id = reply.AgentID; sessionID = reply.SessionID; secureSessionID = reply.SecureSessionID; firstName = reply.FirstName; lastName = reply.LastName; startLocation = reply.StartLocation; agentAccess = reply.AgentAccess; Movement.Camera.LookDirection(reply.LookAt); homePosition = reply.HomePosition; homeLookAt = reply.HomeLookAt; }
/// <summary> /// Decodes a byte[] array into a ParticleSystem Object /// </summary> /// <param name="data">ParticleSystem object</param> /// <param name="pos">Start position for BitPacker</param> public ParticleSystem(byte[] data, int pos) { // TODO: Not sure exactly how many bytes we need here, so partial // (truncated) data will cause an exception to be thrown if (data.Length > 0) { BitPack pack = new BitPack(data, pos); CRC = pack.UnpackUBits(32); PartFlags = pack.UnpackUBits(32); Pattern = (SourcePattern)pack.UnpackByte(); MaxAge = pack.UnpackFixed(false, 8, 8); StartAge = pack.UnpackFixed(false, 8, 8); InnerAngle = pack.UnpackFixed(false, 3, 5); OuterAngle = pack.UnpackFixed(false, 3, 5); BurstRate = pack.UnpackFixed(false, 8, 8); BurstRadius = pack.UnpackFixed(false, 8, 8); BurstSpeedMin = pack.UnpackFixed(false, 8, 8); BurstSpeedMax = pack.UnpackFixed(false, 8, 8); BurstPartCount = pack.UnpackByte(); float x = pack.UnpackFixed(true, 8, 7); float y = pack.UnpackFixed(true, 8, 7); float z = pack.UnpackFixed(true, 8, 7); AngularVelocity = new Vector3f(x, y, z); x = pack.UnpackFixed(true, 8, 7); y = pack.UnpackFixed(true, 8, 7); z = pack.UnpackFixed(true, 8, 7); PartAcceleration = new Vector3f(x, y, z); Texture = pack.UnpackGuid(); Target = pack.UnpackGuid(); PartDataFlags = (ParticleDataFlags)pack.UnpackUBits(32); PartMaxAge = pack.UnpackFixed(false, 8, 8); byte r = pack.UnpackByte(); byte g = pack.UnpackByte(); byte b = pack.UnpackByte(); byte a = pack.UnpackByte(); PartStartColor = new Color4(r, g, b, a); r = pack.UnpackByte(); g = pack.UnpackByte(); b = pack.UnpackByte(); a = pack.UnpackByte(); PartEndColor = new Color4(r, g, b, a); PartStartScaleX = pack.UnpackFixed(false, 3, 5); PartStartScaleY = pack.UnpackFixed(false, 3, 5); PartEndScaleX = pack.UnpackFixed(false, 3, 5); PartEndScaleY = pack.UnpackFixed(false, 3, 5); } else { CRC = PartFlags = 0; Pattern = SourcePattern.None; MaxAge = StartAge = InnerAngle = OuterAngle = BurstRate = BurstRadius = BurstSpeedMin = BurstSpeedMax = 0.0f; BurstPartCount = 0; AngularVelocity = PartAcceleration = Vector3f.Zero; Texture = Target = Guid.Empty; PartDataFlags = ParticleDataFlags.None; PartMaxAge = 0.0f; PartStartColor = PartEndColor = Color4.Black; PartStartScaleX = PartStartScaleY = PartEndScaleX = PartEndScaleY = 0.0f; } }
/// <summary> /// Update client's Position, LookAt and region handle from incoming packet /// </summary> /// <param name="packet">Incoming AgentMovementCompletePacket</param> /// <param name="simulator">Unused</param> /// <remarks>This occurs when after an avatar moves into a new sim</remarks> private void MovementCompleteHandler(Packet packet, Simulator simulator) { AgentMovementCompletePacket movement = (AgentMovementCompletePacket)packet; relativePosition = movement.Data.Position; Movement.Camera.LookDirection(movement.Data.LookAt); simulator.Handle = movement.Data.RegionHandle; simulator.SimVersion = Utils.BytesToString(movement.SimData.ChannelVersion); }
/// <summary> /// Handler for teleport Requests /// </summary> /// <param name="packet">Incoming TeleportHandler packet</param> /// <param name="simulator">Simulator sending teleport information</param> private void TeleportHandler(Packet packet, Simulator simulator) { bool finished = false; TeleportFlags flags = TeleportFlags.Default; if (packet.Type == PacketType.TeleportStart) { TeleportStartPacket start = (TeleportStartPacket)packet; teleportMessage = "Teleport started"; flags = (TeleportFlags)start.Info.TeleportFlags; teleportStat = TeleportStatus.Start; Logger.DebugLog("TeleportStart received, Flags: " + flags.ToString(), Client); } else if (packet.Type == PacketType.TeleportProgress) { TeleportProgressPacket progress = (TeleportProgressPacket)packet; teleportMessage = Utils.BytesToString(progress.Info.Message); flags = (TeleportFlags)progress.Info.TeleportFlags; teleportStat = TeleportStatus.Progress; Logger.DebugLog("TeleportProgress received, Message: " + teleportMessage + ", Flags: " + flags.ToString(), Client); } else if (packet.Type == PacketType.TeleportFailed) { TeleportFailedPacket failed = (TeleportFailedPacket)packet; teleportMessage = Utils.BytesToString(failed.Info.Reason); teleportStat = TeleportStatus.Failed; finished = true; Logger.DebugLog("TeleportFailed received, Reason: " + teleportMessage, Client); } else if (packet.Type == PacketType.TeleportFinish) { TeleportFinishPacket finish = (TeleportFinishPacket)packet; flags = (TeleportFlags)finish.Info.TeleportFlags; string seedcaps = Utils.BytesToString(finish.Info.SeedCapability); finished = true; Logger.DebugLog("TeleportFinish received, Flags: " + flags.ToString(), Client); // Connect to the new sim Simulator newSimulator = Client.Network.Connect(new IPAddress(finish.Info.SimIP), finish.Info.SimPort, finish.Info.RegionHandle, true, seedcaps); if (newSimulator != null) { teleportMessage = "Teleport finished"; teleportStat = TeleportStatus.Finished; // Disconnect from the previous sim Client.Network.DisconnectSim(simulator, true); Logger.Log("Moved to new sim " + newSimulator.ToString(), Helpers.LogLevel.Info, Client); } else { teleportMessage = "Failed to connect to the new sim after a teleport"; teleportStat = TeleportStatus.Failed; // We're going to get disconnected now Logger.Log(teleportMessage, Helpers.LogLevel.Error, Client); } } else if (packet.Type == PacketType.TeleportCancel) { //TeleportCancelPacket cancel = (TeleportCancelPacket)packet; teleportMessage = "Cancelled"; teleportStat = TeleportStatus.Cancelled; finished = true; Logger.DebugLog("TeleportCancel received from " + simulator.ToString(), Client); } else if (packet.Type == PacketType.TeleportLocal) { TeleportLocalPacket local = (TeleportLocalPacket)packet; teleportMessage = "Teleport finished"; flags = (TeleportFlags)local.Info.TeleportFlags; teleportStat = TeleportStatus.Finished; relativePosition = local.Info.Position; Movement.Camera.LookDirection(local.Info.LookAt); // This field is apparently not used for anything //local.Info.LocationID; finished = true; Logger.DebugLog("TeleportLocal received, Flags: " + flags.ToString(), Client); } if (OnTeleport != null) { try { OnTeleport(teleportMessage, teleportStat, flags); } catch (Exception e) { Logger.Log(e.Message, Helpers.LogLevel.Error, Client, e); } } if (finished) teleportEvent.Set(); }
/// <summary> /// Request teleport to a another simulator /// </summary> /// <param name="regionHandle">handle of region to teleport agent to</param> /// <param name="position"><seealso cref="Vector3"/> position in destination sim to teleport to</param> /// <param name="lookAt"><seealso cref="Vector3"/> direction in destination sim agent will look at</param> public void RequestTeleport(ulong regionHandle, Vector3f position, Vector3f lookAt) { if (Client.Network.CurrentSim != null && Client.Network.CurrentSim.Caps != null && Client.Network.CurrentSim.Caps.IsEventQueueRunning) { TeleportLocationRequestPacket teleport = new TeleportLocationRequestPacket(); teleport.AgentData.AgentID = Client.Self.AgentID; teleport.AgentData.SessionID = Client.Self.SessionID; teleport.Info.LookAt = lookAt; teleport.Info.Position = position; teleport.Info.RegionHandle = regionHandle; Logger.Log("Requesting teleport to region handle " + regionHandle.ToString(), Helpers.LogLevel.Info, Client); Client.Network.SendPacket(teleport); } else { teleportMessage = "CAPS event queue is not running"; teleportEvent.Set(); teleportStat = TeleportStatus.Failed; } }
/// <summary> /// Request teleport to a another simulator /// </summary> /// <param name="regionHandle">handle of region to teleport agent to</param> /// <param name="position"><seealso cref="Vector3"/> position in destination sim to teleport to</param> public void RequestTeleport(ulong regionHandle, Vector3f position) { RequestTeleport(regionHandle, position, Vector3f.UnitZ); }
/// <summary> /// Teleport agent to another region /// </summary> /// <param name="regionHandle">handle of region to teleport agent to</param> /// <param name="position"><seealso cref="Vector3"/> position in destination sim to teleport to</param> /// <param name="lookAt"><seealso cref="Vector3"/> direction in destination sim agent will look at</param> /// <returns>true on success, false on failure</returns> /// <remarks>This call is blocking</remarks> public bool Teleport(ulong regionHandle, Vector3f position, Vector3f lookAt) { if (Client.Network.CurrentSim == null || Client.Network.CurrentSim.Caps == null || !Client.Network.CurrentSim.Caps.IsEventQueueRunning) { // Wait a bit to see if the event queue comes online AutoResetEvent queueEvent = new AutoResetEvent(false); NetworkManager.EventQueueRunningCallback queueCallback = delegate(Simulator simulator) { if (simulator == Client.Network.CurrentSim) queueEvent.Set(); }; Client.Network.OnEventQueueRunning += queueCallback; queueEvent.WaitOne(10 * 1000, false); Client.Network.OnEventQueueRunning -= queueCallback; } teleportStat = TeleportStatus.None; teleportEvent.Reset(); RequestTeleport(regionHandle, position, lookAt); teleportEvent.WaitOne(Client.Settings.TELEPORT_TIMEOUT, false); if (teleportStat == TeleportStatus.None || teleportStat == TeleportStatus.Start || teleportStat == TeleportStatus.Progress) { teleportMessage = "Teleport timed out."; teleportStat = TeleportStatus.Failed; } return (teleportStat == TeleportStatus.Finished); }
public CoordinateFrame(Vector3f origin, Quaternionf rotation) { Matrix4f m = new Matrix4f(); m.FromQuaternion(rotation); this.origin = origin; xAxis = new Vector3f(m.M11, m.M21, m.M31); yAxis = new Vector3f(m.M12, m.M22, m.M32); zAxis = new Vector3f(m.M13, m.M23, m.M33); if (!IsFinite()) throw new ArgumentException("Non-finite in CoordinateFrame constructor"); }
public Ray(Vector3f origin, Vector3f direction) { Origin = origin; Direction = direction; }
public void ResetAxes() { xAxis = X_AXIS; yAxis = Y_AXIS; zAxis = Z_AXIS; }
/// <summary> /// Get a parcels LocalID /// </summary> /// <param name="simulator">Simulator parcel is in</param> /// <param name="position">Vector3 position in simulator (Z not used)</param> /// <returns>0 on failure, or parcel LocalID on success.</returns> /// <remarks>A call to <code>Parcels.RequestAllSimParcels</code> is required to populate map and /// dictionary.</remarks> public int GetParcelLocalID(Simulator simulator, Vector3f position) { return simulator.ParcelMap[(byte)position.Y / 4, (byte)position.X / 4]; }
public void Rotate(Matrix4f m) { xAxis = xAxis.Transform(ref m); yAxis = yAxis.Transform(ref m); Orthonormalize(); if (!IsFinite()) throw new Exception("Non-finite in CoordinateFrame.Rotate()"); }
/// <summary> /// Defalt constructor /// </summary> /// <param name="localID">Local ID of this parcel</param> public Parcel(int localID) { LocalID = localID; SelfCount = 0; OtherCount = 0; PublicCount = 0; OwnerID = Guid.Empty; IsGroupOwned = false; AuctionID = 0; ClaimDate = Utils.Epoch; ClaimPrice = 0; RentPrice = 0; AABBMin = Vector3f.Zero; AABBMax = Vector3f.Zero; Bitmap = new byte[0]; Area = 0; Status = ParcelStatus.None; SimWideMaxPrims = 0; SimWideTotalPrims = 0; MaxPrims = 0; TotalPrims = 0; OwnerPrims = 0; GroupPrims = 0; OtherPrims = 0; ParcelPrimBonus = 0; OtherCleanTime = 0; Flags = ParcelFlags.None; SalePrice = 0; Name = String.Empty; Desc = String.Empty; MusicURL = String.Empty; GroupID = Guid.Empty; PassPrice = 0; PassHours = 0; Category = ParcelCategory.None; AuthBuyerID = Guid.Empty; SnapshotID = Guid.Empty; UserLocation = Vector3f.Zero; UserLookAt = Vector3f.Zero; Landing = LandingType.None; Dwell = 0; RegionDenyAnonymous = false; RegionPushOverride = false; AccessWhiteList = new List<ParcelManager.ParcelAccessEntry>(); AccessBlackList = new List<ParcelManager.ParcelAccessEntry>(0); RegionDenyAgeUnverified = false; Media = new ParcelMedia(); ObscureMedia = false; ObscureMusic = false; }
/// <summary> /// /// </summary> /// <param name="at">Looking direction, must be a normalized vector</param> /// <param name="upDirection">Up direction, must be a normalized vector</param> public void LookDirection(Vector3f at, Vector3f upDirection) { // The two parameters cannot be parallel Vector3f left = upDirection.Cross(ref at); if (left == Vector3f.Zero) { // Prevent left from being zero at.X += 0.01f; at.Normalize(); left = upDirection.Cross(ref at); } left.Normalize(); xAxis = at; yAxis = left; zAxis = at.Cross(ref left); }
public Vector4f Cross(Vector3f vector) { }
public void LookAt(Vector3f origin, Vector3f target, Vector3f upDirection) { this.origin = origin; Vector3f at = target - origin; at.Normalize(); LookDirection(at, upDirection); }
public CoordinateFrame(Vector3f origin, Vector3f direction) { this.origin = origin; LookDirection(direction); if (!IsFinite()) throw new ArgumentException("Non-finite in CoordinateFrame constructor"); }
public CoordinateFrame(Vector3f origin) { this.origin = origin; xAxis = X_AXIS; yAxis = Y_AXIS; zAxis = Z_AXIS; if (!this.origin.IsFinite()) throw new ArgumentException("Non-finite in CoordinateFrame constructor"); }
public CoordinateFrame(Vector3f origin, Vector3f xAxis, Vector3f yAxis, Vector3f zAxis) { this.origin = origin; this.xAxis = xAxis; this.yAxis = yAxis; this.zAxis = zAxis; if (!IsFinite()) throw new ArgumentException("Non-finite in CoordinateFrame constructor"); }
/// <summary> /// Rez an object from inventory /// </summary> /// <param name="simulator">Simulator to place object in</param> /// <param name="rotation">Rotation of the object when rezzed</param> /// <param name="position">Vector of where to place object</param> /// <param name="item">InventoryObject object containing item details</param> public Guid RequestRezFromInventory(Simulator simulator, Quaternionf rotation, Vector3f position, InventoryObject item) { return RequestRezFromInventory(simulator, rotation, position, item, _Client.Self.ActiveGroup, Guid.NewGuid(), false); }
public CoordinateFrame(Vector3f origin, Matrix4f rotation) { this.origin = origin; xAxis = new Vector3f(rotation.M11, rotation.M21, rotation.M31); yAxis = new Vector3f(rotation.M12, rotation.M22, rotation.M32); zAxis = new Vector3f(rotation.M13, rotation.M23, rotation.M33); if (!IsFinite()) throw new ArgumentException("Non-finite in CoordinateFrame constructor"); }
/// <summary> /// Rez an object from inventory /// </summary> /// <param name="simulator">Simulator to place object in</param> /// <param name="rotation">Rotation of the object when rezzed</param> /// <param name="position">Vector of where to place object</param> /// <param name="item">InventoryObject object containing item details</param> /// <param name="groupOwner">Guid of group to own the object</param> /// <param name="queryID">User defined queryID to correlate replies</param> /// <param name="requestObjectDetails">if set to true the simulator /// will automatically send object detail packet(s) back to the client</param> public Guid RequestRezFromInventory(Simulator simulator, Quaternionf rotation, Vector3f position, InventoryObject item, Guid groupOwner, Guid queryID, bool requestObjectDetails) { RezObjectPacket add = new RezObjectPacket(); add.AgentData.AgentID = _Client.Self.AgentID; add.AgentData.SessionID = _Client.Self.SessionID; add.AgentData.GroupID = groupOwner; add.RezData.FromTaskID = Guid.Empty; add.RezData.BypassRaycast = 1; add.RezData.RayStart = position; add.RezData.RayEnd = position; add.RezData.RayTargetID = Guid.Empty; add.RezData.RayEndIsIntersection = false; add.RezData.RezSelected = requestObjectDetails; add.RezData.RemoveItem = false; add.RezData.ItemFlags = (uint)item.Flags; add.RezData.GroupMask = (uint)item.Permissions.GroupMask; add.RezData.EveryoneMask = (uint)item.Permissions.EveryoneMask; add.RezData.NextOwnerMask = (uint)item.Permissions.NextOwnerMask; add.InventoryData.ItemID = item.Guid; add.InventoryData.FolderID = item.ParentGuid; add.InventoryData.CreatorID = item.CreatorID; add.InventoryData.OwnerID = item.OwnerID; add.InventoryData.GroupID = item.GroupID; add.InventoryData.BaseMask = (uint)item.Permissions.BaseMask; add.InventoryData.OwnerMask = (uint)item.Permissions.OwnerMask; add.InventoryData.GroupMask = (uint)item.Permissions.GroupMask; add.InventoryData.EveryoneMask = (uint)item.Permissions.EveryoneMask; add.InventoryData.NextOwnerMask = (uint)item.Permissions.NextOwnerMask; add.InventoryData.GroupOwned = item.GroupOwned; add.InventoryData.TransactionID = queryID; add.InventoryData.Type = (sbyte)item.InventoryType; add.InventoryData.InvType = (sbyte)item.InventoryType; add.InventoryData.Flags = (uint)item.Flags; add.InventoryData.SaleType = (byte)item.SaleType; add.InventoryData.SalePrice = item.SalePrice; add.InventoryData.Name = Utils.StringToBytes(item.Name); add.InventoryData.Description = Utils.StringToBytes(item.Description); add.InventoryData.CreationDate = (int)Utils.DateTimeToUnixTime(item.CreationDate); _Client.Network.SendPacket(add, simulator); return queryID; }
/// <summary> /// Attempt to look up a simulator name and teleport to the discovered /// destination /// </summary> /// <param name="simName">Region name to look up</param> /// <param name="position">Position to teleport to</param> /// <param name="lookAt">Target to look at</param> /// <returns>True if the lookup and teleport were successful, otherwise /// false</returns> public bool Teleport(string simName, Vector3f position, Vector3f lookAt) { teleportStat = TeleportStatus.None; simName = simName.ToLower(); if (simName != Client.Network.CurrentSim.Name.ToLower()) { // Teleporting to a foreign sim GridRegion region; if (Client.Grid.GetGridRegion(simName, GridLayerType.Objects, out region)) { return Teleport(region.RegionHandle, position, lookAt); } else { teleportMessage = "Unable to resolve name: " + simName; teleportStat = TeleportStatus.Failed; return false; } } else { // Teleporting to the sim we're already in return Teleport(Client.Network.CurrentSim.Handle, position, lookAt); } }