Esempio n. 1
0
        public void TestllSetLinkPrimitiveParamsForAgent()
        {
            TestHelpers.InMethod();
            //            TestHelpers.EnableLogging();

            UUID userId = TestHelpers.ParseTail(0x1);

            SceneObjectPart part = SceneHelpers.AddSceneObject(m_scene).RootPart;

            part.RotationOffset = new Quaternion(0.7071068f, 0, 0, 0.7071068f);

            LSL_Api apiGrp1 = new LSL_Api();

            apiGrp1.Initialize(m_engine, part, null, null);

            ScenePresence sp = SceneHelpers.AddScenePresence(m_scene, userId);

            // sp has to be less than 10 meters away from 0, 0, 0 (default part position)
            Vector3 startPos = new Vector3(3, 2, 1);

            sp.AbsolutePosition = startPos;

            sp.HandleAgentRequestSit(sp.ControllingClient, sp.UUID, part.UUID, Vector3.Zero);

            int entityUpdates = 0;

            ((TestClient)sp.ControllingClient).OnReceivedEntityUpdate += (entity, flags) => { if (entity is ScenePresence)
                                                                                              {
                                                                                                  entityUpdates++;
                                                                                              }
            };

            // Test position
            {
                Vector3 newPos = new Vector3(1, 2, 3);
                apiGrp1.llSetLinkPrimitiveParams(2, new LSL_Types.list(ScriptBaseClass.PRIM_POSITION, newPos));

                Assert.That(sp.OffsetPosition, Is.EqualTo(newPos));

                m_scene.Update(1);
                Assert.That(entityUpdates, Is.EqualTo(1));
            }

            // Test small reposition
            {
                Vector3 newPos = new Vector3(1.001f, 2, 3);
                apiGrp1.llSetLinkPrimitiveParams(2, new LSL_Types.list(ScriptBaseClass.PRIM_POSITION, newPos));

                Assert.That(sp.OffsetPosition, Is.EqualTo(newPos));

                m_scene.Update(1);
                Assert.That(entityUpdates, Is.EqualTo(2));
            }

            // Test world rotation
            {
                Quaternion newRot = new Quaternion(0, 0.7071068f, 0, 0.7071068f);
                apiGrp1.llSetLinkPrimitiveParams(2, new LSL_Types.list(ScriptBaseClass.PRIM_ROTATION, newRot));

                Assert.That(
                    sp.Rotation, new QuaternionToleranceConstraint(part.GetWorldRotation() * newRot, 0.000001));

                m_scene.Update(1);
                Assert.That(entityUpdates, Is.EqualTo(3));
            }

            // Test local rotation
            {
                Quaternion newRot = new Quaternion(0, 0.7071068f, 0, 0.7071068f);
                apiGrp1.llSetLinkPrimitiveParams(2, new LSL_Types.list(ScriptBaseClass.PRIM_ROT_LOCAL, newRot));

                Assert.That(
                    sp.Rotation, new QuaternionToleranceConstraint(newRot, 0.000001));

                m_scene.Update(1);
                Assert.That(entityUpdates, Is.EqualTo(4));
            }
        }