View Full Version : hierarchy transformation
blacknight 05202005, 08:31 PM hmm could any of you guys please point me to somewhere i could learm how to do hierarchy 2d transformation. i doing some test and i want to being able so that i have a parent layer and a child layer. and i want it to behave like when you parent any object in 3d space. if you rotate the parent the child rotates as well as move. i been looking but all i found in the transformation matrix. i kinda underteand how that works but now how do the calculate the inharited movement


playmesumch00ns
05212005, 11:25 AM
The transformation for the child is the result of the concatenation of the parent's transform matrix and the child's transform matrix.
A good way to lay it out is
World

Transform1

Object1

Transform2

Object2
Then the transform for Object2 is Transform1 X Transform2
arnecls
05232005, 09:04 AM
You should look up "scenegraph" in google for that.
As posted above it's quite simple. You can describe every scale, rotation, translation (movement) and shearing as Matrix. In 2D that would be 3x3 Matrixes, in 3D that would be 4x4. You should use homogene (hope that's the same as in german =) coordinates (for 2D that's 2 coordinates + one which's value is always 1) because otherwise translations won't work. Also be aware that matrixmultiplication is not commutative, meaning that M1 * M2 is NOT M2 * M1 and that vec1 * M1 is NOT M1 * vec1 (but Transpose(M1) * vec1 is).
You can look the details up on mathworld (http://mathworld.wolfram.com/) if you like.
The 2D matrixes are only slightly different from 3D, e.g. Translation:
1 0 0 x
0 1 0 y
0 0 1 z
0 0 0 1
1 0 x
0 1 y
0 0 1
That's for matrix * vector with the vector being one column (a vector is a matrix with one column and 3 rows in that case  again  see mathworld for details).
Ok  now for concatenations.
You can describe ANY movement bei a series of matrixmultiplications  but  as I said  the order is significant. E.g. you are always rotating around the center (0,0) now imagine a square around 0,0, translate that by 10 to the right and now rotate 45 degrees > your square will be (roughly) 3 to the right and 3 to the top.
BUT  if you rotate first you will have a square, rotated by 45 degress 10 to the right.
So what's helping you there? Quite simple. You can see the matrixmultiplications as a stack, meaning you can put a matrix on top AND remove one from the top. That screams "recursion" =)
So a little example: two platforms, one with an object on top and one without. I put in a world transformation matrix for better understanding. Each matrix here can be a concatenation of different matrixes too, e.g. M_translation * M_rotation = M_pa.
You would put each of that Matrixes on the stack, too.
Platform A Translation:
M_world * M_pa * platformSprite
Object Translation
M_world * M_pa * M_obj * object
Platform B Translation
M_world * M_pb * platformSprite
You can now see that as a tree
M_world

+ M_pa
 + platform
 + M_obj
 + object
+ M_pb
+ platform
If you see that as a stack that would be the following operations:
push(M_world)
push(M_pa)
calculate complete Stack and paint platform
push(M_obj)
calculate complete Stack and paint object
pop() < returning to M_pa
pop() < returning to M_world
push(M_pb)
calculate complete Stack and paint platform
See the beauty? =)
For further readings I would suggest searching www.gemdev.net or the Book "Peter Shirley: Fundamentals of Computer Graphics".
CGTalk Moderation
05232005, 09:05 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.
vBulletin v3.0.5, Copyright ©20002014, Jelsoft Enterprises Ltd.