Hi
I have a C++ game development background, and am almost entirely flummoxed by the Transform class that is used to maintain the heirarchical scene graph in Unity.
Why on earth can I not just get and set the Matrix4x4 of a Transform?
The inclusion of rotation / position / scale in the class interfaces is understandable, as there's quite a lot to take in in order to get one's head around matrices.
I'm having to go around the houses for what should be the simplest of tasks.
For example: orphaning a Transform from its parent Transform and then re-positioning it with the same world space transform it had when it was attached.
This would be a single matrix multiply and matrix assignment in most of the game engines I've worked with.
My best guess as to how to do it using Transform is to copy position & rotation and then re-set them on the object after it's been orphaned - but there's no way to ensure scaling gets carried over correctly.
Am I missing something obvious about the way Transform works? e.g. am I supposed to be doing the matrix multiply and setting the At / Up / Right by hand?
cheers,
darbotron
Unity uses Transforms for rendering and for physics interactions. To this end, it does not store transformation matrices explicitly. Translation, rotation and scale are actually stored as vectors and quaternions, and transformation matrices are generated as needed.
Allowing the user to set arbitrary transformation matrices would make it difficult for the API to infer translation, rotation and scale in a lot of cases. Without valid TRS values, the physics engine would be very unhappy. In Unity 2.6, mesh scaling is done on the CPU, which also requires a separable scale (this behaviour is changing in Unity 3).
In the specific case you mention (keeping a Transform's world-space position the same while changing its parent), Unity actually does this automatically when you change Transform.parent. If you want to work around this behaviour, you have to record the Transform's local TRS, change the parent, and then re-assign the TRS values.
I know it might seem as if Unity is holding your hand too much, but this system is a lot safer and usually lets you do what you want in less code than if you were dealing with matrices the whole time.
I need to apply this matrix: “transformation”:[15,0,0,0,0,15,0,0,0,0,15,0,0,0,0,1]
and apply it to a gameobject (.obj 3D MODEL )to obtain a new transformation. How can i do that? Thank you.