Skip to main content
gamedev.net
🔒 Locked 🎮 Unity

Matrix stack

Started by keihun Apr 10, 2008 at 6:35 AM 2 replies 600+ views
Original Post
keihun
keihun
Hi! I'm writing an application which generates a tree. Every node calculates its position, length and vector based on its parent node. And it is working. I simply initalize a line for every treenode and then draw it with directx. My problem with that: it is too static. I have a tree where every node based on the parent node, so if I transform the matrix of the parent I can get the child. So I made a STL stack wih D3DXMATRIX. The child reads with top(). Next is the transformation. But my tree simply falling apart, when I do this. When the drawing is based on absolute coordinates, there is no problem. What I'm doing: 1. read the matrix of the parent 2. translate that matrix with the length of the parent, so I'm at the endpoint. 3. rotate with the angle between the parent and the child 4. draw a line 5. push the matrix And then going to the grandchild. And repeat. However the angles are good the nodes are separeted with space, which size is growing with the depth of the tree. I really can't figure out what have I done wrong. I hope you can.
Adam_42
Adam_42
Try swapping steps 2 and 3.
keihun
keihun
Unfortunately, it makes things worse.
Buckeye
Buckeye
I'm not sure what your code actually looks like but it should be something like:

rotMat = child's rotation with respect to parent
transMat = child's translation with respect to parent

childMat = rotMat * transMat * parentMat

You don't need to get any information from the parent's matrix. The matrix mutliplication will take care of that.

Except for the root matrix (which positions and rotates the tree in world space), all rotations and translations should be local, i.e., with respect to the parent.
Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly. You don't forget how to play when you grow old; you grow old when you forget how to play.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.