Thursday, November 14, 2019

transformation - What is more efficient: Using matrix translation to move a character, or using a vector/scalar?


In 2D or 3D, matrix transformations are used for rotation, scaling, and sheering. However, when it comes to movement, should I go out of my way to use and implement scalar/vector movement, or just stick to matrix translations? Thanks.




Answer



This depends on some pipeline details, but generally we're not just translating objects, our engines need to handle objects that are translated, rotated, and scaled, and often need to apply camera view & perspective transforms to them too.


All of these transformations can be concatenated and applied with a single matrix multiplication, so it usually makes sense just to fold translation into that matrix. There's no incremental cost to translating that way, and any object, no matter how it's transformed, can be handled identically (rather than having one path for purely-translated objects and another for everything else)


If you're making a game where nothing ever scales, rotates, skews, or perspective projects, then you might make some efficiency gains by translating alone through vector addition without a matrix — but in exchange for pretty onerous restrictions on what your engine can do. For most projects, the matrix multiply is worth the flexibility it offers.


Even where a matrix is used, it's still conventional to store the translation, rotation, and scale information separately, so that when any of those change the matrix can be rebuilt from scratch, rather than continuously modified, keeping rounding errors from accumulating & causing drift.


No comments:

Post a Comment

Simple past, Present perfect Past perfect

Can you tell me which form of the following sentences is the correct one please? Imagine two friends discussing the gym... I was in a good s...