What is Matrix4x4 and how do i use it?
Matrix4x4 is a matrix with four rows and four columns and - along with the 3-dimensional vector - is the foundation of much 3D linear algebra. There is a lot you can do with a 4x4 matrix, but the simplest way to think of it is as a transformation. Unity Transform objects store their position, scale and rotation in two vectors and a quaternion. However, all of that information can be stored in a single matrix.
It doesn’t seem obvious at first, but transforms are just ways to move points and vectors from one place to another. ex. When you change the scale values on an object, it tells Unity to take the local values stored in the model and change where they appear in the game world.
Unity is nice enough to hide some of this stuff from you with interfaces.
Think about Transform.position and Transform.localPosition. Transform.position is just a shortcut so we don’t need to type out a matrix multiplication when we want to find out where a local position appears in world space.
However, they don’t give you a simple way to make things go in the other direction. If you wanted to know what a world point was in your game object’s local space, you would need to do something like
Vector3 localPoint = gameObject.transform.worldToLocalMatrix.MultiplyPoint( worldPoint )
Matrices are a topic too big to cover here. Luckily, the first few chapters of many many graphics textbooks are dedicated to them.
A great resource is the Real-Time Rendering Resources site. It has links to all kinds of books and other resources that will help you.
I need to work with a 4x4 matrix (16 numbers) and apply this transformation matrix to obtain a new position, rotation and scale, as I can work it?