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
Modifying D3DUtil_SetProjectionMatrix for ortho
Just check out those structures: D3DXMatrixOrthoLH & D3DXMatrixOrthoOffCenterLH.
Wouldn''t it be easier...
Wouldn''t it be easier...
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
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
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:
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!)
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!)
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
http://therabbithole.redback.inficad.com
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
at my site
http://therabbithole.redback.inficad.com
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
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement