Common way to store model transformations

Posted by redreggae on Game Development See other posts from Game Development or by redreggae
Published on 2013-06-25T14:47:58Z Indexed on 2013/06/25 16:30 UTC
Read the original article Hit count: 188

Filed under:
|
|

I ask myself what's the best way to store the transformations in a model class. What I came up with is to store the translation and scaling in a Vector3 and the rotation in a Matrix4.

On each update (frame) I multiply the 3 matrices (first build a Translation and Scaling Matrix) to get the world matrix. In this way I have no accumulated error.

world = translation * scaling * rotation 

Another way would be to store the rotation in a quaternion but then I would have a high cost to convert to a matrix every time step. If I lerp the model I convert the rotation matrix to quaternion and then back to matrix.

For speed optimization I have a dirty flag for each transformation so that I only do a matrix multiplication if necessary.

world = translation
if (isScaled) {
    world *= scaling
}
if (isRotated) {
    world *= rotation
}

Is this a common way or is it more common to have only one Matrix4 for all transformations? And is it better to store the rotation only as quaternion? For info: Currently I'm building a CSS3D engine in Javascript but these questions are relevant for every 3D engine.

© Game Development or respective owner

Related posts about matrix

Related posts about models