Simple Matrix maths, rotating the node of a scenegraph based on the parent node.

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

Recommended Posts

Hey everyone, I've got a simple question. I have a scenegraph of a tree. Not a programming tree, but a tree (as in what you would see if you got outside more often). Lets say it has a trunk. Each branch off that is a child node of the main trunk. Each branch off those branches is a child node. And each leaf off those branches is another child node. Lets say each branch has a rotational matrix, so it is a branch from OriginBasedOnParentNode to (RotationalMatrix*Vector)+OriginBasedOnParentNode How would I go about preserving the rotation based on it's parent, given the parent's matrix? Lets say that the parent's matrix is rotated 90 degrees on the x axis. And the child's matrix is rotated -15 degrees on the x axis. So the child is rendered with a matrix of 75 degrees on the x axis. Given the parent matrix and the child matrix, how would I get the final matrix?

Share on other sites
Concatenating transformations means simply to multiply their matrices. If you are using column vectors, then applying a trafo M to a vector v means
v' := M * v
If you have 2 particular trafos, both to be applied, then it is
v' := M2 * M1 * v = ( M2 * M1 ) * v = M21 *v

However, there are several issues to deal carefully with (don't know how aware you are about this tuff, so I enumerate all that came to my mind).

(1) To work well, yo have to use homogeneous co-ordinates matrices. That frees you from the addition of the translation, and hence give you the chance to really concatenate transformations.

(2) Matrix multiplication isn't commutative, so that M1 * M2 != M2 * M1. In practice that makes a difference whether first to, say, rotate and then to translate, or vice-versa.

(3) Be aware of the difference of position vectors and direction vectors if dealing with supressed homogeneous co-ordinate.

EDIT:

(4) You may have to introduce supplementary trafos, e.g. if you have to rotate or to scale about a local center position.

Share on other sites
If two matrix transformations follow each other, the transformation is essentially the same as transforming with the matrix product of the two original matrices. In short:

finalTransformationMatrix = firstTransformationMatrix * secondTransformationMatrix

Order does matter.

This applies to pretty much any transformation (rotate, scale, translate, shear, etc...)

-Richardo

• What is your GameDev Story?

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

• 16
• 15
• 28
• 12
• 14
• Forum Statistics

• Total Topics
634805
• Total Posts
3019365
×