views:

86

answers:

1

XNA has the following Matrix objects under BasicEffect

public Matrix World
public Matrix View
public Matrix Projection

OpenGL uses the following defines for glMatrixMode()

GL_MODELVIEW
GL_PROJECTION

I'm not really sure why one would have more than the other, to be honest. I'm porting a GL game over, and it would be nice if I could get an explanation of the similarities and differences.

Does World = GL_MODELVIEW, or does View = GL_MODELVIEW?

What would I do to render the same scene, just load an Identity Matrix into the one I don't use?

Thanks alot!

+1  A: 

The name of GL_MODELVIEW is a reflection of the fact that it represents both the view of a scene and the transformations applied on the world, since these transformations are opposites (translating the camera 5 units left equals translating the world 5 units right). I am not sure what XNA's matrices represent, but I think that XNA simply represents these transformations as two different matrices. For porting you game, then, you would have your camera apply its transformation to the View Matrix, and other things apply transformations to the Model matrix. (Please correct me if I am wrong.)

http://www.toymaker.info/Games/XNA/html/xna_matrix.html describes what the XNA matrices represent.

l33tnerd
Can do.. I guess it would be great if there was a way to wrap the methods of GL around XNA, and create that extra matrix out of the two that I have instanced, if that's even possible... My gut sorta says it can, but my brain says "............"
Kyle
If you want to merge the View and World matrices, multiplying the view by the Model matrix (in that order) should work (since then the camera transform would be applied first). XNA might not like that, however.
l33tnerd
Well I guess what I need is to have my code keep using just the two matrix stacks as it was, and sort of display in same same fashion as it did on GL by creating that World matrix separate.. I'll try a few things and report back.
Kyle
The order that you multiply matrices is opposite in XNA from openGL. openGL uses column major matrices and XNA uses row major matrices. One odd but interesting ramification of this is an opposite-ness in the proper order of concatenating them. In XNA you would typically write: Matrix modelView = modelMatrix * viewMatrix; I'm not sure if that's how you meant to mean it anyway I33tnerd, but I thought I'd point it out. Also, if you intend to use the built in 'BasicEffect' in xna, you have to pass the two matrices to the effect separately anyway so it doesn't make sense to combine them.
Steve H
Ah, thanks. I never knew that, having only learned OpenGL.
l33tnerd