# Resize a whole particle system

5 replies to this topic

### #1codewings

New Member

• Members
• 3 posts
• LocationShanghai, China

Posted 08 December 2012 - 01:58 PM

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:

1. decompose the final transformation of the particle system to get the scaling component, then remove it from the final transformation.
2. transform the particle system by using the matrix get from step 1.
3. 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.

### #2Reedbeta

DevMaster Staff

• 5307 posts
• LocationBellevue, WA

Posted 08 December 2012 - 05:55 PM

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?
reedbeta.com - developer blog, OpenGL demos, and other projects

### #3codewings

New Member

• Members
• 3 posts
• LocationShanghai, China

Posted 09 December 2012 - 09:39 AM

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?

### #4}:+()___ (Smile)

Member

• Members
• 169 posts

Posted 09 December 2012 - 04:15 PM

Your algorithm works only for diagonal scale matrices. Math algorithms work for any type of scale matrices (arbitrary rotated).
Sorry my broken english!

### #5Reedbeta

DevMaster Staff

• 5307 posts
• LocationBellevue, WA

Posted 09 December 2012 - 06:26 PM

codewings, on 09 December 2012 - 09:39 AM, said:

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

Right.

codewings, on 09 December 2012 - 09:39 AM, said:

I 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.
reedbeta.com - developer blog, OpenGL demos, and other projects

### #6codewings

New Member

• Members
• 3 posts
• LocationShanghai, China

Posted 10 December 2012 - 12:26 PM

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

#### 1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users