D3DXMatrixRotationAxis Math

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

Recommended Posts

Can anyone help me with the how this function works in DirectX im using my own Structs in my engine so i dont have to use Directx for Matrix's, Vector's, ect and im not sure how to do this the method takes a Vector and an Angle. Any help would be great thanks everyone.

Share on other sites
I am also currious about this, are they using quanternions to do it and justnot telling you?

Share on other sites
If you're just wondering about how to build an axis-angle rotation matrix, here's some code that does so:

template <class T> void Matrix4<T>::LoadAxisAngle(T x, T y, T z, T angle){    T s = sin(angle);    T c = cos(angle);    T omc = (T)1.0 - c;        T xomc = x * omc;    T yomc = y * omc;    T zomc = z * omc;        T xxomc = x * xomc;    T xyomc = x * yomc;    T xzomc = x * zomc;    T yyomc = y * yomc;    T yzomc = y * zomc;    T zzomc = z * zomc;        T xs = x * s;    T ys = y * s;    T zs = z * s;        Set3x3(xxomc + c,  xyomc + zs, xzomc - ys,           xyomc - zs, yyomc + c,  yzomc + xs,           xzomc + ys, yzomc - xs, zzomc + c);}

The above is in row-vector form, which is probably what you want for compatibility with DX.

Share on other sites
The above code is actually the "quaternion to orientation matrix" approach.

The "pure matrix" way to this involves what it know as a "similarity transformation" (linear aslgebra term).
You calculate a rotation matrix which is mathematically "similar" to a typical rotation around one of the global axes. Mathematically "similar" means merely the same transformation performing on different coordinates' systems.

If you feel like looking into this a bit more, you can google "similarity transformation", however the implementation suggested by jyk will be much faster, plus it remains unaffected by degenerate cases.

My opinion is go for the quaternion approach...

Share on other sites
Actually, the code I posted is just a regular axis-angle rotation matrix, not a quaternion matrix. I assume that's what the OP was looking for, but I'm not sure.

Share on other sites
"quaternion" way and "pure" way is inherently the same as in both cases you have axis, and sine and cosine of angle (or half angle). (you don't use angle directly, you find sin and cos)
Also, as juk's matrix uses angle and not half angle it is more like "pure" way.

Share on other sites
My bad... It looks a lot like the quaternion to matrix implementation, which -of course- I don't remember by heart. Indeed, the use of the whole angle instead of the half was a good indication, however, this isn't really something to rely on. (with all the trig. identities and stuff...)

A similarity transformation seemed quite a "pure" way to me, because it handles the problem in a straightforward manner, using "primitive" means: Change basis vectors, rotate around global axis (which has trivial -to derive- rotation matrix), restore basis vectors.

However I suggest the above implementation too. It's fast.

Share on other sites
Thanks guys for the great posts I think I am leaning on the quaternion way, but now I guess my question would be which would be better performance wise? or is there not much of a difference.

• What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 13
• 12
• 15
• 11
• 12
• Forum Statistics

• Total Topics
634153
• Total Posts
3015844
×