Using a Matrix to transform vectors

Post your questions, suggestions and experiences regarding to Image manipulation, 3d modeling and level editing for the Irrlicht engine here.
Post Reply
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Using a Matrix to transform vectors

Post by Acki »

hi,
I have 8 vectors that build a bounding box...
and I have the transformation matrix of a node...

but how do I use the matrix to translate and rotate the vectors ???

sorry for my ignorance... :oops:
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Using a Matrix to transform vectors

Post by CuteAlien »

Check CMatrix4<T>::transformVect in matrix4.h which does just that.
Or if you want more info check https://en.wikipedia.org/wiki/Matrix_multiplication (a vector can be thought of as a 1x3 or 3x1 matrix).
So it's a matrix-multiplication of the inner 3x3 matrix with the vector - and the translation part (elements 12-14 in Irrlicht) is simply added. Forget about 4th row for now it's usually 0.

And be careful that the inner 3x3 not only rotates but can also scale.

Or if you want to visualize it - the inner 3x3 matrix is basically describing your 3 axes of your coordinate system. And vectors are a multiplication with those axes. X*first axis+ Y*second axis + Z*third axis (which ends up being x = x*axis1.x+y*axis2.x+z*axis3.x as each axis can have an x part, same for y and z) We usually don't think about it for the simple case (the identity matrix) as all the multlications by 0 fall away and so result is just (x,y,z) again but the usual Cartesian coordinates are also a multiplication by the axes. If the 3 axis go in another direction and you do the same calculation then it moves your coordinate in those directions. So once you got a matrix things are pretty simple. Creating the matrix can be a bit more tricky (tends to involve the sin/cos stuff which you learned in school to use for rotations to rotate the original axes toward their new position).
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Post Reply