public void TestMove()
        {
            TestHelpers.InMethod();
            //            log4net.Config.XmlConfigurator.Configure();

            ScenePresence sp = SceneHelpers.AddScenePresence(m_scene, TestHelpers.ParseTail(0x1));

            Vector3 startPos = sp.AbsolutePosition;

            //            Vector3 startPos = new Vector3(128, 128, 30);

            // For now, we'll make the scene presence fly to simplify this test, but this needs to change.
            sp.Flying = true;

            m_scene.Update(1);
            Assert.That(sp.AbsolutePosition, Is.EqualTo(startPos));

            Vector3 targetPos = startPos + new Vector3(0, 10, 0);

            sp.MoveToTarget(targetPos, false, false);

            Assert.That(sp.AbsolutePosition, Is.EqualTo(startPos));
            Assert.That(
                sp.Rotation, new QuaternionToleranceConstraint(new Quaternion(0, 0, 0.7071068f, 0.7071068f), 0.000001));

            m_scene.Update(1);

            // We should really check the exact figure.
            Assert.That(sp.AbsolutePosition.X, Is.EqualTo(startPos.X));
            Assert.That(sp.AbsolutePosition.Y, Is.GreaterThan(startPos.Y));
            Assert.That(sp.AbsolutePosition.Z, Is.EqualTo(startPos.Z));
            Assert.That(sp.AbsolutePosition.Z, Is.LessThan(targetPos.X));

            m_scene.Update(10);

            double distanceToTarget = Util.GetDistanceTo(sp.AbsolutePosition, targetPos);

            Assert.That(distanceToTarget, Is.LessThan(1), "Avatar not within 1 unit of target position on first move");
            Assert.That(sp.AbsolutePosition, Is.EqualTo(targetPos));
            Assert.That(sp.AgentControlFlags, Is.EqualTo((uint)AgentManager.ControlFlags.NONE));

            // Try a second movement
            startPos  = sp.AbsolutePosition;
            targetPos = startPos + new Vector3(10, 0, 0);
            sp.MoveToTarget(targetPos, false, false);

            Assert.That(sp.AbsolutePosition, Is.EqualTo(startPos));
            Assert.That(
                sp.Rotation, new QuaternionToleranceConstraint(new Quaternion(0, 0, 0, 1), 0.000001));

            m_scene.Update(1);

            // We should really check the exact figure.
            Assert.That(sp.AbsolutePosition.X, Is.GreaterThan(startPos.X));
            Assert.That(sp.AbsolutePosition.X, Is.LessThan(targetPos.X));
            Assert.That(sp.AbsolutePosition.Y, Is.EqualTo(startPos.Y));
            Assert.That(sp.AbsolutePosition.Z, Is.EqualTo(startPos.Z));

            m_scene.Update(10);

            distanceToTarget = Util.GetDistanceTo(sp.AbsolutePosition, targetPos);
            Assert.That(distanceToTarget, Is.LessThan(1), "Avatar not within 1 unit of target position on second move");
            Assert.That(sp.AbsolutePosition, Is.EqualTo(targetPos));
        }
示例#2
0
        private void DoMove(RequestData rdata)
        {
            if (rdata.Parameters.Length < 6)
            {
                Rest.Log.WarnFormat("{0} Move: No movement information provided", MsgId);
                rdata.Fail(Rest.HttpStatusCodeBadRequest, "no movement information provided");
            }
            else
            {
                string[]      names    = rdata.Parameters[PARM_MOVE_AVATAR].Split(Rest.CA_SPACE);
                ScenePresence presence = null;
                Scene         scene    = null;

                if (names.Length != 2)
                {
                    rdata.Fail(Rest.HttpStatusCodeBadRequest,
                               String.Format("invalid avatar name: <{0}>", rdata.Parameters[PARM_MOVE_AVATAR]));
                }

                Rest.Log.WarnFormat("{0} '{1}' command received for {2} {3}",
                                    MsgId, rdata.Parameters[0], names[0], names[1]);

                // The first parameter should be an avatar name, look for the
                // avatar in the known regions first.

                Rest.main.SceneManager.ForEachScene(delegate(Scene s)
                {
                    s.ForEachRootScenePresence(delegate(ScenePresence sp)
                    {
                        if (sp.Firstname == names[0] && sp.Lastname == names[1])
                        {
                            scene    = s;
                            presence = sp;
                        }
                    });
                });

                if (presence != null)
                {
                    Rest.Log.DebugFormat("{0} Move : Avatar {1} located in region {2}",
                                         MsgId, rdata.Parameters[PARM_MOVE_AVATAR], scene.RegionInfo.RegionName);

                    try
                    {
                        float   x      = Convert.ToSingle(rdata.Parameters[PARM_MOVE_X]);
                        float   y      = Convert.ToSingle(rdata.Parameters[PARM_MOVE_Y]);
                        float   z      = Convert.ToSingle(rdata.Parameters[PARM_MOVE_Z]);
                        Vector3 vector = new Vector3(x, y, z);
                        presence.MoveToTarget(vector, false, false);
                    }
                    catch (Exception e)
                    {
                        rdata.Fail(Rest.HttpStatusCodeBadRequest,
                                   String.Format("invalid parameters: {0}", e.Message));
                    }
                }
                else
                {
                    rdata.Fail(Rest.HttpStatusCodeBadRequest,
                               String.Format("avatar {0} not present", rdata.Parameters[PARM_MOVE_AVATAR]));
                }

                rdata.Complete();
                rdata.Respond("OK");
            }
        }