Orthographic projection

Started by
5 comments, last by GroZZleR 18 years, 8 months ago
Ok, I've been searching for about 5 days now and I can't find any tutorials on orthographic projections. I had read somewhere that there was a sample that comes with directx, but I can't seem to find that either (I'm using DirectX9.0b). I had a scene setup a perspective projection that had tiles that were 1x1units in size. When I changed the projection matrix to an orthographic they look time now. So I tried making them bigger (32x32units) and that didn't work. It still looked time at 400x400 (they were bigger, but they were still small.) I've never used an orthographic projection and I can't seem to find any tutorials on it. Could somebody help me please? Thanks! PS: This is in C++ and DirectX9.0b
Advertisement
When you get into orthomode you're setting it up so that one unit = one pixel and depth doesnt change size.

you should post your code that looks like this:
float sw, sh, zn, zf; // these are screen width, heigh, Z near, farD3DXMATRIX prj;D3DXMatrixOrthoLH(&prj, sw, sh, zn, zf);device->SetTransform(D3DTS_PROJECTION, prj);
Ok, my code is:
D3DXMATRIX ProjMtx;D3DXMatrixIdentity(&ProjMtx);D3DXMatrixOrthoLH(&ProjMtx, 800.0f, 600.0f, 1.0f, 1000.0f);g_pDevice->SetTransform(D3DTS_PROJECTION, &ProjMtx);
Quote:Original post by chad_420
When you get into orthomode you're setting it up so that one unit = one pixel and depth doesnt change size.

Not necessarily. I use orthogonal projection matricies pretty much exclusively, but I always make the rance -0.5 to 0.5 or 0.0 to 1.0 or something like that.
Orthographic projections are so simple, they're wierd. I think the problem you are having is that the d3dx function expects inputs in view space coordinates.

These are typically of the same scale as world space coordinates. It looks like you are passing in screen space. 800 and 600 goes in the viewport.

Here is a snippet from my engine, where I am fitting a character's bounding box ( in world/view coords ) into an ortho projection.

float width  = max( 16.0f, 1.5f * ( aBox.Max.x - aBox.Min.x ) );float height = max( 16.0f, 1.5f * ( aBox.Max.z - aBox.Min.z ) );D3DXMatrixOrthoLH( &mCamera.mProjectionMatrix, width, height, anear, afar );


So, just figure out how many world units should be visible across & down in the view, and make that the width & height.
Thanks SimmerD! I've never used orthographic projections and I can't seem to find anything on them, so I just figured that it was asking for screen space width and height.
You might also want to look at D3DXMatrixOrthoOffCenterLH. You can create a more familiar projection matrix where (0,0) is the top left and increased Y is lower on the screen.

This topic is closed to new replies.

Advertisement