Can I do everything with Matrix that I've been using RotateAroundAxis etc for?

I found some posts about using Matrices for doing the same thing as RotateAroundAxis and all, but nothing too solid on the usage.

For example, using Matrix( ), how can I convert stuff like from this method to Matrix( ):

[lua] pos = _pos + _ang:Right( ) * pos.x + _ang:Forward( ) * pos.y + _ang:Up( ) * pos.z;
_ang:RotateAroundAxis( _ang:Forward( ), ang.p )
_ang:RotateAroundAxis( _ang:Up( ), ang.y )
_ang:RotateAroundAxis( _ang:Right( ),ang.r )[/lua]

Not exactly the same but:

[lua]local M = Matrix()

_pos = M:GetTranslation()
_ang = M:GetAngles()[/lua]

As I said in that other thread, matrices work a bit like a camera that you’d move and rotate in the world. A default matrix (returned by the Matrix() function) is equivalent to a camera at position (0, 0, 0) and angles (0, 0, 0). Any translation or rotation you apply to it is done relative to its current position and angles. So the order in which you apply the transformations is very important.

It might not give the exact same results as the code you posted. This is because Rotate actually performs three rotations (one for pitch, one for yaw and one for roll), and it doesn’t really tell you in which order it does them.

Also in Source, X is the forward axis, Y is the right axis and Z is the up axis. Therefore pitch is a rotation around the right axis, yaw is a rotation around the up axis and roll is a rotation around the forward axis. Get your axes right.

That might be the tidbit of info I needed.

I applied that matrix code to my weapon base to see if I could replace the RotateAroundAxis. It worked, sort of, it was off by a bit. So I’ll have to check the order then.

I’m working on a Skeleton Game-Mode with a ton of useful “helper-functions”, but classes to support rounds, bans, and more!

I’m trying to figure this out to add more functions to the arsenal! Thanks, I’ll play around with it a bit more :slight_smile: