#### Archived

This topic is now archived and is closed to further replies.

# Modifying D3DUtil_SetProjectionMatrix for ortho

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

## Recommended Posts

  HRESULT D3DUtil_SetProjectionMatrix( D3DMATRIX& mat, FLOAT fFOV, FLOAT fAspect, FLOAT fNearPlane, FLOAT fFarPlane ) { if( fabs(fFarPlane-fNearPlane) < 0.01f ) return E_INVALIDARG; if( fabs(sin(fFOV/2)) < 0.01f ) return E_INVALIDARG; // FLOAT w = fAspect * ( cosf(fFOV/2)/sinf(fFOV/2) ); // FLOAT h = 1.0f * ( cosf(fFOV/2)/sinf(fFOV/2) ); // FLOAT Q = fFarPlane / ( fFarPlane - fNearPlane ); FLOAT w = 1.0f * ( cosf(fFOV/2)/sinf(fFOV/2) ); FLOAT h = 1.0f * ( cosf(fFOV/2)/sinf(fFOV/2) ); FLOAT Q = 1.0f / ( fFarPlane - fNearPlane ); ZeroMemory( &mat, sizeof(D3DMATRIX) ); // mat._11 = w; // mat._22 = h; // mat._33 = Q; // mat._34 = 1.0f; // mat._43 = -Q*fNearPlane; mat._11 = 2.0f/w; mat._22 = 2.0f/h; mat._33 = Q; mat._43 = -(fNearPlane * Q); mat._44 = 1.0f; return S_OK; } 
I'm directly modifying the SetProjectionMatrix routine just because it simplifies things greatly. It's almost correct. I got the equations off of an older thread posted by an Anon. That person left off the w and h equations and I was wondering if anyone knows what they should be. It mostly works as it is in that there's no Z but X and Y screen positions are still being incorrectly calculated. Thanks, Ben [/source] Edited by - KalvinB on January 25, 2001 2:15:58 PM

##### Share on other sites
Just check out those structures: D3DXMatrixOrthoLH & D3DXMatrixOrthoOffCenterLH.
Wouldn''t it be easier...

##### Share on other sites
I believe those are DX8 only. I''m using DX7. Also modifying the original code directly eliminates having to rewrite or add more code than I need to the game. It also gives me the opportunity to do any optimizing that might beable to be done.

Besides I''ve got most of the equations. It''s just barely off when I test it out. It''d be easier to finish up doing it this way than by researching a whole new method.

Ben

##### Share on other sites
1st - both functions are present in DX7, just check! (in D3DX)!!

2nd - in case you still do not trust those helpers, openGL defines an ortho projection matrix as follows:

  a 0 0 tx0 b 0 ty0 0 c tz0 0 0 -1

where:
a = 2/(right-left)*fAspect = fAspect
b = 2/(top-bottom) = 1
c = -1/(far-near)
tx= -(right+left)/(right+left) = 0
ty= -(top+bottom)/(top-bottom) = 0
tz= -(far+near)/(far-near) = -1

assuming:
right = -left = 1
top = -bottom = 1
near = 0
far = whatever

source: Microsoft (yes!)

##### Share on other sites
Thanks but I already knew about the OpenGL functions at MS. D3DX is just more code to add to a program that has as much as it needs concerning 3D functions.

at my site

under "Tricks of the game programming newbies" you''ll find a tutorial I wrote on doing orthogonal by modifying D3DUtil_SetProjectionMatrix directly. Which is easier once you know how to do it. So yeah, I figured it out. It just took actually working through the equations. Also since I know how it works, I can optimize as much as possible.

Thanks for looking into it though,

Ben

1. 1
Rutin
19
2. 2
3. 3
JoeJ
16
4. 4
5. 5

• 26
• 20
• 13
• 13
• 17
• ### Forum Statistics

• Total Topics
631700
• Total Posts
3001781
×