Reputation: 741
What is the difference between:
myModel.transform.SetToTranslation( *some Vector3* )
and
myModel.transform.translate( *some Vector3* )
(where myModel is of type ModelInstance)
Specifically, what are the side-effects of these operations?
And most importantly for me, what are some typical use cases in which you'd use one method over the other?
Upvotes: 4
Views: 839
Reputation: 8123
setToTranslation
sets the matrix to the translation. In other words, it removes every transformation the matrix had prior to the call (e.g. any translation, rotation and scale) and then sets it be a translation matrix with the specified values.
translate
will post-multiply the current transformations of the matrix with a translation matrix containing the given translation, resulting in:
transform.translate(x,y,z) == transform.mul(tempMatrix.setToTranslation(x,y,z))
The major side effect from using translate
(which is matrix math and not specific to libgdx) is that any transformation prior to it might (will) influence the translation.
This post might be helpful for you: http://badlogicgames.com/forum/viewtopic.php?f=11&t=17878&p=75338#p75338
Upvotes: 7
Reputation: 112897
SetToTranslation sets the 4x4 matrix to the identity matrix, and then sets the fourth column to the passed in translations matrix.
translate post multiplies the matrix with a translation vector.
Without the fancy words, this means that SetToTranslation removes all rotation and sets the Model on the coordinates you give it, and translate moves the model from it's current position which what you multiply it with.
SetToTranslation migth be used when you want to put a model on a specific coordinate, whilst translate is better if you want to move your model smoothly.
Upvotes: 3