/// <summary> /// Builds an AgentUpdate packet entirely from parameters. This /// will not touch the state of Self.Movement or /// Self.Movement.Camera in any way /// </summary> /// <param name="controlFlags"></param> /// <param name="position"></param> /// <param name="forwardAxis"></param> /// <param name="leftAxis"></param> /// <param name="upAxis"></param> /// <param name="bodyRotation"></param> /// <param name="headRotation"></param> /// <param name="farClip"></param> /// <param name="reliable"></param> /// <param name="flags"></param> /// <param name="state"></param> public void SendManualUpdate(AgentManager.ControlFlags controlFlags, Vector3 position, Vector3 forwardAxis, Vector3 leftAxis, Vector3 upAxis, Quaternion bodyRotation, Quaternion headRotation, float farClip, AgentFlags flags, AgentState state, bool reliable) { // Since version 1.40.4 of the Linden simulator, sending this update // causes corruption of the agent position in the simulator if (Client.Network.CurrentSim != null && (!Client.Network.CurrentSim.HandshakeComplete)) { return; } AgentUpdatePacket update = new AgentUpdatePacket(); update.AgentData.AgentID = Client.Self.AgentID; update.AgentData.SessionID = Client.Self.SessionID; update.AgentData.BodyRotation = bodyRotation; update.AgentData.HeadRotation = headRotation; update.AgentData.CameraCenter = position; update.AgentData.CameraAtAxis = forwardAxis; update.AgentData.CameraLeftAxis = leftAxis; update.AgentData.CameraUpAxis = upAxis; update.AgentData.Far = farClip; update.AgentData.ControlFlags = (uint)controlFlags; update.AgentData.Flags = (byte)flags; update.AgentData.State = (byte)state; update.Header.Reliable = reliable; Client.Network.SendPacket(update); }
/// <summary> /// /// </summary> /// <param name="reliable"></param> public void UpdateCamera(bool reliable) { AgentUpdatePacket update = new AgentUpdatePacket(); update.AgentData.AgentID = Client.Network.AgentID; update.AgentData.SessionID = Client.Network.SessionID; update.AgentData.State = 0; update.AgentData.BodyRotation = new LLQuaternion(0, 0.6519076f, 0, 0); update.AgentData.HeadRotation = new LLQuaternion(); // Semi-sane default values update.AgentData.CameraCenter = new LLVector3(9.549901f, 7.033957f, 11.75f); update.AgentData.CameraAtAxis = new LLVector3(0.7f, 0.7f, 0); update.AgentData.CameraLeftAxis = new LLVector3(-0.7f, 0.7f, 0); update.AgentData.CameraUpAxis = new LLVector3(0.1822026f, 0.9828722f, 0); update.AgentData.Far = 384; update.AgentData.ControlFlags = 0; update.AgentData.Flags = 0; update.Header.Reliable = reliable; Client.Network.SendPacket(update); // Send an AgentFOV packet widening our field of vision /*AgentFOVPacket fovPacket = new AgentFOVPacket(); * fovPacket.AgentData.AgentID = this.ID; * fovPacket.AgentData.SessionID = Client.Network.SessionID; * fovPacket.AgentData.CircuitCode = simulator.CircuitCode; * fovPacket.FOVBlock.GenCounter = 0; * fovPacket.FOVBlock.VerticalAngle = 6.28318531f; * fovPacket.Header.Reliable = true; * Client.Network.SendPacket((Packet)fovPacket);*/ }
private Packet mProxy_AgentUpdatePacketReceived(Packet p, IPEndPoint ep) { AgentUpdatePacket packet = p as AgentUpdatePacket; mLastUpdatePacket = DateTime.UtcNow; //Console.WriteLine("Recieved agent update packet. " + mLastUpdatePacket); /*Vector3 pos = packet.AgentData.CameraCenter; * * if (mFrame.Core.ControlMode == ControlMode.Absolute) { * //new Thread(() => { * if (mViewerConfig.CheckForPause) { * string key = MakeKey(pos); * lock (mUnackedUpdates) { * if (mUnackedUpdates.ContainsKey(key)) * mUnackedUpdates.Remove(key); * } * * CheckForPause(); * } * //}).Start(); * } * * if (pPositionChanged != null) * pPositionChanged(pos, new Rotation(packet.AgentData.CameraAtAxis));*/ agentUpdatePacketQueue.Add(packet); return(p); }
/// <summary> /// Send new AgentUpdate packet to update our current camera /// position and rotation /// </summary> /// <param name="reliable">Whether to require server acknowledgement /// of this packet</param> /// <param name="simulator">Simulator to send the update to</param> public void SendUpdate(bool reliable, Simulator simulator) { LLVector3 origin = Camera.Position; LLVector3 xAxis = Camera.LeftAxis; LLVector3 yAxis = Camera.AtAxis; LLVector3 zAxis = Camera.UpAxis; // Attempted to sort these in a rough order of how often they might change if (agentControls == 0 && yAxis == LastCameraYAxis && origin == LastCameraCenter && State == lastState && HeadRotation == LastHeadRotation && BodyRotation == LastBodyRotation && xAxis == LastCameraXAxis && Camera.Far == LastFar && zAxis == LastCameraZAxis) { ++duplicateCount; } else { duplicateCount = 0; } if (Client.Settings.CONTINUOUS_AGENT_UPDATES || duplicateCount < 10) { // Store the current state to do duplicate checking in the future LastHeadRotation = HeadRotation; LastBodyRotation = BodyRotation; LastCameraYAxis = yAxis; LastCameraCenter = origin; LastCameraXAxis = xAxis; LastCameraZAxis = zAxis; LastFar = Camera.Far; lastState = State; // Build the AgentUpdate packet and send it AgentUpdatePacket update = new AgentUpdatePacket(); update.Header.Reliable = reliable; update.AgentData.AgentID = Client.Self.AgentID; update.AgentData.SessionID = Client.Self.SessionID; update.AgentData.HeadRotation = HeadRotation; update.AgentData.BodyRotation = BodyRotation; update.AgentData.CameraAtAxis = yAxis; update.AgentData.CameraCenter = origin; update.AgentData.CameraLeftAxis = xAxis; update.AgentData.CameraUpAxis = zAxis; update.AgentData.Far = Camera.Far; update.AgentData.State = (byte)State; update.AgentData.ControlFlags = agentControls; update.AgentData.Flags = (byte)Flags; Client.Network.SendPacket(update, simulator); ResetControlFlags(); } }
void AgentUpdateHandler(Packet packet, Agent agent) { AgentUpdatePacket update = (AgentUpdatePacket)packet; agent.Avatar.Rotation = update.AgentData.BodyRotation; agent.ControlFlags = (AgentManager.ControlFlags)update.AgentData.ControlFlags; agent.State = update.AgentData.State; agent.Flags = (PrimFlags)update.AgentData.Flags; ObjectUpdatePacket fullUpdate = SimulationObject.BuildFullUpdate(agent.Avatar, server.RegionHandle, agent.State, agent.Flags); server.UDP.BroadcastPacket(fullUpdate, PacketCategory.State); }
void SendAgentUpdate(SecondLife client, uint ControlID) { AgentUpdatePacket p = new AgentUpdatePacket(); p.AgentData.Far = DRAW_DISTANCE; //LLVector3 myPos = client.Self.Position; p.AgentData.CameraCenter = new LLVector3(0, 0, 0); p.AgentData.CameraAtAxis = new LLVector3(0, 0, 0); p.AgentData.CameraLeftAxis = new LLVector3(0, 0, 0); p.AgentData.CameraUpAxis = new LLVector3(0, 0, 0); p.AgentData.HeadRotation = new LLQuaternion(0, 0, 0, 1); ; p.AgentData.BodyRotation = new LLQuaternion(0, 0, 0, 1); ; p.AgentData.AgentID = client.Network.AgentID; p.AgentData.SessionID = client.Network.SessionID; p.AgentData.ControlFlags = ControlID; client.Network.SendPacket(p); }
/// <summary> /// Send new AgentUpdate /// </summary> public void SendUpdate() { AgentUpdatePacket update = new AgentUpdatePacket(); update.AgentData.AgentID = Client.Network.AgentID; update.AgentData.SessionID = Client.Network.SessionID; update.AgentData.HeadRotation = Camera.HeadRotation; update.AgentData.BodyRotation = Camera.BodyRotation; update.AgentData.CameraAtAxis = Camera.CameraAtAxis; update.AgentData.CameraCenter = Camera.CameraCenter; update.AgentData.CameraLeftAxis = Camera.CameraLeftAxis; update.AgentData.CameraUpAxis = Camera.CameraUpAxis; update.AgentData.ControlFlags = agentControls; update.AgentData.Far = Camera.Far; Client.Network.SendPacket(update); }
public void SitNow() { plugin.SendUserAlert("Activated Sit"); AgentUpdatePacket a = new AgentUpdatePacket(); a.Type = PacketType.AgentUpdate; a.AgentData = new AgentUpdatePacket.AgentDataBlock(); a.AgentData.AgentID = frame.AgentID; a.AgentData.BodyRotation = Quaternion.Identity; a.AgentData.CameraAtAxis = shared.CameraAtAxis; a.AgentData.CameraCenter = shared.CameraPosition; a.AgentData.CameraLeftAxis = shared.CameraLeftAxis; a.AgentData.CameraUpAxis = shared.CameraUpAxis; a.AgentData.ControlFlags = 131072; a.AgentData.Far = shared.Far; a.AgentData.Flags = 0; a.AgentData.HeadRotation = Quaternion.Identity; a.AgentData.SessionID = frame.SessionID; a.AgentData.State = 0; proxy.InjectPacket(a, Direction.Outgoing); }
/// <summary> /// Builds an AgentUpdate packet entirely from parameters. This /// will not touch the state of Self.Movement or /// Self.Movement.Camera in any way /// </summary> /// <param name="controlFlags"></param> /// <param name="position"></param> /// <param name="forwardAxis"></param> /// <param name="leftAxis"></param> /// <param name="upAxis"></param> /// <param name="bodyRotation"></param> /// <param name="headRotation"></param> /// <param name="farClip"></param> /// <param name="reliable"></param> /// <param name="flags"></param> /// <param name="state"></param> public void SendManualUpdate(AgentManager.ControlFlags controlFlags, Vector3 position, Vector3 forwardAxis, Vector3 leftAxis, Vector3 upAxis, Quaternion bodyRotation, Quaternion headRotation, float farClip, AgentFlags flags, AgentState state, bool reliable) { AgentUpdatePacket update = new AgentUpdatePacket(); update.AgentData.AgentID = Client.Self.AgentID; update.AgentData.SessionID = Client.Self.SessionID; update.AgentData.BodyRotation = bodyRotation; update.AgentData.HeadRotation = headRotation; update.AgentData.CameraCenter = position; update.AgentData.CameraAtAxis = forwardAxis; update.AgentData.CameraLeftAxis = leftAxis; update.AgentData.CameraUpAxis = upAxis; update.AgentData.Far = farClip; update.AgentData.ControlFlags = (uint)controlFlags; update.AgentData.Flags = (byte)flags; update.AgentData.State = (byte)state; update.Header.Reliable = reliable; Client.Network.SendPacket(update); }
public void HandleUpdate(AgentUpdatePacket pack) { if (((uint)pack.AgentData.ControlFlags & (uint)MainAvatar.ControlFlags.AGENT_CONTROL_FLY) != 0) { if (this._physActor.Flying == false) { this.current_anim = Animations.AnimsLLUUID["ANIM_AGENT_FLY"]; this.anim_seq = 1; this.SendAnimPack(); } this._physActor.Flying = true; } else { if (this._physActor.Flying == true) { this.current_anim = Animations.AnimsLLUUID["ANIM_AGENT_STAND"]; this.anim_seq = 1; this.SendAnimPack(); } this._physActor.Flying = false; } if (((uint)pack.AgentData.ControlFlags & (uint)MainAvatar.ControlFlags.AGENT_CONTROL_AT_POS) != 0) { Axiom.MathLib.Quaternion q = new Axiom.MathLib.Quaternion(pack.AgentData.BodyRotation.W, pack.AgentData.BodyRotation.X, pack.AgentData.BodyRotation.Y, pack.AgentData.BodyRotation.Z); if (((movementflag & 1) == 0) || (q != this.bodyRot)) { if (((movementflag & 1) == 0) && (!this._physActor.Flying)) { this.current_anim = Animations.AnimsLLUUID["ANIM_AGENT_WALK"]; this.anim_seq = 1; this.SendAnimPack(); } //we should add a new force to the list // but for now we will deal with velocities NewForce newVelocity = new NewForce(); Axiom.MathLib.Vector3 v3 = new Axiom.MathLib.Vector3(1, 0, 0); Axiom.MathLib.Vector3 direc = q * v3; direc.Normalize(); //work out velocity for sim physics system direc = direc * ((0.03f) * 128f); if (this._physActor.Flying) { direc *= 2; } newVelocity.X = direc.x; newVelocity.Y = direc.y; newVelocity.Z = direc.z; this.forcesList.Add(newVelocity); movementflag = 1; this.bodyRot = q; } } else if ((((uint)pack.AgentData.ControlFlags & (uint)MainAvatar.ControlFlags.AGENT_CONTROL_UP_POS) != 0) && (PhysicsEngineFlying)) { if (((movementflag & 2) == 0) && this._physActor.Flying) { //we should add a new force to the list // but for now we will deal with velocities NewForce newVelocity = new NewForce(); Axiom.MathLib.Vector3 v3 = new Axiom.MathLib.Vector3(0, 0, 1); Axiom.MathLib.Vector3 direc = v3; direc.Normalize(); //work out velocity for sim physics system direc = direc * ((0.03f) * 128f * 2); newVelocity.X = direc.x; newVelocity.Y = direc.y; newVelocity.Z = direc.z; this.forcesList.Add(newVelocity); movementflag = 2; } } else if ((((uint)pack.AgentData.ControlFlags & (uint)MainAvatar.ControlFlags.AGENT_CONTROL_UP_NEG) != 0) && (PhysicsEngineFlying)) { if (((movementflag & 4) == 0) && this._physActor.Flying) { //we should add a new force to the list // but for now we will deal with velocities NewForce newVelocity = new NewForce(); Axiom.MathLib.Vector3 v3 = new Axiom.MathLib.Vector3(0, 0, -1); //Axiom.MathLib.Quaternion q = new Axiom.MathLib.Quaternion(pack.AgentData.BodyRotation.W, pack.AgentData.BodyRotation.X, pack.AgentData.BodyRotation.Y, pack.AgentData.BodyRotation.Z); Axiom.MathLib.Vector3 direc = v3; direc.Normalize(); //work out velocity for sim physics system direc = direc * ((0.03f) * 128f * 2); newVelocity.X = direc.x; newVelocity.Y = direc.y; newVelocity.Z = direc.z; this.forcesList.Add(newVelocity); movementflag = 4; } } else if (((uint)pack.AgentData.ControlFlags & (uint)MainAvatar.ControlFlags.AGENT_CONTROL_AT_NEG) != 0) { Axiom.MathLib.Quaternion q = new Axiom.MathLib.Quaternion(pack.AgentData.BodyRotation.W, pack.AgentData.BodyRotation.X, pack.AgentData.BodyRotation.Y, pack.AgentData.BodyRotation.Z); if (((movementflag & 8) == 0) || (q != this.bodyRot)) { //we should add a new force to the list // but for now we will deal with velocities NewForce newVelocity = new NewForce(); Axiom.MathLib.Vector3 v3 = new Axiom.MathLib.Vector3(-1, 0, 0); Axiom.MathLib.Vector3 direc = q * v3; direc.Normalize(); //work out velocity for sim physics system direc = direc * ((0.03f) * 128f); if (this._physActor.Flying) { direc *= 2; } newVelocity.X = direc.x; newVelocity.Y = direc.y; newVelocity.Z = direc.z; this.forcesList.Add(newVelocity); movementflag = 8; this.bodyRot = q; } } else { if (movementflag == 16) { movementflag = 0; } if ((movementflag) != 0) { NewForce newVelocity = new NewForce(); newVelocity.X = 0; newVelocity.Y = 0; newVelocity.Z = 0; this.forcesList.Add(newVelocity); movementflag = 0; // We're standing still, so make it show! if (this._physActor.Flying == false) { this.current_anim = Animations.AnimsLLUUID["ANIM_AGENT_STAND"]; this.anim_seq = 1; this.SendAnimPack(); } this.movementflag = 16; } } }
/// <summary> /// Send new AgentUpdate packet to update our current camera /// position and rotation /// </summary> /// <param name="reliable">Whether to require server acknowledgement /// of this packet</param> /// <param name="simulator">Simulator to send the update to</param> public void SendUpdate(bool reliable, Simulator simulator) { // Since version 1.40.4 of the Linden simulator, sending this update // causes corruption of the agent position in the simulator if (simulator != null && (!simulator.AgentMovementComplete)) { return; } Vector3 origin = Camera.Position; Vector3 xAxis = Camera.LeftAxis; Vector3 yAxis = Camera.AtAxis; Vector3 zAxis = Camera.UpAxis; // Attempted to sort these in a rough order of how often they might change if (agentControls == 0 && yAxis == LastCameraYAxis && origin == LastCameraCenter && State == lastState && HeadRotation == LastHeadRotation && BodyRotation == LastBodyRotation && xAxis == LastCameraXAxis && Camera.Far == LastFar && zAxis == LastCameraZAxis) { ++duplicateCount; } else { duplicateCount = 0; } if (Client.Settings.DISABLE_AGENT_UPDATE_DUPLICATE_CHECK || duplicateCount < 10) { // Store the current state to do duplicate checking LastHeadRotation = HeadRotation; LastBodyRotation = BodyRotation; LastCameraYAxis = yAxis; LastCameraCenter = origin; LastCameraXAxis = xAxis; LastCameraZAxis = zAxis; LastFar = Camera.Far; lastState = State; // Build the AgentUpdate packet and send it AgentUpdatePacket update = new AgentUpdatePacket(); update.Header.Reliable = reliable; update.AgentData.AgentID = Client.Self.AgentID; update.AgentData.SessionID = Client.Self.SessionID; update.AgentData.HeadRotation = HeadRotation; update.AgentData.BodyRotation = BodyRotation; update.AgentData.CameraAtAxis = xAxis; update.AgentData.CameraCenter = origin; update.AgentData.CameraLeftAxis = yAxis; update.AgentData.CameraUpAxis = zAxis; update.AgentData.Far = Camera.Far; update.AgentData.State = (byte)State; update.AgentData.ControlFlags = agentControls; update.AgentData.Flags = (byte)Flags; Client.Network.SendPacket(update, simulator); if (autoResetControls) { ResetControlFlags(); } } }
/// <summary> /// /// </summary> /// <param name="reliable"></param> public void UpdateCamera(bool reliable) { AgentUpdatePacket update = new AgentUpdatePacket(); update.AgentData.AgentID = Client.Network.AgentID; update.AgentData.SessionID = Client.Network.SessionID; update.AgentData.State = 0; update.AgentData.BodyRotation = new LLQuaternion(0, 0.6519076f, 0, 0); update.AgentData.HeadRotation = new LLQuaternion(); // Semi-sane default values update.AgentData.CameraCenter = new LLVector3(9.549901f, 7.033957f, 11.75f); update.AgentData.CameraAtAxis = new LLVector3(0.7f, 0.7f, 0); update.AgentData.CameraLeftAxis = new LLVector3(-0.7f, 0.7f, 0); update.AgentData.CameraUpAxis = new LLVector3(0.1822026f, 0.9828722f, 0); update.AgentData.Far = 384; update.AgentData.ControlFlags = 0; update.AgentData.Flags = 0; update.Header.Reliable = reliable; Client.Network.SendPacket(update); // Send an AgentFOV packet widening our field of vision /*AgentFOVPacket fovPacket = new AgentFOVPacket(); fovPacket.AgentData.AgentID = this.ID; fovPacket.AgentData.SessionID = Client.Network.SessionID; fovPacket.AgentData.CircuitCode = simulator.CircuitCode; fovPacket.FOVBlock.GenCounter = 0; fovPacket.FOVBlock.VerticalAngle = 6.28318531f; fovPacket.Header.Reliable = true; Client.Network.SendPacket((Packet)fovPacket);*/ }
/// <summary> /// Send new AgentUpdate packet to update our current camera /// position and rotation /// </summary> /// <param name="reliable">Whether to require server acknowledgement /// of this packet</param> /// <param name="simulator">Simulator to send the update to</param> public void SendUpdate(bool reliable, Simulator simulator) { Vector3 origin = Camera.Position; Vector3 xAxis = Camera.LeftAxis; Vector3 yAxis = Camera.AtAxis; Vector3 zAxis = Camera.UpAxis; // Attempted to sort these in a rough order of how often they might change if (agentControls == 0 && yAxis == LastCameraYAxis && origin == LastCameraCenter && State == lastState && HeadRotation == LastHeadRotation && BodyRotation == LastBodyRotation && xAxis == LastCameraXAxis && Camera.Far == LastFar && zAxis == LastCameraZAxis) { ++duplicateCount; } else { duplicateCount = 0; } if (Self.DisableAgentUpdateDuplicateCheck || duplicateCount < 10) { // Store the current state to do duplicate checking LastHeadRotation = HeadRotation; LastBodyRotation = BodyRotation; LastCameraYAxis = yAxis; LastCameraCenter = origin; LastCameraXAxis = xAxis; LastCameraZAxis = zAxis; LastFar = Camera.Far; lastState = State; // Build the AgentUpdate packet and send it AgentUpdatePacket update = new AgentUpdatePacket(); update.Header.Reliable = reliable; update.AgentData.AgentID = Network.AgentID; update.AgentData.SessionID = Network.SessionID; update.AgentData.HeadRotation = HeadRotation; update.AgentData.BodyRotation = BodyRotation; update.AgentData.CameraAtAxis = yAxis; update.AgentData.CameraCenter = origin; update.AgentData.CameraLeftAxis = xAxis; update.AgentData.CameraUpAxis = zAxis; update.AgentData.Far = Camera.Far; update.AgentData.State = (byte)State; update.AgentData.ControlFlags = agentControls; update.AgentData.Flags = (byte)Flags; Network.SendPacket(update, simulator); if (autoResetControls) { ResetControlFlags(); } } }
/// <summary> /// Send new AgentUpdate packet to update our current camera /// position and rotation /// </summary> /// <param name="reliable">Whether to require server acknowledgement /// of this packet</param> /// <param name="simulator">Simulator to send the update to</param> public void SendUpdate(bool reliable, Simulator simulator) { // Since version 1.40.4 of the Linden simulator, sending this update // causes corruption of the agent position in the simulator if (simulator != null && (!simulator.HandshakeComplete)) return; Vector3 origin = Camera.Position; Vector3 xAxis = Camera.LeftAxis; Vector3 yAxis = Camera.AtAxis; Vector3 zAxis = Camera.UpAxis; // Attempted to sort these in a rough order of how often they might change if (agentControls == 0 && yAxis == LastCameraYAxis && origin == LastCameraCenter && State == lastState && HeadRotation == LastHeadRotation && BodyRotation == LastBodyRotation && xAxis == LastCameraXAxis && Camera.Far == LastFar && zAxis == LastCameraZAxis) { ++duplicateCount; } else { duplicateCount = 0; } if (Client.Settings.DISABLE_AGENT_UPDATE_DUPLICATE_CHECK || duplicateCount < 10) { // Store the current state to do duplicate checking LastHeadRotation = HeadRotation; LastBodyRotation = BodyRotation; LastCameraYAxis = yAxis; LastCameraCenter = origin; LastCameraXAxis = xAxis; LastCameraZAxis = zAxis; LastFar = Camera.Far; lastState = State; // Build the AgentUpdate packet and send it AgentUpdatePacket update = new AgentUpdatePacket(); update.Header.Reliable = reliable; update.AgentData.AgentID = Client.Self.AgentID; update.AgentData.SessionID = Client.Self.SessionID; update.AgentData.HeadRotation = HeadRotation; update.AgentData.BodyRotation = BodyRotation; update.AgentData.CameraAtAxis = yAxis; update.AgentData.CameraCenter = origin; update.AgentData.CameraLeftAxis = xAxis; update.AgentData.CameraUpAxis = zAxis; update.AgentData.Far = Camera.Far; update.AgentData.State = (byte)State; update.AgentData.ControlFlags = agentControls; update.AgentData.Flags = (byte)Flags; Client.Network.SendPacket(update, simulator); if (autoResetControls) { ResetControlFlags(); } } }
private void AgentUpdateHandler(Packet packet, LLAgent agent) { AgentUpdatePacket update = (AgentUpdatePacket)packet; // Update rotation if the agent is not sitting on anything if (agent.Parent == null) { agent.RelativeRotation = update.AgentData.BodyRotation; } agent.CameraPosition = update.AgentData.CameraCenter; agent.CameraAtAxis = update.AgentData.CameraAtAxis; agent.CameraLeftAxis = update.AgentData.CameraLeftAxis; agent.CameraUpAxis = update.AgentData.CameraUpAxis; agent.DrawDistance = update.AgentData.Far; agent.ControlFlags = (AgentManager.ControlFlags)update.AgentData.ControlFlags; agent.State = (AgentState)update.AgentData.State; agent.HideTitle = update.AgentData.Flags != 0; #region Standing ILinkable parent = agent.Parent; if (parent != null && (agent.ControlFlags & AgentManager.ControlFlags.AGENT_CONTROL_STAND_UP) == AgentManager.ControlFlags.AGENT_CONTROL_STAND_UP) { agent.SetParent(null, true, true); agent.RelativePosition = parent.ScenePosition + Vector3.Transform(agent.SitPosition, Matrix4.CreateFromQuaternion(agent.SitRotation)) + Vector3.UnitZ; agent.Animations.ResetDefaultAnimation(); m_scene.SendPresenceAnimations(this, agent); agent.CollisionsEnabled = true; agent.DynamicsEnabled = true; m_scene.EntityAddOrUpdate(this, agent, UpdateFlags.Position | UpdateFlags.Rotation, (uint)LLUpdateFlags.PrimFlags); return; } #endregion Standing #region Inputs // Create forward and left vectors from the current avatar rotation Matrix4 rotMatrix = Matrix4.CreateFromQuaternion(agent.RelativeRotation); Vector3 fwd = Vector3.Transform(Vector3.UnitX, rotMatrix); Vector3 left = Vector3.Transform(Vector3.UnitY, rotMatrix); // Check control flags bool heldForward = (agent.ControlFlags & AgentManager.ControlFlags.AGENT_CONTROL_AT_POS) == AgentManager.ControlFlags.AGENT_CONTROL_AT_POS; bool heldBack = (agent.ControlFlags & AgentManager.ControlFlags.AGENT_CONTROL_AT_NEG) == AgentManager.ControlFlags.AGENT_CONTROL_AT_NEG; bool heldLeft = (agent.ControlFlags & AgentManager.ControlFlags.AGENT_CONTROL_LEFT_POS) == AgentManager.ControlFlags.AGENT_CONTROL_LEFT_POS; bool heldRight = (agent.ControlFlags & AgentManager.ControlFlags.AGENT_CONTROL_LEFT_NEG) == AgentManager.ControlFlags.AGENT_CONTROL_LEFT_NEG; //bool heldTurnLeft = (agent.ControlFlags & AgentManager.ControlFlags.AGENT_CONTROL_TURN_LEFT) == AgentManager.ControlFlags.AGENT_CONTROL_TURN_LEFT; //bool heldTurnRight = (agent.ControlFlags & AgentManager.ControlFlags.AGENT_CONTROL_TURN_RIGHT) == AgentManager.ControlFlags.AGENT_CONTROL_TURN_RIGHT; bool heldUp = (agent.ControlFlags & AgentManager.ControlFlags.AGENT_CONTROL_UP_POS) == AgentManager.ControlFlags.AGENT_CONTROL_UP_POS; bool heldDown = (agent.ControlFlags & AgentManager.ControlFlags.AGENT_CONTROL_UP_NEG) == AgentManager.ControlFlags.AGENT_CONTROL_UP_NEG; bool flying = (agent.ControlFlags & AgentManager.ControlFlags.AGENT_CONTROL_FLY) == AgentManager.ControlFlags.AGENT_CONTROL_FLY; //bool mouselook = (agent.ControlFlags & AgentManager.ControlFlags.AGENT_CONTROL_MOUSELOOK) == AgentManager.ControlFlags.AGENT_CONTROL_MOUSELOOK; bool nudgeForward = (agent.ControlFlags & AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_AT_POS) == AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_AT_POS; bool nudgeBack = (agent.ControlFlags & AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_AT_NEG) == AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_AT_NEG; bool nudgeLeft = (agent.ControlFlags & AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_LEFT_POS) == AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_LEFT_POS; bool nudgeRight = (agent.ControlFlags & AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_LEFT_NEG) == AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_LEFT_NEG; bool nudgeUp = (agent.ControlFlags & AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_UP_POS) == AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_UP_POS; bool nudgeDown = (agent.ControlFlags & AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_UP_NEG) == AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_UP_NEG; // direction in which the avatar is trying to move Vector3 move = Vector3.Zero; if (heldForward) { move.X += fwd.X; move.Y += fwd.Y; } else if (nudgeForward) { move.X += fwd.X * 0.5f; move.Y += fwd.Y * 0.5f; } if (heldBack) { move.X -= fwd.X; move.Y -= fwd.Y; } else if (nudgeBack) { move.X -= fwd.X * 0.5f; move.Y -= fwd.Y * 0.5f; } if (heldLeft) { move.X += left.X; move.Y += left.Y; } else if (nudgeLeft) { move.X += left.X * 0.5f; move.Y += left.Y * 0.5f; } if (heldRight) { move.X -= left.X; move.Y -= left.Y; } else if (nudgeRight) { move.X -= left.X * 0.5f; move.Y -= left.Y * 0.5f; } if (heldUp) { move.Z += 1f; } else if (nudgeUp) { move.Z += 0.5f; } if (heldDown) { move.Z -= 1f; } else if (nudgeDown) { move.Z -= 0.5f; } bool jumping = agent.JumpStart != 0; float speed = (flying ? FLY_SPEED : agent.IsRunning && !jumping ? RUN_SPEED : WALK_SPEED); if ((heldForward || heldBack) && (heldLeft || heldRight)) { speed /= SQRT_TWO; } #endregion Inputs agent.InputVelocity = move * speed; agent.LastMovementState = agent.MovementState; agent.MovementState = (flying ? MovementState.Flying : agent.IsRunning && !jumping ? MovementState.Running : MovementState.Walking); }
/// <summary> /// Send new AgentUpdate packet to update our current camera /// position and rotation /// </summary> /// <param name="reliable">Whether to require server acknowledgement /// of this packet</param> /// <param name="simulator">Simulator to send the update to</param> public void SendUpdate(bool reliable, Simulator simulator) { // Attempted to sort these in a rough order of how often they might change if (agentControls == 0 && Camera.CameraAtAxis == Camera.LastCameraAtAxis && Camera.CameraCenter == Camera.LastCameraCenter && State != lastState && Camera.HeadRotation == Camera.LastHeadRotation && Camera.BodyRotation == Camera.LastBodyRotation && Camera.CameraLeftAxis == Camera.LastCameraLeftAxis && Camera.Far == Camera.LastFar && Camera.CameraUpAxis == Camera.LastCameraUpAxis) { ++duplicateCount; } else { duplicateCount = 0; } if (duplicateCount < 2) { // Store the current state to do duplicate checking in the future Camera.LastHeadRotation = Camera.HeadRotation; Camera.LastBodyRotation = Camera.BodyRotation; Camera.LastCameraAtAxis = Camera.CameraAtAxis; Camera.LastCameraCenter = Camera.CameraCenter; Camera.LastCameraLeftAxis = Camera.CameraLeftAxis; Camera.LastCameraUpAxis = Camera.CameraUpAxis; Camera.LastFar = Camera.Far; lastState = State; // Build the AgentUpdate packet and send it AgentUpdatePacket update = new AgentUpdatePacket(); update.Header.Reliable = reliable; update.AgentData.AgentID = Client.Network.AgentID; update.AgentData.SessionID = Client.Network.SessionID; update.AgentData.HeadRotation = Camera.HeadRotation; update.AgentData.BodyRotation = Camera.BodyRotation; update.AgentData.CameraAtAxis = Camera.CameraAtAxis; update.AgentData.CameraCenter = Camera.CameraCenter; update.AgentData.CameraLeftAxis = Camera.CameraLeftAxis; update.AgentData.CameraUpAxis = Camera.CameraUpAxis; update.AgentData.Far = Camera.Far; update.AgentData.State = (byte)State; update.AgentData.ControlFlags = agentControls; update.AgentData.Flags = (byte)Flags; Client.Network.SendPacket(update, simulator); } }
public void HandleUpdate(AgentUpdatePacket pack) { if (((uint)pack.AgentData.ControlFlags & (uint)MainAvatar.ControlFlags.AGENT_CONTROL_FLY) != 0) { if (this._physActor.Flying == false) { this.current_anim = Animations.AnimsLLUUID["ANIM_AGENT_FLY"]; this.anim_seq = 1; this.SendAnimPack(); } this._physActor.Flying = true; } else { if (this._physActor.Flying == true) { this.current_anim = Animations.AnimsLLUUID["ANIM_AGENT_STAND"]; this.anim_seq = 1; this.SendAnimPack(); } this._physActor.Flying = false; } if (((uint)pack.AgentData.ControlFlags & (uint)MainAvatar.ControlFlags.AGENT_CONTROL_AT_POS) != 0) { Axiom.MathLib.Quaternion q = new Axiom.MathLib.Quaternion(pack.AgentData.BodyRotation.W, pack.AgentData.BodyRotation.X, pack.AgentData.BodyRotation.Y, pack.AgentData.BodyRotation.Z); if (((movementflag & 1) == 0) || (q != this.bodyRot)) { if (((movementflag & 1) == 0) && (!this._physActor.Flying)) { this.current_anim = Animations.AnimsLLUUID["ANIM_AGENT_WALK"]; this.anim_seq = 1; this.SendAnimPack(); } //we should add a new force to the list // but for now we will deal with velocities NewForce newVelocity = new NewForce(); Axiom.MathLib.Vector3 v3 = new Axiom.MathLib.Vector3(1, 0, 0); Axiom.MathLib.Vector3 direc = q * v3; direc.Normalize(); //work out velocity for sim physics system direc = direc * ((0.03f) * 128f); if (this._physActor.Flying) direc *= 2; newVelocity.X = direc.x; newVelocity.Y = direc.y; newVelocity.Z = direc.z; this.forcesList.Add(newVelocity); movementflag = 1; this.bodyRot = q; } } else if ((((uint)pack.AgentData.ControlFlags & (uint)MainAvatar.ControlFlags.AGENT_CONTROL_UP_POS) != 0) && (PhysicsEngineFlying)) { if (((movementflag & 2) == 0) && this._physActor.Flying) { //we should add a new force to the list // but for now we will deal with velocities NewForce newVelocity = new NewForce(); Axiom.MathLib.Vector3 v3 = new Axiom.MathLib.Vector3(0, 0, 1); Axiom.MathLib.Vector3 direc = v3; direc.Normalize(); //work out velocity for sim physics system direc = direc * ((0.03f) * 128f * 2); newVelocity.X = direc.x; newVelocity.Y = direc.y; newVelocity.Z = direc.z; this.forcesList.Add(newVelocity); movementflag = 2; } } else if ((((uint)pack.AgentData.ControlFlags & (uint)MainAvatar.ControlFlags.AGENT_CONTROL_UP_NEG) != 0) && (PhysicsEngineFlying)) { if (((movementflag & 4) == 0) && this._physActor.Flying) { //we should add a new force to the list // but for now we will deal with velocities NewForce newVelocity = new NewForce(); Axiom.MathLib.Vector3 v3 = new Axiom.MathLib.Vector3(0, 0, -1); //Axiom.MathLib.Quaternion q = new Axiom.MathLib.Quaternion(pack.AgentData.BodyRotation.W, pack.AgentData.BodyRotation.X, pack.AgentData.BodyRotation.Y, pack.AgentData.BodyRotation.Z); Axiom.MathLib.Vector3 direc = v3; direc.Normalize(); //work out velocity for sim physics system direc = direc * ((0.03f) * 128f * 2); newVelocity.X = direc.x; newVelocity.Y = direc.y; newVelocity.Z = direc.z; this.forcesList.Add(newVelocity); movementflag = 4; } } else if (((uint)pack.AgentData.ControlFlags & (uint)MainAvatar.ControlFlags.AGENT_CONTROL_AT_NEG) != 0) { Axiom.MathLib.Quaternion q = new Axiom.MathLib.Quaternion(pack.AgentData.BodyRotation.W, pack.AgentData.BodyRotation.X, pack.AgentData.BodyRotation.Y, pack.AgentData.BodyRotation.Z); if (((movementflag & 8) == 0) || (q != this.bodyRot)) { //we should add a new force to the list // but for now we will deal with velocities NewForce newVelocity = new NewForce(); Axiom.MathLib.Vector3 v3 = new Axiom.MathLib.Vector3(-1, 0, 0); Axiom.MathLib.Vector3 direc = q * v3; direc.Normalize(); //work out velocity for sim physics system direc = direc * ((0.03f) * 128f); if (this._physActor.Flying) direc *= 2; newVelocity.X = direc.x; newVelocity.Y = direc.y; newVelocity.Z = direc.z; this.forcesList.Add(newVelocity); movementflag = 8; this.bodyRot = q; } } else { if (movementflag == 16) { movementflag = 0; } if ((movementflag) != 0) { NewForce newVelocity = new NewForce(); newVelocity.X = 0; newVelocity.Y = 0; newVelocity.Z = 0; this.forcesList.Add(newVelocity); movementflag = 0; // We're standing still, so make it show! if (this._physActor.Flying == false) { this.current_anim = Animations.AnimsLLUUID["ANIM_AGENT_STAND"]; this.anim_seq = 1; this.SendAnimPack(); } this.movementflag = 16; } } }
/// <summary> /// Builds an AgentUpdate packet entirely from parameters. This /// will not touch the state of Self.Movement or /// Self.Movement.Camera in any way /// </summary> /// <param name="controlFlags"></param> /// <param name="position"></param> /// <param name="forwardAxis"></param> /// <param name="leftAxis"></param> /// <param name="upAxis"></param> /// <param name="bodyRotation"></param> /// <param name="headRotation"></param> /// <param name="farClip"></param> /// <param name="reliable"></param> /// <param name="flags"></param> /// <param name="state"></param> public void SendManualUpdate(AgentManager.ControlFlags controlFlags, Vector3 position, Vector3 forwardAxis, Vector3 leftAxis, Vector3 upAxis, Quaternion bodyRotation, Quaternion headRotation, float farClip, AgentFlags flags, AgentState state, bool reliable) { // Since version 1.40.4 of the Linden simulator, sending this update // causes corruption of the agent position in the simulator if (Client.Network.CurrentSim != null && (!Client.Network.CurrentSim.HandshakeComplete)) return; AgentUpdatePacket update = new AgentUpdatePacket(); update.AgentData.AgentID = Client.Self.AgentID; update.AgentData.SessionID = Client.Self.SessionID; update.AgentData.BodyRotation = bodyRotation; update.AgentData.HeadRotation = headRotation; update.AgentData.CameraCenter = position; update.AgentData.CameraAtAxis = forwardAxis; update.AgentData.CameraLeftAxis = leftAxis; update.AgentData.CameraUpAxis = upAxis; update.AgentData.Far = farClip; update.AgentData.ControlFlags = (uint)controlFlags; update.AgentData.Flags = (byte)flags; update.AgentData.State = (byte)state; update.Header.Reliable = reliable; Client.Network.SendPacket(update); }
/// <summary> /// Sends camera and action updates to the server including the /// position and orientation of our camera, and a ControlFlags field /// specifying our current movement actions /// </summary> /// <param name="reliable">Whether to ensure this packet makes it to the server</param> public void UpdateCamera(Avatar.AgentUpdateFlags controlFlags, LLVector3 position, LLVector3 forwardAxis, LLVector3 leftAxis, LLVector3 upAxis, LLQuaternion bodyRotation, LLQuaternion headRotation, float farClip, bool reliable) { AgentUpdatePacket update = new AgentUpdatePacket(); update.AgentData.AgentID = Client.Network.AgentID; update.AgentData.SessionID = Client.Network.SessionID; update.AgentData.State = 0; update.AgentData.BodyRotation = bodyRotation; update.AgentData.HeadRotation = headRotation; update.AgentData.CameraCenter = position; update.AgentData.CameraAtAxis = forwardAxis; update.AgentData.CameraLeftAxis = leftAxis; update.AgentData.CameraUpAxis = upAxis; update.AgentData.Far = farClip; update.AgentData.ControlFlags = (uint)controlFlags; update.AgentData.Flags = 0; update.Header.Reliable = reliable; Client.Network.SendPacket(update); }