how worldmatrix stack works in DrawState?

Jun 16, 2010 at 10:08 AM

I tried to edit Tutorial 12 "advanced model  use".

now, Actor's Draw method is here.

public void Draw(DrawState state)
   //ModelInstances automatically setup the default material shaders
   //Custom shaders can be used with model.SetShaderOverride(...)
            Matrix world = Matrix.CreateTranslation(new Vector3(5, 5, 5));
            using (state.WorldMatrix.Push(ref world))



I expect that Model and Model's BoudningBox are moved.

at result, model is moved to 5,5,5. but model's bounding box is not moved.

how worldmatrix stack works exactly ?

Jun 16, 2010 at 10:48 AM
Edited Jun 16, 2010 at 11:10 AM

'Push' will replace the matrix on the top of the stack. PushMultiply will do the same, but will multiply with the current matrix on the top of the stack.

So by using Push you are saying 'replace the current matrix', with PushMultiply you are saying 'combine the current transform with the transform of this matrix'.

Unfortunately, the DrawBoundingBoxes method is using Push() instead of PushMultiply(). This is the source of the confusion.

When the stack is empty (ie, identity matrix), a call to Push() or PushMultiply produces identical results (and is just as fast).

Jun 16, 2010 at 12:04 PM

oh, i see. thanks for your reply.