Comments and answers for "Mapping from External to Unity World Coordinates"
http://answers.unity.com/questions/621202/mapping-from-external-to-unity-world-coordinates.html
The latest comments and answers for the question "Mapping from External to Unity World Coordinates"Comment by Schnodahipfe on Schnodahipfe's answer
http://answers.unity.com/comments/621324/view.html
Tried it and it worked (with the scale and translation calculated as in the above comment)! Thanks a lot!Mon, 20 Jan 2014 16:31:30 GMTSchnodahipfeComment by Schnodahipfe on Schnodahipfe's answer
http://answers.unity.com/comments/621231/view.html
Thanks a bunch! How would I get the scale factor and the position/translation vector? Would the following be correct?
1. Calculate the scale as
`Vector3.Distance (a*, b*) /
Vector3.Distance (a, b)` (with `a`
and `b` being the original points
and `a*` and `b*` being the
corresponding points in the target
system).
2. Scale `a` with the calculated factor
to get `a'`. Use `a* - a'` as the
position/translation vector.Mon, 20 Jan 2014 13:43:05 GMTSchnodahipfeAnswer by Bunny83
http://answers.unity.com/answers/621209/view.html
Just create a [Matrix4x4][1] with your desired values:
Vector3 position = new Vector3(XX,YY,ZZ);
Vector3 scale = Vector3.one * scale;
// or
//Vector3 scale = new Vector3(scaleX,scaleY,scaleZ);
Matrix4x4 mat = Matrix4x4.TRS(position, Quaternion.identity, scale);
***edit***
If you don't have any rotation you can also manually scale / transform the points:
Vector3 Map(Vector3 aPos)
{
aPos *= scale;
aPos += position;
return aPos;
}
***2. edit***
As final alternative you can simply create an empty gameobject, move it where your "new" origin of your external position should be and change the scale ot the object. All childs can be placed at the incoming external coordinates (localPosition) and to read the unity world position just read ".position".
With this approach you get the transformation matrix for free since the Transform component calculates it for you. You can also use [TransformPoint][2] and [InverseTransformPoint][3] to convert a position from one space to the other.
[1]: http://docs.unity3d.com/Documentation/ScriptReference/Matrix4x4.html
[2]: http://docs.unity3d.com/Documentation/ScriptReference/Transform.TransformPoint.html
[3]: http://docs.unity3d.com/Documentation/ScriptReference/Transform.InverseTransformPoint.htmlMon, 20 Jan 2014 12:56:16 GMTBunny83