MatrixStack problem

Started by
9 comments, last by acid2 19 years, 2 months ago
Hi, I'm having some problems using the MatrixStack class in MDX (I guess it applies to normal DX aswell). The code I use to update the stack is as below.

		public void UpdateMatrices()
		{
			manager.World.Push();
			manager.World.MultiplyMatrix(Matrix.Scaling(Scale) * Matrix.RotationQuaternion(OrientationQuat)
                * Matrix.Translation(Location));
			world = manager.World.Top;
			foreach(SceneGraphNode child in children)
				child.UpdateMatrices();

			manager.World.Pop();
		}

However, If I have a root node at [0, 0, 5] and a child node at [0, 2, 0] the child is node is displayed it [0, 2, 0] - not [0, 2, 5] as I think it should be. Am I doing something wrong? All of the update calls are being accessed as expected, and the mesh is rendered at the "world" position (defined in the source above. Thanks, - aCiD2
Ollie"It is better to ask some of the questions than to know all the answers." ~ James Thurber[ mdxinfo | An iridescent tentacle | Game design patterns ]
Advertisement
** Bump *** :)
Ollie"It is better to ask some of the questions than to know all the answers." ~ James Thurber[ mdxinfo | An iridescent tentacle | Game design patterns ]
Another bump :P
Ollie"It is better to ask some of the questions than to know all the answers." ~ James Thurber[ mdxinfo | An iridescent tentacle | Game design patterns ]
Granted, the code seems a bit cryptic to me 'cause I don't know anything about managed programming. And when it comes to math, I describe myself as 'sly as a fox with a plastic baggie on its head'. But...

I don't see where you are applying the root node's position to the child's.
The way I follow it:
-You push a matrix onto the stack (it should be identity, right?)
-you multiply scaling; some form of quaternion rotation that I don't entirely understand (is this where the root node applies itself to the child?); and translation; then multiply the result to the world matrix from the last step
-store the new result in some variable called 'matrix'
-perform some kind of loop, where this function is called recursively on each child (?)

What is the matrix 'world'? Where else is it used? And where exactly are the effects of the parent being applied to the child?

I'm not sure if this will help or not (since I really don't know what I'm talking about ;) But I hate to leave unanswered questions on the board, especially after two bumps.
I first set the MatrixStack to an identity matrix. Then, I push this onto the stack and times that matrix by the scaling, rotating (RotationQuaternion just converts a quaternion into a matrix) and trnasformation in _object_ space. Then, I peek the matrix stack and store it in the SceneGraph node (so I have the objects world space, useful for rendering meshs etc). In then repeat all that over again for all of the nodes children.

All of this is being accessed correctly, but something is being funny somewhere along the line :| Oh, and there's nothing wrong with the "Matrix.Scaling(Scale) * Matrix.RotationQuaternion(OrientationQuat) * Matrix.Translation(Location)" to my knowledge - it works fine because I used it for the time before I had a scene graph in.
Ollie"It is better to ask some of the questions than to know all the answers." ~ James Thurber[ mdxinfo | An iridescent tentacle | Game design patterns ]
I must not being getting 'the big picture' here. I still don't see how the child is translated to it's parent's coordinates. Is that in another part of the scenegraph? The rendeer perhaps? Or maybe it's a feature of the recursion that I just don't see.

In other words:
Quote:
Then, I peek the matrix stack and store it in the SceneGraph node

I take it, by this you mean the variable 'world'? How is that applied to the childeren?

[edit]Typo, I said 'matrix' when I meant 'world'
[/edit]
When you push something onto the MatrixStack its meant to multiply it by things already in the stack, thats why MatrixStack (IDXMatrixStack in c++?) is different from a normal stack.
Ollie"It is better to ask some of the questions than to know all the answers." ~ James Thurber[ mdxinfo | An iridescent tentacle | Game design patterns ]
Ooops [embarrass] I get it now. Sorry.

Is the data (matrix) being stored and used in the rest of the scenegraph properly?
Yea, because if I dont parent nodes to the graph it displays fine (well, displays fine if all nodes are attached to the root node which is just an identity matrix)
Ollie"It is better to ask some of the questions than to know all the answers." ~ James Thurber[ mdxinfo | An iridescent tentacle | Game design patterns ]
From what I can tell, there is nothing wrong with the code you posted. There isn't like, an overloaded version of the MatrixStack::MultiplyMatrix() function is there? Actually, come to think of it: in ID3DXMatrixStack, there are two versions. One gets the product of the current matrix multiplied by the given, and one gets the product of the given matrix multiplied by the current. Are you using the wrong one perhaps?

This topic is closed to new replies.

Advertisement