OpenSim.Region.Framework.Scenes.ScenePresence.AddNewMovement C# (CSharp) Method

AddNewMovement() public method

Rotate the avatar to the given rotation and apply a movement in the given relative vector
public AddNewMovement ( System.Vector3 vec, Quaternion rotation ) : void
vec System.Vector3 The vector in which to move. This is relative to the rotation argument
rotation Quaternion
return void
        public void AddNewMovement(Vector3 vec, Quaternion rotation)
        {
            if (m_isChildAgent)
            {
                // WHAT???
                m_log.Debug("[SCENEPRESENCE]: AddNewMovement() called on child agent, making root agent!");

                // we have to reset the user's child agent connections.
                // Likely, here they've lost the eventqueue for other regions so border 
                // crossings will fail at this point unless we reset them.

                List<ulong> regions = new List<ulong>(KnownChildRegionHandles);
                regions.Remove(m_scene.RegionInfo.RegionHandle);

                MakeRootAgent(new Vector3(127f, 127f, 127f), true);

                // Async command
                if (m_scene.SceneGridService != null)
                {
                    m_scene.SceneGridService.SendCloseChildAgentConnections(UUID, regions);

                    // Give the above command some time to try and close the connections.
                    // this is really an emergency..   so sleep, or we'll get all discombobulated.
                    System.Threading.Thread.Sleep(500);
                }
                
                if (m_scene.SceneGridService != null)
                {
                    IEntityTransferModule m_agentTransfer = m_scene.RequestModuleInterface<IEntityTransferModule>();
                    if (m_agentTransfer != null)
                        m_agentTransfer.EnableChildAgents(this);
                }
                
                return;
            }

            m_perfMonMS = Util.EnvironmentTickCount();

            Rotation = rotation;
            Vector3 direc = vec * rotation;
            direc.Normalize();

            direc *= 0.03f * 128f * m_speedModifier;

            PhysicsActor actor = m_physicsActor;
            if (actor != null)
            {
                if (actor.Flying)
                {
                    direc *= 4.0f;
                    //bool controlland = (((m_AgentControlFlags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_UP_NEG) != 0) || ((m_AgentControlFlags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_UP_NEG) != 0));
                    //bool colliding = (m_physicsActor.IsColliding==true);
                    //if (controlland)
                    //    m_log.Info("[AGENT]: landCommand");
                    //if (colliding)
                    //    m_log.Info("[AGENT]: colliding");
                    //if (m_physicsActor.Flying && colliding && controlland)
                    //{
                    //    StopFlying();
                    //    m_log.Info("[AGENT]: Stop FLying");
                    //}
                }
                else if (!actor.Flying && actor.IsColliding)
                {
                    if (direc.Z > 2.0f)
                    {
                        direc.Z *= 3.0f;

                        // TODO: PreJump and jump happen too quickly.  Many times prejump gets ignored.
                        Animator.TrySetMovementAnimation("PREJUMP");
                        Animator.TrySetMovementAnimation("JUMP");
                    }
                }
            }

            // TODO: Add the force instead of only setting it to support multiple forces per frame?
            m_forceToApply = direc;

            m_scene.StatsReporter.AddAgentTime(Util.EnvironmentTickCountSubtract(m_perfMonMS));
        }

Usage Example

示例#1
1
        public void HandleOnSignificantClientMovement(ScenePresence presence)
        {
            lock (m_avatars)
            {
                if (m_avatars.ContainsKey(presence.UUID) && presence.MovingToTarget)
                {
                    double distanceToTarget = Util.GetDistanceTo(presence.AbsolutePosition, presence.MoveToPositionTarget);
//                            m_log.DebugFormat(
//                                "[NPC MODULE]: Abs pos of {0} is {1}, target {2}, distance {3}",
//                                presence.Name, presence.AbsolutePosition, presence.MoveToPositionTarget, distanceToTarget);

                    // Check the error term of the current position in relation to the target position
                    if (distanceToTarget <= ScenePresence.SIGNIFICANT_MOVEMENT)
                    {
                        // We are close enough to the target
                        m_log.DebugFormat("[NPC MODULE]: Stopping movement of npc {0}", presence.Name);

                        if (presence.PhysicsActor.Flying)
                        {
                            Vector3 targetPos = presence.MoveToPositionTarget;
                            float terrainHeight = (float)presence.Scene.Heightmap[(int)targetPos.X, (int)targetPos.Y];
                            if (targetPos.Z - terrainHeight < 0.2)
                            {
                                presence.PhysicsActor.Flying = false;
                            }
                        }

                        presence.Velocity = Vector3.Zero;
                        presence.AbsolutePosition = presence.MoveToPositionTarget;
                        presence.ResetMoveToTarget();

                        // FIXME: This doesn't work
                        if (presence.PhysicsActor.Flying)
                            presence.Animator.TrySetMovementAnimation("HOVER");
                        else
                            presence.Animator.TrySetMovementAnimation("STAND");
                    }
                    else
                    {
                        m_log.DebugFormat(
                            "[NPC MODULE]: Updating npc {0} at {1} for next movement to {2}",
                            presence.Name, presence.AbsolutePosition, presence.MoveToPositionTarget);

                        Vector3 agent_control_v3 = new Vector3();
                        presence.HandleMoveToTargetUpdate(ref agent_control_v3, presence.Rotation);
                        presence.AddNewMovement(agent_control_v3, presence.Rotation);
                    }
//
////                    presence.DoMoveToPositionUpdate((0, presence.MoveToPositionTarget, null);

//
//

                }
            }
        }
All Usage Examples Of OpenSim.Region.Framework.Scenes.ScenePresence::AddNewMovement
ScenePresence