]]>Thank you very much. Uniform scaling is enough for my particle system.

]]>So if i am using the column major matrix, I only need to change the index to make the code snippet work, right?

Right.

@codewingsI also noticed that there have some other algorithms to decompose a matrix ( SVD, QR algorithm ). So when should I to use these algorithms?

To clarify, I'm assuming that your matrix is in "SRT" form - Scale, Rotate, Translate, meaning the transformations from local to world space are done in that order. First you scale the local space - usually uniformly, but if nonuniform scaling is applied it is always along the XYZ axes of local space (this is what Smile meant by a "diagonal scale matrix"). Then you rotate the space to orient it to its parent and finally translate it to its correct position. When a matrix is constructed in SRT form, you can extract the original XYZ scale factors by looking at the length of each row (for row-vector convention) or column (for column-vector convention) of the matrix.

This will also work when multiple transformations are concatenated in a local->parent->parent->...->world hierarchy - as long as nonuniform scaling is applied only at the bottom-most level. (Uniform scaling is fine at any level.) If rotation is used prior to non-uniform scaling, or (worse) if multiple non-uniform scalings are applied with a rotation between them, then the result is no longer in SRT form and you have to use a more sophisticated algorithm like one of the ones you mentioned.

In short, stick with uniform scaling and you won't have trouble. Non-uniform scaling brings in a whole bunch of extra problems.

]]>Your algorithm works only for diagonal scale matrices. Math algorithms work for any type of scale matrices (arbitrary rotated).

]]>Thanks for replying me.

I need to solve the problem because my particle system has the local space simulation mode and the world space simulation mode ( I think most of the game engines should have these two modes ). When using the world space simulation mode, each particle will not take consider of the emitter's transformation after it spawned. So I can't use vertex shader to do this job.

So if i am using the column major matrix, I only need to change the index to make the code snippet work, right?I also noticed that there have some other algorithms to decompose a matrix ( SVD, QR algorithm ). So when should I to use these algorithms?

]]>If you are using the row-vector convention for your matrix math, that should be correct.

However, I'm not sure why you need to go to such trouble. If the particles are simulated in the particle system's local space, then you can apply the transform in the particles' vertex shader just like any other shader, can't you?

]]>Hi,

I am now want to make my particle system support scaling. My particle system can be attached to an arbitrary node. Here is my plan:

- decompose the final transformation of the particle system to get the scaling component, then remove it from the final transformation.
- transform the particle system by using the matrix get from step 1.
- use the scaling component to scale the parameters of the particle system ( velocity, acceleration, position, size and so on ).
I am not sure if I can extract the scaling component from the matrix by using the following code:

const FLOAT Sum0 = (M[0][0] * M[0][0]) + (M[0][1] * M[0][1]) + (M[0][2] * M[0][2]);

const FLOAT Sum1 = (M[1][0] * M[1][0]) + (M[1][1] * M[1][1]) + (M[1][2] * M[1][2]);

const FLOAT Sum2 = (M[2][0] * M[2][0]) + (M[2][1] * M[2][1]) + (M[2][2] * M[2][2]);FLOAT ScaleX = sqrt(Sum0);

FLOAT InvScaleX = 1.f / ScaleX;

M[0][0] *= InvScaleX;

M[0][1] *= InvScaleX;

M[0][2] *= InvScaleX;FLOAT ScaleY = sqrt(Sum1);

FLOAT InvScaleY = 1.f / ScaleY;

M[1][0] *= InvScaleY;

M[1][1] *= InvScaleY;

M[1][2] *= InvScaleY;FLOAT ScaleZ = sqrt(Sum2);

FLOAT InvScaleZ = 1.f / ScaleZ;

M[2][0] *= InvScaleZ;

M[2][1] *= InvScaleZ;

M[2][2] *= InvScaleZ;Fix me if I am wrong please. Thanks in advance.