Esempio n. 1
0
        public void TestTwoBodies()
        {
            // * rootObj
            //   - rb1
            //   * go2
            //     - rb2
            //     - joint
            var rootObj = new GameObject();
            var rb1     = rootObj.AddComponent <Rigidbody>();

            var go2 = new GameObject();
            var rb2 = go2.AddComponent <Rigidbody>();

            go2.transform.SetParent(rootObj.transform);

            var joint = go2.AddComponent <ConfigurableJoint>();

            joint.connectedBody = rb1;

            var poseExtractor = new RigidBodyPoseExtractor(rb1);

            Assert.AreEqual(2, poseExtractor.NumPoses);

            rb1.position = new Vector3(1, 0, 0);
            rb1.rotation = Quaternion.Euler(0, 13.37f, 0);
            rb1.velocity = new Vector3(2, 0, 0);

            Assert.AreEqual(rb1.position, poseExtractor.GetPoseAt(0).position);
            Assert.IsTrue(rb1.rotation == poseExtractor.GetPoseAt(0).rotation);
            Assert.AreEqual(rb1.velocity, poseExtractor.GetLinearVelocityAt(0));
        }
Esempio n. 2
0
        public void TestTwoBodiesVirtualRoot()
        {
            // * virtualRoot
            // * rootObj
            //   - rb1
            //   * go2
            //     - rb2
            //     - joint
            var virtualRoot = new GameObject("I am vroot");

            var rootObj = new GameObject();
            var rb1     = rootObj.AddComponent <Rigidbody>();

            var go2 = new GameObject();

            go2.AddComponent <Rigidbody>();
            go2.transform.SetParent(rootObj.transform);

            var joint = go2.AddComponent <ConfigurableJoint>();

            joint.connectedBody = rb1;

            var poseExtractor = new RigidBodyPoseExtractor(rb1, null, virtualRoot);

            Assert.AreEqual(3, poseExtractor.NumPoses);

            // "body" 0 has no parent
            Assert.AreEqual(-1, poseExtractor.GetParentIndex(0));

            // body 1 has parent 0
            Assert.AreEqual(0, poseExtractor.GetParentIndex(1));

            var virtualRootPos = new Vector3(0, 2, 0);
            var virtualRootRot = Quaternion.Euler(0, 42, 0);

            virtualRoot.transform.position = virtualRootPos;
            virtualRoot.transform.rotation = virtualRootRot;

            Assert.AreEqual(virtualRootPos, poseExtractor.GetPoseAt(0).position);
            Assert.IsTrue(virtualRootRot == poseExtractor.GetPoseAt(0).rotation);
            Assert.AreEqual(Vector3.zero, poseExtractor.GetLinearVelocityAt(0));

            // Same as above test, but using index 1
            rb1.position = new Vector3(1, 0, 0);
            rb1.rotation = Quaternion.Euler(0, 13.37f, 0);
            rb1.velocity = new Vector3(2, 0, 0);

            Assert.AreEqual(rb1.position, poseExtractor.GetPoseAt(1).position);
            Assert.IsTrue(rb1.rotation == poseExtractor.GetPoseAt(1).rotation);
            Assert.AreEqual(rb1.velocity, poseExtractor.GetLinearVelocityAt(1));
        }
Esempio n. 3
0
        public void TestTwoBodies()
        {
            // * rootObj
            //   - rb1
            //   * go2
            //     - rb2
            //     - joint
            var rootObj = new GameObject();
            var rb1     = rootObj.AddComponent <Rigidbody>();

            var go2 = new GameObject();
            var rb2 = go2.AddComponent <Rigidbody>();

            go2.transform.SetParent(rootObj.transform);

            var joint = go2.AddComponent <ConfigurableJoint>();

            joint.connectedBody = rb1;

            var poseExtractor = new RigidBodyPoseExtractor(rb1);

            Assert.AreEqual(2, poseExtractor.NumPoses);

            rb1.position = new Vector3(1, 0, 0);
            rb1.rotation = Quaternion.Euler(0, 13.37f, 0);
            rb1.velocity = new Vector3(2, 0, 0);

            Assert.AreEqual(rb1.position, poseExtractor.GetPoseAt(0).position);
            Assert.IsTrue(rb1.rotation == poseExtractor.GetPoseAt(0).rotation);
            Assert.AreEqual(rb1.velocity, poseExtractor.GetLinearVelocityAt(0));

            // Check DisplayNodes gives expected results
            var displayNodes = poseExtractor.GetDisplayNodes();

            Assert.AreEqual(2, displayNodes.Count);
            Assert.AreEqual(rb1, displayNodes[0].NodeObject);
            Assert.AreEqual(false, displayNodes[0].Enabled);

            Assert.AreEqual(rb2, displayNodes[1].NodeObject);
            Assert.AreEqual(true, displayNodes[1].Enabled);
        }