Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / Deriving rotation, scale and translation from world matrix?

Author
Message
Rudolpho
19
Years of Service
User Offline
Joined: 28th Dec 2005
Location: Sweden
Posted: 24th Jan 2014 15:39
This should be relatively easy to do, but so far I've been unable to find any information on it and thought I'd ask and see if somebody around here know how to go about it.

I have a pre-computed world matrix (rotation * scale * translation). Is there any easy way to extract the three matrices that were combined to make this transform? If there isn't I suppose it should be possible to extract values that can be re-interpreted to recreate those matrices again, any idea on how to go about that?


Thanks for any input.


"Why do programmers get Halloween and Christmas mixed up?"
Rudolpho
19
Years of Service
User Offline
Joined: 28th Dec 2005
Location: Sweden
Posted: 24th Jan 2014 22:53
Hm, I found this link which deals with the issue. His solution works fow the position and scale, however the rotation is seriously off (and yes, I do calculate it in radians, not degrees). Too bad there is no mention of the "reason for this to work" except that that blog post wasn't the place for it, any idea what may be wrong with it?
The rotation in my test transform matrix is created using XMMatrixRotationRollPitchYaw(x, y, z) if that matters, but I would think that the resulting rotation matrix follows a set format still to work at all (and yes, transformations by this matrix do look accurate so I don't think the matrix is messed up).


"Why do programmers get Halloween and Christmas mixed up?"
Le Verdier
13
Years of Service
User Offline
Joined: 10th Jan 2012
Location: In the mosh-pit
Posted: 24th Jan 2014 23:05
So we have:
Mr*Ms*Mt=
m11 m12 m13 0
m21 m22 m23 0
m31 m32 m33 0
m41 m42 m43 1


which is:
bx*scx by*scy bz*scz 0
nx*scx ny*scy nz*scz 0
tx*scx ty*scy tz*scz 0
dx dy dz 1

Extrating Mt is easy:
1 0 0 0
0 1 0 0
0 0 1 0
dx dy dz 1

Mr is an orthonormal basis, so Len(bx, nx, tx) = 1 (idem for by/ny/ty and bz/nz/tz...)
we find:
scx = sqrt(m11*m11+m21*m21+m31*31)
scy = sqrt(m12*m12+m22*m22+m32*32)
scz = sqrt(m13*m13+m23*m23+m33*33)

Ms:
scx 0 0 0
0 scy 0 0
0 0 scZ 0
0 0 0 1

and for Mr:
m11/scx m12/scy m13/scz 0
m21/scx m22/scy m23/scz 0
m31/scx m32/scy m33/scz 0
0 0 0 1


!!!

Rudolpho
19
Years of Service
User Offline
Joined: 28th Dec 2005
Location: Sweden
Posted: 25th Jan 2014 22:10
Thank you very much for the thorough explanation; I broke out the old paper and pencil and eventually managed to follow your reasoning (maybe I shouldn't have given up my math studies after failing that introductory course to linear algebra after all...?) and it indeed solved my problem


"Why do programmers get Halloween and Christmas mixed up?"
Le Verdier
13
Years of Service
User Offline
Joined: 10th Jan 2012
Location: In the mosh-pit
Posted: 26th Jan 2014 12:33

Glad that helped but let me just a slight add:

I assumed a matrix to fit your question (rotation * scale * translation)
but generaly the scale is applied first:
scale * rotation * translation
which is :
bx*scx by*scx bz*scx 0
nx*scy ny*scy nz*scy 0
tx*scz ty*scz tz*scz 0
dx dy dz 1

in this case, scx = sqrt(m11*m11+m12*m12+m13*m13) and so on..
so you should verify if your transform order is well Mr*Ms*Mt

this give the same result in case of uniform scaling, but not in nonuniform scaling..

Rudolpho
19
Years of Service
User Offline
Joined: 28th Dec 2005
Location: Sweden
Posted: 26th Jan 2014 22:44
Hm, thanks for the heads-up; it is the application order I use in my Transform class and it was based on some MSDN page and / or DirectX tutorial I believe so I just assumed that was the way it should be done. I know you can apply individual X, Y, Z rotation matrices in arbitrary order which gives the result of first rotating around the first axis, then the other and so on but I thought the resulting matrix would simply be "wrong" if you mix up the order of the main parts, at least that's what I recall from reading about it.

I will take an extra look at how the collada files I'm parsing (that's why I needed this solved in the first place) seem to store their matrices though. Apart from them being column major and DX row major everything seems to be accurate now though


"Why do programmers get Halloween and Christmas mixed up?"

Login to post a reply

Server time is: 2025-05-16 18:20:57
Your offset time is: 2025-05-16 18:20:57