Orthographic Clipping panes.

Started by
3 comments, last by TheNobleOne 18 years, 8 months ago
Ok here is what I am doing. I am creating a 2D engine where the resolution can vary depending on the user of the engine wish. The tiles are 32x32 pixles in size. I am using a z buffer for my layer system. Now first off I want my (0,0) position to be at the top left corner of the screen where pos y is down and pos x is right and pos z is facing the user. This is not the hard part. I just rotate the world matrix on the x axis by 180 degrees. My problem arises when setting up the projection matrix it takes all floats and I don't know what to put in it. obviously I want all the negative values 0.0f as I don't need them. Which should automatically put the world axis up in the top left corner of the screen. But how do I create the pos clipping panes? What values do I use? Also should I rotate the world before I set up the projection or after? BTW I am using MDX :P
My JournalComputer science education cannot make anybody an expert programmer any more than studying brushes and pigment can make somebody an expert painter. (Eric Raymond)"C makes it easy to shoot yourself in the foot. C++ makes itharder, but when you do, it blows away your whole leg."-- Bjarne Stroustrup
Advertisement
Think of the screen like this:
0;0                 10;0  +------------------+  |                  |  |                  |  |                  |  |                  |  |                  |  +------------------+0;8                10;8


Now, if you want to setup your projection so that it looks like the thing I tried to draw you'd do this:

D3DXMATRIX projMatrix;D3DXMatrixOrthoLH( &projMatrix, 10.0f, 8.0f, nearClipPlane, farClipPlane );


I think this example is pretty self-explainatory.

[edit]I never used MDX, but I believe you can find out how to do the equivalent.
ok I got the idea but screen coords go by pixels so how would I convert a float position to a pixel valued position so that I know how many tiles I can get on the screen? is there some formula like 0.1 f = 1 pixel type thing?
My JournalComputer science education cannot make anybody an expert programmer any more than studying brushes and pigment can make somebody an expert painter. (Eric Raymond)"C makes it easy to shoot yourself in the foot. C++ makes itharder, but when you do, it blows away your whole leg."-- Bjarne Stroustrup
It's pretty simple, instead of using 10.0f and 8.0f use the same values you used to create your backbuffer, then make sure your backbuffer is not being streched (sp?) or something, like having it display in a window bigger then the backbuffer or vice-versa.

But in my personal opinion you shouldn't make your game be "pixel aligned", that way you can zoom in/out and stuff. The only thing I'd "tolerate" (don't know a better word) that uses this in a modern 2D game is the HUD. But this is just my opinion.

[edit] btw, screen coordinates in Direct3D range from 0.0 to 1.0
[edit2] screen coordinates range from -1.0 to 1.0.. sorry, I need to sleep...
ok thanks a bunch.
My JournalComputer science education cannot make anybody an expert programmer any more than studying brushes and pigment can make somebody an expert painter. (Eric Raymond)"C makes it easy to shoot yourself in the foot. C++ makes itharder, but when you do, it blows away your whole leg."-- Bjarne Stroustrup

This topic is closed to new replies.

Advertisement