Ortho Projection Without D3DX??

Started by
7 comments, last by ozone_blue 22 years, 8 months ago
Does anyone know how to set up an orthogonal projection matrix without using the D3DX files? Is there a way to do without the D3DX files? ozone_blue
Advertisement
Try this :



    D3DMATRIX7 d3dMatrix;

    float fAspect = ((float)dwHeight)/((float)dwWidth);
    float fTemp = (sinf(fFOV/2.0f) / (sinf(fFOV/2.0f) * fZoom));

    float w = fAspect * fTemp;
    float h = fTemp;

    IdentityMatrix(&d3dMatrix);
    d3dMatrix._11 = w;
    d3dMatrix._22 = h;
    d3dMatrix._33 = 0.0f;
    d3dMatrix._43 = 1.0f;

    lpD3DDevice->SetTransform(D3DTRANSFORMSTATE_PROJECTION, &d3dMatrix);



"NPCs will be inherited from the basic Entity class. They will be fully independent, and carry out their own lives oblivious to the world around them ... that is, until you set them on fire ..." -- Merrick

"It is far easier for a camel to pass through the eye of a needle if it first passes through a blender" -- Damocles

Edited by - Merrick on August 9, 2001 8:12:02 PM
"NPCs will be inherited from the basic Entity class. They will be fully independent, and carry out their own lives oblivious to the world around them ... that is, until you set them on fire ..." -- Merrick
Just curious - why?

For basic math stuff, the D3DX functions are highly recommended. I''m not sure why one would avoid them...
Author, "Real Time Rendering Tricks and Techniques in DirectX", "Focus on Curves and Surfaces", A third book on advanced lighting and materials
for example, like me, not using M$ VC++ with DirectX, so D3DX utility lib may not compile correctly...

it''s sad for non-M$ VC++ users...
I changed d3dutil.cpp to do what Merrick posted.

D3DX justs adds unncessary overhead to your project.

The tutorial is at The Rabbit Hole.

Ben

[Icarus Independent | Jump Down The Rabbithole | Tombstone: Vendetta ]
Thanks for the help, guys. To double check, though, my matrix should simplify to something that looks like this (right?):

[ ar*q 0 0 0 ]

[ 0 q 0 0 ]

[ 0 0 0 0 ]

[ 0 0 1 1 ]

Where:
q = 1 / fzoom
ar = dwHeight / dwWidth


I needed it because I am working in d3dim, and didn''t want to have to deal with the overhead from d3dx if I was just taking one orthographic projection matrix.
Thanks again.


ozone_blue
Umm, what overhead?

D3DX is just a static lib providing some convenience functions. It doesn''t add any overhead to your code. A good linker will only include the functions you actually use into the exe file, so if you only use D3DXOrthoMatrix (whatever it''s called), then that is the only part of D3DX that will be included in yuor exe file.

D3DX is nothing like the old D3DRM if that''s what you think.
Agreed. Supposedly, the D3DX functions have optimizations for MMX, 3DNow, etc. So even if there is overhead, it''s probably worth it...
Author, "Real Time Rendering Tricks and Techniques in DirectX", "Focus on Curves and Surfaces", A third book on advanced lighting and materials
Maybe he just wants matrix routines that are portable in case someday he wants to use a differant API.

ECKILLER
ECKILLER

This topic is closed to new replies.

Advertisement