/// <summary> /// Return a Vector rotated around the Quaternion /// </summary> /// <param name="q1"> /// Quaternion /// </param> /// <param name="v2"> /// Vector /// </param> /// <returns> /// </returns> public static IVector3 RotateVector3(IQuaternion q1, IVector3 v2) { Quaternion QuatVect = new Quaternion(v2.x, v2.y, v2.z, 0); Quaternion QuatNorm = (Quaternion)q1.Normalize(); Quaternion Result = Hamilton(Hamilton(QuatNorm, QuatVect), QuatNorm.Conjugate()); return(new Vector3(Result.x, Result.y, Result.z)); }
/// <summary> /// Returns the Hamilton Product of two Quaternions /// </summary> /// <param name="vLeft"> /// Quaternion 1 /// </param> /// <param name="vRight"> /// Quaternion 2 /// </param> /// <returns> /// </returns> public static Quaternion Hamilton(IQuaternion vLeft, IQuaternion vRight) { double w = (vLeft.w * vRight.w) - (vLeft.x * vRight.x) - (vLeft.y * vRight.y) - (vLeft.z * vRight.z); double x = (vLeft.w * vRight.x) + (vLeft.x * vRight.w) + (vLeft.y * vRight.z) - (vLeft.z * vRight.y); double y = (vLeft.w * vRight.y) - (vLeft.x * vRight.z) + (vLeft.y * vRight.w) + (vLeft.z * vRight.x); double z = (vLeft.w * vRight.z) + (vLeft.x * vRight.y) - (vLeft.y * vRight.x) + (vLeft.z * vRight.w); return(new Quaternion(x, y, z, w)); }
/// <summary> /// </summary> /// <param name="character"> /// </param> /// <param name="destination"> /// </param> /// <param name="heading"> /// </param> /// <param name="playfield"> /// </param> public void Teleport(Character character, Coordinate destination, IQuaternion heading, Identity playfield) { // Prevent client from entering this again if (character.DoNotDoTimers) { return; } character.DoNotDoTimers = true; // Teleport to another playfield ZoneEngine.Core.Packets.Teleport.Send(character, destination, heading, playfield); // Send packet, disconnect, and other playfield waits for connect DespawnMessage despawnMessage = ZoneEngine.Core.Packets.Despawn.Create(character.Identity); this.AnnounceOthers(despawnMessage, character.Identity); character.RawCoordinates = new Vector3() { X = destination.x, Y = destination.y, Z = destination.z }; character.RawHeading = new Quaternion(heading.xf, heading.yf, heading.zf, heading.wf); character.Save(); CharacterDao.SetPlayfield(character.Identity.Instance, (int)playfield.Type, playfield.Instance); // TODO: Get new server ip from chatengine (which has to log all zoneengine's playfields) // for now, just transmit our ip and port IPAddress tempIp; if (IPAddress.TryParse(Config.Instance.CurrentConfig.ZoneIP, out tempIp) == false) { IPHostEntry zoneHost = Dns.GetHostEntry(Config.Instance.CurrentConfig.ZoneIP); foreach (IPAddress ip in zoneHost.AddressList) { if (ip.AddressFamily == AddressFamily.InterNetwork) { tempIp = ip; break; } } } var redirect = new ZoneRedirectionMessage { ServerIpAddress = tempIp, ServerPort = (ushort)this.server.TcpEndPoint.Port }; character.Client.SendCompressed(redirect); character.DoNotDoTimers = false; // character.Client.Server.DisconnectClient(character.Client); }
/// <summary> /// </summary> /// <param name="character"> /// </param> /// <param name="destination"> /// </param> /// <param name="heading"> /// </param> /// <param name="playfield"> /// </param> /// <returns> /// </returns> public static N3TeleportMessage Create( ICharacter character, Coordinate destination, IQuaternion heading, Identity playfield) { return new N3TeleportMessage() { Identity = character.Identity, Destination = new Vector3() { X = destination.x, Y = destination.y, Z = destination.z }, Heading = new Quaternion() { X = heading.xf, Y = heading.yf, Z = heading.zf, W = heading.wf }, Unknown1 = 0x61, Playfield = new Identity() { Type = IdentityType.Playfield1, Instance = playfield.Instance }, ChangePlayfield = ((playfield.Instance != character.Playfield.Identity.Instance) || (playfield.Type != character.Playfield.Identity.Type)) ? new Identity { Type = IdentityType.Playfield2, Instance = playfield.Instance } : Identity.None, Playfield2 = new Identity { Type = IdentityType.Playfield3, Instance = playfield.Instance }, }; }
/// <summary> /// </summary> /// <param name="character"> /// </param> /// <param name="destination"> /// </param> /// <param name="heading"> /// </param> /// <param name="playfield"> /// </param> /// <returns> /// </returns> public static N3TeleportMessage Create( ICharacter character, Coordinate destination, IQuaternion heading, Identity playfield) { return(new N3TeleportMessage() { Identity = character.Identity, Destination = new Vector3() { X = destination.x, Y = destination.y, Z = destination.z }, Heading = new Quaternion() { X = heading.xf, Y = heading.yf, Z = heading.zf, W = heading.wf }, Unknown1 = 0x61, Playfield = new Identity() { Type = IdentityType.Playfield1, Instance = playfield.Instance }, ChangePlayfield = ((playfield.Instance != character.Playfield.Identity.Instance) || (playfield.Type != character.Playfield.Identity.Type)) ? new Identity { Type = IdentityType.Playfield2, Instance = playfield.Instance } : Identity.None, Playfield2 = new Identity { Type = IdentityType.Playfield3, Instance = playfield.Instance }, }); }
/// <summary> /// </summary> /// <param name="destination"> /// </param> /// <param name="heading"> /// </param> /// <param name="playfield"> /// </param> public virtual void Teleport(Coordinate destination, IQuaternion heading, Identity playfield) { // TODO: Maybe write teleport code for dynels }
/// <summary> /// Returns the Hamilton Product of two Quaternions /// </summary> /// <param name="vRight"> /// Other Quaternion /// </param> /// <returns> /// </returns> public IQuaternion Hamilton(IQuaternion vRight) { return Hamilton(this, vRight); }
/// <summary> /// Return a Vector rotated around the Quaternion /// </summary> /// <param name="q1"> /// Quaternion /// </param> /// <param name="v2"> /// Vector /// </param> /// <returns> /// </returns> public static IVector3 RotateVector3(IQuaternion q1, IVector3 v2) { Quaternion QuatVect = new Quaternion(v2.x, v2.y, v2.z, 0); Quaternion QuatNorm = (Quaternion)q1.Normalize(); Quaternion Result = Hamilton(Hamilton(QuatNorm, QuatVect), QuatNorm.Conjugate()); return new Vector3(Result.x, Result.y, Result.z); }
/// <summary> /// Return a Normalized Quaternion /// </summary> /// <param name="q1"> /// Quaternion /// </param> /// <returns> /// </returns> public static IQuaternion Normalize(IQuaternion q1) { double mag = q1.magnitude; return new Quaternion(q1.x / mag, q1.y / mag, q1.z / mag, q1.w / mag); }
/// <summary> /// </summary> /// <param name="dynel"> /// </param> /// <param name="destination"> /// </param> /// <param name="heading"> /// </param> /// <param name="playfield"> /// </param> public void Teleport(Dynel dynel, Coordinate destination, IQuaternion heading, Identity playfield) { // Prevent client from entering this again if (dynel.DoNotDoTimers) { return; } Thread.Sleep(200); int dynelId = dynel.Identity.Instance; // Disable sending stat changes and wait a bit to clear the queue dynel.DoNotDoTimers = true; Thread.Sleep(1000); // Teleport to another playfield TeleportMessageHandler.Default.Send( dynel as ICharacter, destination.coordinate, (Vector.Quaternion)heading, playfield); // Send packet, disconnect, and other playfield waits for connect DespawnMessage despawnMessage = DespawnMessageHandler.Default.Create(dynel.Identity); this.AnnounceOthers(despawnMessage, dynel.Identity); dynel.RawCoordinates = new Vector3() { X = destination.x, Y = destination.y, Z = destination.z }; dynel.RawHeading = new Vector.Quaternion(heading.xf, heading.yf, heading.zf, heading.wf); // IMPORTANT!! // Dispose the character object, save new playfield data and then recreate it // else you would end up at weird coordinates in the same playfield // Save client object ZoneClient client = (ZoneClient)dynel.Controller.Client; // Set client=null so dynel can really dispose IPlayfield newPlayfield = this.server.PlayfieldById(playfield); Pool.Instance.GetObject <Playfield>( Identity.None, new Identity() { Type = playfield.Type, Instance = playfield.Instance }); if (newPlayfield == null) { newPlayfield = new Playfield(this.server, playfield); } dynel.Playfield = newPlayfield; dynel.Controller.Client = null; dynel.Dispose(); LogUtil.Debug(DebugInfoDetail.Database, "Saving to pf " + playfield.Instance); // TODO: Get new server ip from chatengine (which has to log all zoneengine's playfields) // for now, just transmit our ip and port IPAddress tempIp; if (IPAddress.TryParse(Config.Instance.CurrentConfig.ZoneIP, out tempIp) == false) { IPHostEntry zoneHost = Dns.GetHostEntry(Config.Instance.CurrentConfig.ZoneIP); foreach (IPAddress ip in zoneHost.AddressList) { if (ip.AddressFamily == AddressFamily.InterNetwork) { tempIp = ip; break; } } } var redirect = new ZoneRedirectionMessage { ServerIpAddress = tempIp, ServerPort = (ushort)this.server.TcpEndPoint.Port }; if (client != null) { client.SendCompressed(redirect); } // client.Server.DisconnectClient(client); }
/// <summary> /// </summary> /// <param name="destination"> /// </param> /// <param name="heading"> /// </param> /// <param name="playfield"> /// </param> public override void Teleport(Coordinate destination, IQuaternion heading, Identity playfield) { this.Playfield.Teleport(this, destination, heading, playfield); }
/// <summary> /// Return a Normalized Quaternion /// </summary> /// <param name="q1"> /// Quaternion /// </param> /// <returns> /// </returns> public static IQuaternion Normalize(IQuaternion q1) { double mag = q1.magnitude; return(new Quaternion(q1.x / mag, q1.y / mag, q1.z / mag, q1.w / mag)); }
/// <summary> /// Returns the Hamilton Product of two Quaternions /// </summary> /// <param name="vRight"> /// Other Quaternion /// </param> /// <returns> /// </returns> public IQuaternion Hamilton(IQuaternion vRight) { return(Hamilton(this, vRight)); }
public static IFloat Dot(IQuaternion a, IQuaternion b) { return(a.x * b.x + a.y * b.y + a.z * b.z + a.w * b.w); }
/// <summary> /// </summary> /// <param name="destination"> /// </param> /// <param name="heading"> /// </param> /// <param name="playfield"> /// </param> public override void Teleport(Coordinate destination, IQuaternion heading, Identity playfield) { this.Playfield.Teleport(this, destination, heading, playfield); }
/// <summary> /// </summary> /// <param name="character"> /// </param> /// <param name="destination"> /// </param> /// <param name="heading"> /// </param> /// <param name="playfield"> /// </param> public static void Send(ICharacter character, Coordinate destination, IQuaternion heading, Identity playfield) { // This needs to be sent immediately! character.Client.SendCompressed(Create(character, destination, heading, playfield)); }
/// <summary> /// </summary> /// <param name="destination"> /// </param> /// <param name="heading"> /// </param> /// <param name="playfield"> /// </param> public void Teleport(Coordinate destination, IQuaternion heading, Identity playfield) { this.IsTeleporting = false; this.Playfield.Teleport(this, destination, heading, playfield); }
public void FromEuler(Vector3 euler) { quaternion = factory.FromEuler(euler); Debug.Log(dummyName + ":\t" + quaternion + "\n" + quaternion.ToEuler()); }
/// <summary> /// </summary> /// <param name="character"> /// </param> /// <param name="destination"> /// </param> /// <param name="heading"> /// </param> /// <param name="playfield"> /// </param> public static void Send(ICharacter character, Coordinate destination, IQuaternion heading, Identity playfield) { // This needs to be sent immediately! character.Client.SendCompressed(Create(character, destination, heading, playfield)); }
/// <summary> /// Returns the Hamilton Product of two Quaternions /// </summary> /// <param name="vLeft"> /// Quaternion 1 /// </param> /// <param name="vRight"> /// Quaternion 2 /// </param> /// <returns> /// </returns> public static Quaternion Hamilton(IQuaternion vLeft, IQuaternion vRight) { double w = (vLeft.w * vRight.w) - (vLeft.x * vRight.x) - (vLeft.y * vRight.y) - (vLeft.z * vRight.z); double x = (vLeft.w * vRight.x) + (vLeft.x * vRight.w) + (vLeft.y * vRight.z) - (vLeft.z * vRight.y); double y = (vLeft.w * vRight.y) - (vLeft.x * vRight.z) + (vLeft.y * vRight.w) + (vLeft.z * vRight.x); double z = (vLeft.w * vRight.z) + (vLeft.x * vRight.y) - (vLeft.y * vRight.x) + (vLeft.z * vRight.w); return new Quaternion(x, y, z, w); }
/// <summary> /// </summary> /// <param name="destination"> /// </param> /// <param name="heading"> /// </param> /// <param name="playfield"> /// </param> public void Teleport(Coordinate destination, IQuaternion heading, Identity playfield) { this.IsTeleporting = false; this.Playfield.Teleport(this, destination, heading, playfield); }
/// <summary> /// </summary> /// <param name="destination"> /// </param> /// <param name="heading"> /// </param> /// <param name="playfield"> /// </param> public virtual void Teleport(Coordinate destination, IQuaternion heading, Identity playfield) { // TODO: Maybe write teleport code for dynels }