Jump to content
  • Advertisement
Sign in to follow this  
k00k

D3DXMatrixRotationAxis Math

This topic is 4524 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

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 this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
I am also currious about this, are they using quanternions to do it and justnot telling you?

Share this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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.

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!