Jump to content
  • Advertisement
Sign in to follow this  
Programmer16

Orthographic projection

This topic is 4885 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
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, far
D3DXMATRIX prj;
D3DXMatrixOrthoLH(&prj, sw, sh, zn, zf);
device->SetTransform(D3DTS_PROJECTION, prj);

Share this post


Link to post
Share on other sites
Ok, my code is:

D3DXMATRIX ProjMtx;
D3DXMatrixIdentity(&ProjMtx);
D3DXMatrixOrthoLH(&ProjMtx, 800.0f, 600.0f, 1.0f, 1000.0f);
g_pDevice->SetTransform(D3DTS_PROJECTION, &ProjMtx);

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!