- Home /
What is worldToLocalMatrix.MultiplyPoint doing in the back end ?
I just have a simple question.
what mathematical operation is worldToLocalMatrix.MultiplyPoint carrying out in the back end ?
I wanted to know what calculations happen inside of worldToLocalMatrix.MultiplyPoint so I wrote a little script that rotates an object through the x axis only by +=1
I then add a child object to the object with this script on it .
This prints out all the changes that worldToLocalMatrix.MultiplyPoint of the child object when we rotate the parent through the x axis.
when i rotate an move the child object around I see the printed out values change. they follow a pattern but I cant figure out what the numbers mean
using UnityEngine;
public class InspectWTLM : MonoBehaviour {
public int xRotations;
// Update is called once per frame
void Update ()
{
transform.localEulerAngles = new Vector3(xRotations += 1, 0, 0);
Debug.Log((transform.worldToLocalMatrix.MultiplyPoint(transform.position) + " " + xRotations));
if (xRotations == 360)
{
xRotations = 0;
}
}
}
Answer by HarshadK · Feb 16, 2017 at 06:08 AM
The Matrix4x4.MultiplyPoint method implementation is something like this:
public Vector3 MultiplyPoint(Vector3 v)
{
Vector3 result;
result.x = this.m00 * v.x + this.m01 * v.y + this.m02 * v.z + this.m03;
result.y = this.m10 * v.x + this.m11 * v.y + this.m12 * v.z + this.m13;
result.z = this.m20 * v.x + this.m21 * v.y + this.m22 * v.z + this.m23;
float num = this.m30 * v.x + this.m31 * v.y + this.m32 * v.z + this.m33;
num = 1f / num;
result.x *= num;
result.y *= num;
result.z *= num;
return result;
}
Hope this helps.