Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

libgdx: What is the difference between ModelInstance.transform.setToTranslation(..) and ModelInstance.transform.translate(..)?

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?

like image 924
kalenwatermeyer Avatar asked Dec 25 '22 17:12

kalenwatermeyer


1 Answers

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

like image 152
Xoppa Avatar answered May 18 '23 18:05

Xoppa