tags:

views:

212

answers:

1

If I want a orthograpic view of the region (-10,-1),(-2,-1),(-2,-7),(-10,-7) how do I define the view and projection matrices? (I set the world matrix to identity). I tried this but it did not work:

worldMatrix = Matrix.Identity;
projectionMatrix = Matrix.CreateOrthographicOffCenter(-10,-2,-7,-1,-1.0f,100.0f);
viewMatrix = Matrix.CreateTranslation(1, -1, 0) * Matrix.CreateScale(400,-300,1);

I was assuming this transformation order: (is it correct ?)

screenPoint = worldPoint*worldMatrix*projectionMatrix*viewMatrix

My motivation for this is that the projectionMatrix transforms the world box to normaliced device coordinates:(-10,-1)->(-1,1), (-2,-1)->(1,1), (-2,-7)->(1,-1), (-10,-7)->(-1,-1) and I then move this unity square to the fourth quadrant an scale it to screen size (800x600) and flip the y direction. But I am doing things wrong because I can't see nothing.

+2  A: 

Resolved!

My problem was that I mistook the view transformation for a viewport transformation, i.e should map -1 .. 1 to screen.

But viewport transformations is never talked about in xna, they are implicit. This insight helped a lot. The solution turned out to be embarrassingly simple:

worldMatrix = Matrix.Identity; 
viewMatrix = Matrix.Identity; 
projectionMatrix = Matrix.CreateOrthographicOffCenter(-10, -2, -7, -1, -1.0f, 100.0f);
lgwest