Jump to content
  • Advertisement
Sign in to follow this  
fs1

Matrix Decomposition

This topic is 1551 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Dear All
It is my first post here.
I have a 4x4 affine matrix transformation and wanted to decompose it by polar decomposition, get the scale/stretch component and modify it - so I can resize my sprites to half of their size, and compose back my transform matrix.
Is this possible?
Thanks

Share this post


Link to post
Share on other sites
Advertisement

Decomposing the matrix transform is perhaps not needed; it depends on how you create the original sprite transform matrix. If you just use a rotation and translation, then you can multiply with the scaling matrix, i.e.

    M * S( 0.5 )  when using column vectors

    S( 0.5 ) * M  when using row vectors

should do the job. It works by first scaling the sprite (uniformly) and then applying the original transformation. Have you tried this already?

Share this post


Link to post
Share on other sites
Thanks haegarr!

This doesn't work unfortunately.

Can I do it via polar decomposition?

Share this post


Link to post
Share on other sites
I am hooking a game and getting the world matrix.

If I apply a scale matrix to it, the sprites disappear, they don't do the desire effect which is the scaling I want.

That's why I am looking into decomposition.

Regards,

Share this post


Link to post
Share on other sites


If I apply a scale matrix to it, the sprites disappear, they don't do the desire effect which is the scaling I want.

If you put the scale matrix on the wrong side, then you scale also the position and a sprite may disappear due to that. So, have you ensured that you've chosen the correct order of multiplication? What happens if you use scaling factors close to 1?

Share this post


Link to post
Share on other sites
haegarr, thanks. I did some tests.

I applied the scaling to the transform and it does the job. The problem I am having is that there is a group of sprites with a center somewhere, and the scale applies to that center.

How can I do a scale to each individual sprite from each center? This group is drawn in a single draw call.

I guess that math-wise, you need to translate to each center and do the scale for each element of the group?

Thanks!

Share this post


Link to post
Share on other sites


I guess that math-wise, you need to translate to each center and do the scale for each element of the group?

Yes: If p is the position of the center, then translate by -p so that the center comes to rest at 0, do the scaling, then translate back by +p.

 

Is the drawcall done with an own matrix for each sprite, or with a common matrix for all sprites?

Share this post


Link to post
Share on other sites

Thanks haegarr.

 

The problem is that the draw call is done with a common matrix. Any suggestions? Any changes on the vertices are possible?

 

Thanks for your help!

 

Regards,

Edited by fs1

Share this post


Link to post
Share on other sites


The problem is that the draw call is done with a common matrix. Any suggestions? Any changes on the vertices are possible?

I don't know whether you can change the vertices directly, because you just told nothing about how the vertices are passed.

 

If you have access to them then of course you can use the CPU to do the job. For example, if all sprites are given by quads then each 4-tuple of vertices are to be used. Or if sprites are passed as 2 triangles, then each 6-tuple is to be used. Or if the vertices are passed by index, then the same goes with indices.

 

You can then compute the center of each sprite by summing the N vertex positions and divide by N. Then subtract those center position from each of the N vertex positions, half the resulting vector, and re-add the center. E.g.

for each sprite
   vec2 center(0, 0);
   for each of the N vertices of the sprite do
      center += vertex.pos;
   center /= N;
   for each of the N vertices of the sprite do
      vertex.pos = ( vertex.pos + center ) * 0.5;

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!