Gems/EMotionFX/Code/Tests/SimulatedObjectSetupTests.cpp
TEST_P(GetSimulatedRootJointFixture, TestSimulatedObject_GetSimulatedRootJoint)
    {
        PrefabLeftArmSkeleton leftArmSkeleton;

        Actor actor;
        EXPECT_CALL(actor, GetSkeleton())
            .WillRepeatedly(testing::Return(&leftArmSkeleton.m_skeleton));

        SimulatedObjectSetup setup(&actor);
        SimulatedObject* object = setup.AddSimulatedObject();

        const int jointIndex1 = testing::get<0>(GetParam());
        const int jointIndex2 = testing::get<1>(GetParam());

        object->AddSimulatedJointAndChildren(jointIndex1);
        if (jointIndex2 >= 0)
        {
            object->AddSimulatedJointAndChildren(jointIndex2);
        }

        const SimulatedJoint* simulatedJoint1 = object->FindSimulatedJointBySkeletonJointIndex(jointIndex1);
        EXPECT_TRUE(simulatedJoint1);

        if (jointIndex2 >= 0 && jointIndex2 != jointIndex1)
        {
            const SimulatedJoint* simulatedJoint2 = object->FindSimulatedJointBySkeletonJointIndex(jointIndex2);
            EXPECT_TRUE(simulatedJoint2);

            const Skeleton& skeleton = leftArmSkeleton.m_skeleton;
            const int hasCommonParent = NodeHasCommonParent(skeleton.GetNode(jointIndex1), skeleton.GetNode(jointIndex2));

            if (hasCommonParent == 0)
            {
                // simulatedJoint1 and simulatedJoint2 are not in each other's
                // parent list
                EXPECT_EQ(object->GetSimulatedRootJoint(object->GetSimulatedRootJointIndex(simulatedJoint1)), simulatedJoint1);
                EXPECT_EQ(object->GetSimulatedRootJoint(object->GetSimulatedRootJointIndex(simulatedJoint2)), simulatedJoint2);
                EXPECT_EQ(object->GetNumSimulatedRootJoints(), 2);
            }
            else if (hasCommonParent < 0)
            {
                // simulatedJoint1 is a parent of simulatedJoint2
                EXPECT_EQ(object->GetSimulatedRootJoint(object->GetSimulatedRootJointIndex(simulatedJoint1)), simulatedJoint1);
                EXPECT_EQ(object->GetNumSimulatedRootJoints(), 1);
            }
            else
            {
                // simulatedJoint2 is a parent of simulatedJoint1
                EXPECT_EQ(object->GetSimulatedRootJoint(object->GetSimulatedRootJointIndex(simulatedJoint2)), simulatedJoint2);
                EXPECT_EQ(object->GetNumSimulatedRootJoints(), 1);
            }
        }
        else
        {
            EXPECT_EQ(object->GetSimulatedRootJoint(object->GetSimulatedRootJointIndex(simulatedJoint1)), simulatedJoint1);
            EXPECT_EQ(object->GetNumSimulatedRootJoints(), 1);
        }
    }
// This test verifies that when any two joint indexes are added to a
// simulated object, it results in the correct root joints. It is
// parameterized on tuple<int, int>, where the two ints are the joint
// indexes of the PrefabLeftArmSkeleton to add. Index 2 may be -1, in which
// case only joint index 1 will be added to the object.
// For any two joints, it is possible that one joint is in the parent list
// of another joint. In this case, the number of root joints that should be
// in the simulated object is 1. If the two joints are siblings of each
// other, or in some other way unrelated (like not having any common
// parents), then the expected number of root joints is 2.
This test verifies that when any two joint indexes are added to a
simulated object, it results in the correct root joints. It is
parameterized on tuple, where the two ints are the joint
indexes of the PrefabLeftArmSkeleton to add. Index 2 may be -1, in which
case only joint index 1 will be added to the object.
For any two joints, it is possible that one joint is in the parent list
of another joint. In this case, the number of root joints that should be
in the simulated object is 1. If the two joints are siblings of each
other, or in some other way unrelated (like not having any common
parents), then the expected number of root joints is 2.
This test verifies that when any two joint indexes are added to a simulated object it results in the correct root joints . It is parameterized on tuple where the two ints are the joint indexes of the PrefabLeftArmSkeleton to add . Index 2 may be - 1 in which case only joint index 1 will be added to the object . For any two joints it is possible that one joint is in the parent list of another joint . In this case the number of root joints that should be in the simulated object is 1 . If the two joints are siblings of each other or in some other way unrelated ( like not having any common parents ) then the expected number of root joints is 2 .
TEST_P(GetSimulatedRootJointFixture, TestSimulatedObject_GetSimulatedRootJoint)
    {
        PrefabLeftArmSkeleton leftArmSkeleton;
        Actor actor;
        EXPECT_CALL(actor, GetSkeleton())
            .WillRepeatedly(testing::Return(&leftArmSkeleton.m_skeleton));
        SimulatedObjectSetup setup(&actor);
        SimulatedObject* object = setup.AddSimulatedObject();
        const int jointIndex1 = testing::get<0>(GetParam());
        const int jointIndex2 = testing::get<1>(GetParam());
        object->AddSimulatedJointAndChildren(jointIndex1);
        if (jointIndex2 >= 0)
        {
            object->AddSimulatedJointAndChildren(jointIndex2);
        }
        const SimulatedJoint* simulatedJoint1 = object->FindSimulatedJointBySkeletonJointIndex(jointIndex1);
        EXPECT_TRUE(simulatedJoint1);
        if (jointIndex2 >= 0 && jointIndex2 != jointIndex1)
        {
            const SimulatedJoint* simulatedJoint2 = object->FindSimulatedJointBySkeletonJointIndex(jointIndex2);
            EXPECT_TRUE(simulatedJoint2);
            const Skeleton& skeleton = leftArmSkeleton.m_skeleton;
            const int hasCommonParent = NodeHasCommonParent(skeleton.GetNode(jointIndex1), skeleton.GetNode(jointIndex2));
            if (hasCommonParent == 0)
            {
                EXPECT_EQ(object->GetSimulatedRootJoint(object->GetSimulatedRootJointIndex(simulatedJoint1)), simulatedJoint1);
                EXPECT_EQ(object->GetSimulatedRootJoint(object->GetSimulatedRootJointIndex(simulatedJoint2)), simulatedJoint2);
                EXPECT_EQ(object->GetNumSimulatedRootJoints(), 2);
            }
            else if (hasCommonParent < 0)
            {
                EXPECT_EQ(object->GetSimulatedRootJoint(object->GetSimulatedRootJointIndex(simulatedJoint1)), simulatedJoint1);
                EXPECT_EQ(object->GetNumSimulatedRootJoints(), 1);
            }
            else
            {
                EXPECT_EQ(object->GetSimulatedRootJoint(object->GetSimulatedRootJointIndex(simulatedJoint2)), simulatedJoint2);
                EXPECT_EQ(object->GetNumSimulatedRootJoints(), 1);
            }
        }
        else
        {
            EXPECT_EQ(object->GetSimulatedRootJoint(object->GetSimulatedRootJointIndex(simulatedJoint1)), simulatedJoint1);
            EXPECT_EQ(object->GetNumSimulatedRootJoints(), 1);
        }
    }
