1
\$\begingroup\$

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.

\$\endgroup\$
1
  • 1
    \$\begingroup\$ Did you have any issue with that? Or is it just premature optimization? \$\endgroup\$
    – Vaillancourt
    Dec 29, 2015 at 19:13

1 Answer 1

2
\$\begingroup\$

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.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .