- Home /
Usage of Pose.GetTransformedBy
Hi, I ran into an issue using Pose.GetTransformedBy.
The documentation is pretty brief on this one:
"Transforms the current pose into the local space of the provided pose."
I wanted to use this to convert a pose from worldspace into the space of another pose. But it seems like this is not how it works. Here is my test setup: I have a root object. I have child object A on the root with an offset and rotation. If i take the global pose of the child object and call get transformed by the root, I should get the local Pose of child object A.
Example code to try is below.
My Question:
How is GetTransformedBy usually used? Did i missunderstand the documentation?
My current solution is to transform the Pose via this code:
public static Pose worldPoseToLocal(Pose worldPose, Transform system)
{
return new Pose(system.InverseTransformPoint(worldPose.position),
Quaternion.Inverse(system.rotation) * worldPose.rotation);
}
Code to test GetTransformedBy:
GameObject root = GameObject.CreatePrimitive(PrimitiveType.Cylinder);
root.name = "root";
GameObject aobj = GameObject.CreatePrimitive(PrimitiveType.Cylinder);
aobj.name = "A";
GameObject bobj = GameObject.CreatePrimitive(PrimitiveType.Cylinder);
bobj.name = "B";
//Random pose
root.transform.position = new Vector3(1.0f, 0.5f, 1.2f);
root.transform.rotation = new Quaternion(0.2f, 1.2f, 0.2f, 1.0f).normalized;
//Random child Pose
aobj.transform.SetParent(root.transform);
aobj.transform.localPosition = new Vector3(2.5f, 1.0f, 3.0f);
aobj.transform.localRotation = new Quaternion(0.8f, 0.0f, 1.2f, 0.77f).normalized;
Pose relPose = new Pose(aobj.transform.position, aobj.transform.rotation).GetTransformedBy(root.transform);
// Visualise pose difference
// relPose != aobj.localPosition, aobj.localRotation
bobj.transform.SetParent(root.transform);
bobj.transform.localPosition = relPose.position;
bobj.transform.localRotation = relPose.rotation;
Did you ever figure out what GetTransformedBy is actually doing?