TEST_P ( GetSimulatedRootJointFixture , TestSimulatedObject_GetSimulatedRootJoint ) { PrefabLeftArmSkeleton leftArmSkeleton ; Actor actor ; EXPECT_CALL ( actor , GetSkeleton ( ) ) . WillRepeatedly ( testing :: Return ( & leftArmSkeleton . m_skeleton ) ) ; SimulatedObjectSetup setup ( & actor ) ; SimulatedObject * object = setup . AddSimulatedObject ( ) ; const int jointIndex1 = testing :: get < 0 > ( GetParam ( ) ) ; const int jointIndex2 = testing :: get < 1 > ( GetParam ( ) ) ; object -> AddSimulatedJointAndChildren ( jointIndex1 ) ; if ( jointIndex2 >= 0 ) { object -> AddSimulatedJointAndChildren ( jointIndex2 ) ; } const SimulatedJoint * simulatedJoint1 = object -> FindSimulatedJointBySkeletonJointIndex ( jointIndex1 ) ; EXPECT_TRUE ( simulatedJoint1 ) ; if ( jointIndex2 >= 0 && jointIndex2 != jointIndex1 ) { const SimulatedJoint * simulatedJoint2 = object -> FindSimulatedJointBySkeletonJointIndex ( jointIndex2 ) ; EXPECT_TRUE ( simulatedJoint2 ) ; const Skeleton & skeleton = leftArmSkeleton . m_skeleton ; const int hasCommonParent = NodeHasCommonParent ( skeleton . GetNode ( jointIndex1 ) , skeleton . GetNode ( jointIndex2 ) ) ; if ( hasCommonParent == 0 ) { EXPECT_EQ ( object -> GetSimulatedRootJoint ( object -> GetSimulatedRootJointIndex ( simulatedJoint1 ) ) , simulatedJoint1 ) ; EXPECT_EQ ( object -> GetSimulatedRootJoint ( object -> GetSimulatedRootJointIndex ( simulatedJoint2 ) ) , simulatedJoint2 ) ; EXPECT_EQ ( object -> GetNumSimulatedRootJoints ( ) , 2 ) ; } else if ( hasCommonParent < 0 ) { EXPECT_EQ ( object -> GetSimulatedRootJoint ( object -> GetSimulatedRootJointIndex ( simulatedJoint1 ) ) , simulatedJoint1 ) ; EXPECT_EQ ( object -> GetNumSimulatedRootJoints ( ) , 1 ) ; } else { EXPECT_EQ ( object -> GetSimulatedRootJoint ( object -> GetSimulatedRootJointIndex ( simulatedJoint2 ) ) , simulatedJoint2 ) ; EXPECT_EQ ( object -> GetNumSimulatedRootJoints ( ) , 1 ) ; } } else { EXPECT_EQ ( object -> GetSimulatedRootJoint ( object -> GetSimulatedRootJointIndex ( simulatedJoint1 ) ) , simulatedJoint1 ) ; EXPECT_EQ ( object -> GetNumSimulatedRootJoints ( ) , 1 ) ; } }
This test verifies that when any two joint indexes are added to a
simulated object, it results in the correct root joints.
This test verifies that when any two joint indexes are added to a simulated object it results in the correct root joints .
// simulatedJoint1 and simulatedJoint2 are not in each other's // parent list // simulatedJoint1 is a parent of simulatedJoint2 // simulatedJoint2 is a parent of simulatedJoint1