Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

Looooong story short I'm essentially trying to code Mode 7 in XNA. Before I continue bashing my brains out in research and various failed matrix math equations; I just want to make sure that XNA supports this just out-of-the-box (so to speak).

I'd prefer not to have to import other libraries, because I want to learn how it works myself that way I understand the whole thing better. However that's all for naught if it won't work at all. So no opengl, directx, etc if possible (will eventually do it just to optimize everything, but not for now).

tl;dr: Can I has Mode 7 in XNA?

share|improve this question

1 Answer 1

up vote 2 down vote accepted

You can pass an arbitrary 4x4 matrix to SpriteBatch.Begin (MSDN) - it doesn't even have to be affine (but it can be if you leave the extra elements set to the identity matrix). This transformation will be applied to all the sprites that you draw within that batch.

You can build the matrix by hand, or use the helpful Create* methods on the Matrix type (MSDN). I think for the classic perspective plane effect you need to create the matrix by hand - I'll let you figure out the actual maths involved ;)

(Just remember that XNA's Matrix type is row vector, M41 and M42 are the X and Y translation elements.)

Remember that SpriteBatch draws its sprites, by default and after transformation, in "client space" - (0,0) in the top left, (width,height) in the bottom right. But you can have a completely arbitrary projection by using a custom effect - this is actually easier if you're trying to draw sprites in 3D space, because you can just use a real perspective projection matrix (instead of the built-in orthographic client one) and you can use the built-in creation methods.

share|improve this answer
    
Hey, thanks! I really appreciate this answer! I haven't given it a try yet but I definitely will ASAP =) –  BCqrstoO Sep 17 '12 at 23:34

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.