Archived

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

DXplayah

D3DX or not

Recommended Posts

I just started trying to learn DX again, now DX 8. My problem is I can''t decide wether or not to use D3DX. I''m sort of the "reinvent the wheel" type of guy. I''ve allready written X/Y/Z rotation matrix routines based of D3DMATRIX (not D3DXMATRIX) but all samples and tutorials I find and so forth use D3DXMATRIX and the equivalent D3DXMatrixRotateY or what the function is. The reason I''m starting to think about using D3DX is that now I have to write functions to set view/projection matrices etc that means I have to write the matrix functions + vector functions (normalizing etc). So my question is. What positive effects does having ie a D3DMATRIX *ml_MatrixRotateX own made function have over just slamming inn a D3DX version of it and also a full mathlib. A positive effect I can think of is that I will get better at 3d maths in general because I will be writing the code myself and understanding it better. And could someone please point me to tutorials/source/examples of setting up the world/projection/view etc matrices WITHOUT D3DX? Cause I don''t want to use ie the LookAtLh D3DX func etc. Thanks in advance =)

Share this post


Link to post
Share on other sites
As a learning excersise, it is well worth writing your own math routines, especially more complex things like intersection tests etc (which are covered to a lesser extent by the d3dx math libs anyway). As for setting up the projection and view matrics, theres loads of info in the SDK about that, so that should be your first port of call.

Once you''re up to speed with your maths, then I can whole heartedly recommend using d3dx. Version 8.1 has been optimised greatly to benefit from any cool instructions your CPU might support, and is pretty damn fast.

As an example, I tried optimising a matrix invert routine myself, even to the point of using a little SSE assembly, and researched it quite a lot. In a comparison with the d3dx matrix invert func, mine was a tad slower, AND a tad less accurate. (The test I did multiplied a matrix with its inverse, so I could see how far it deviated from the identity.) I''ll be the first to admit, im pretty bad at low level optimisation like that, and I started with only a tiny bit of x86 asm knowledge. Even so, I think, unless you are very talented at such coding, you''d be foolish not to consider using the d3dx math functions.

T

Share this post


Link to post
Share on other sites
The d3dx8.l libraries are faster eh? I guess I am going to have to reverse-engineer them to work with dx7

If the types and function symbols are the same, then I could just swap the OBJ files in the LIB. I may have to h4x0r the cpu detection function though, it probably looks at an external variable

Writing your own functions is ok to learn, but the d3dx functions make it so much faster to get started

Share this post


Link to post
Share on other sites
Don't rely on D3DX with your life. If for some fluke, Microsoft decided to remove it in the next version, a lot of people would be screwed over because they depend on it too much. I completely agree that you should use it because D3DX is fast and optomised like heck. What I do is code out anything that D3DX supports before using it so that if it were to be removed, I could use my slower but working code. That's what I would recommend but you may go the way of just using it's functionality. It just depends on whether you really have the time and to want to have the abilities and credit for creating the code yourself.

Edit: As for tutorials on using matrices and transforms yourself, the SDK has code samples of creating projection matrices by hand and such. Also, www.drunkenhyena.com has tutorials on using matrices without D3DX.

[edited by - RapidStunna on June 6, 2002 4:30:34 PM]

Share this post


Link to post
Share on other sites
I haven''t found anything in SDK but I probably haven''t looked good enough

I have written rotation, translation and scaling functions myself. I know how to do those. Also know how to do basic 3d math from school such as dot and cross product, plane intersection, vector scaling, products and so forth. I guess I''ll use D3DX now and if for some reason they are removed later I will finnish writing my mathlib.

Share this post


Link to post
Share on other sites
I remember reading that the D3DX8.1 functions are a lot more optimized than those in D3DX8.0.

Can anyone confirm or discredit this? 8.1 may have just added optimizations for 3DNow. I cannot remember anymore.

--TheMuuj



[edited by - themuuj on June 6, 2002 5:09:51 PM]

Share this post


Link to post
Share on other sites
Ok I finished hacking it! all I did was copy the OBJ files related to the math functions out of the DX8.1 LIB file into a custom one. Of cource I poked around the dissasembler a bit to see what I was up against

It is very optimized, it uses a jump table that points to different functions optimized for 3dnow, sse, sse2 and plain x86. The function interface and structures are IDENTICAL so it works perfect in dx7. The only problem is the projection matrix function broke, so now the aspect ratio is wrong!

Too bad the math library alone is 200kb. The dx8.1 library is 4 times larger than the dx7 one! They even have the ZLIB and PNG libraries included!

Share this post


Link to post
Share on other sites
quote:
Original post by Cybertron
The only problem is the projection matrix function broke, so now the aspect ratio is wrong!



Flip your Width and Height. It used to be backwords, now it is correct. FYI, D3DX9 is 60-70% bigger then D3DX8. Because these are libs, however, only those functions which you refrence will end up in your final exe.





Share this post


Link to post
Share on other sites
I just wish function-level-linking was used in the library

Here are the object lists. As you can see the DX8 one is freakin'' huge!

d3dx.lib (dx7 version)

  
obj\i386\d3dx.res
obj\i386\ccapsfile.obj
obj\i386\cd3dxfile.obj
obj\i386\sprite.obj
obj\i386\reglines.obj
obj\i386\regblts.obj
obj\i386\convert.obj
obj\i386\convhelp.obj
obj\i386\d3du.obj
obj\i386\texpick.obj
obj\i386\texture.obj
obj\i386\helper.obj
obj\i386\d3duexcept.obj
obj\i386\cd3ducontext.obj
obj\i386\calloc.obj
obj\i386\chelinfo.obj
obj\i386\cd3dudevice.obj
obj\i386\cddrawdevice.obj
obj\i386\cd3duglobals.obj
obj\i386\init.obj
obj\i386\pchcore.obj
obj\i386\shapes.obj
obj\i386\vbwrap.obj
obj\i386\teapot.obj
obj\i386\pchshape.obj
obj\i386\cstack.obj
obj\i386\d3dumath.obj
obj\i386\pchmath.obj


d3dx8.lib (dx8.1 version)

  
obj\i386\d3dx.res
objf\i386\ssefasttable2.obj
objf\i386\d3dxtrigsse2.obj
objf\i386\d3dxquatsse2.obj
objf\i386\d3dxmathsse2.obj
objf\i386\pchintel.obj
objf\i386\ssefasttable.obj
objf\i386\d3dxtrigsse.obj
objf\i386\d3dxquatsse.obj
objf\i386\d3dxmathsse.obj
objf\i386\pchintel.obj
.\Release\math.obj
.\Release\math_lib.obj
objd\i386\x3d_vec4.obj
objd\i386\x3d_vec3.obj
objd\i386\x3d_vec2.obj
objd\i386\x3d_quat.obj
objd\i386\x3d_matx.obj
objd\i386\x3d_plane.obj
objd\i386\d3dxmathx3d.obj
objd\i386\pchamd.obj
obj\i386\zutil.obj
obj\i386\uncompr.obj
obj\i386\trees.obj
obj\i386\maketree.obj
obj\i386\infutil.obj
obj\i386\inftrees.obj
obj\i386\inflate.obj
obj\i386\inffast.obj
obj\i386\infcodes.obj
obj\i386\infblock.obj
obj\i386\gzio.obj
obj\i386\deflate.obj
obj\i386\crc32.obj
obj\i386\compress.obj
obj\i386\adler32.obj
obj\i386\pngwutil.obj
obj\i386\pngwtran.obj
obj\i386\pngwrite.obj
obj\i386\pngtrans.obj
obj\i386\pngwio.obj
obj\i386\pngrio.obj
obj\i386\pngmem.obj
obj\i386\pngerror.obj
obj\i386\pngrutil.obj
obj\i386\pngrtran.obj
obj\i386\pngpread.obj
obj\i386\pngread.obj
obj\i386\pngget.obj
obj\i386\pngset.obj
obj\i386\png.obj
obj\i386\mem-simp.obj
obj\i386\normal.obj
obj\i386\priority.obj
obj\i386\dict.obj
obj\i386\tessmono.obj
obj\i386\tess.obj
obj\i386\sweep.obj
obj\i386\render.obj
obj\i386\mesh.obj
obj\i386\errorstr.obj
obj\i386\geom.obj
obj\i386\pffst.obj
obj\i386\pfint.obj
obj\i386\pifst.obj
obj\i386\piint.obj
obj\i386\mffst.obj
obj\i386\mfint.obj
obj\i386\mifst.obj
obj\i386\miint.obj
obj\i386\jutils.obj
obj\i386\jquant2.obj
obj\i386\jquant1.obj
obj\i386\jmemnobs.obj
obj\i386\jmemmgr.obj
obj\i386\jidctred.obj
obj\i386\jidctint.obj
obj\i386\jidctfst.obj
obj\i386\jidctflt.obj
obj\i386\jerror.obj
obj\i386\jdtrans.obj
obj\i386\jdsample.obj
obj\i386\jdpostct.obj
obj\i386\jdphuff.obj
obj\i386\jdmerge.obj
obj\i386\jdmaster.obj
obj\i386\jdmarker.obj
obj\i386\jdmainct.obj
obj\i386\jdinput.obj
obj\i386\jdhuff.obj
obj\i386\jddctmgr.obj
obj\i386\jdcolor.obj
obj\i386\jdcoefct.obj
obj\i386\jdapistd.obj
obj\i386\jdapimin.obj
obj\i386\jcomapi.obj
obj\i386\d3dx8tex.obj
obj\i386\cd3dximage.obj
obj\i386\cd3dxlock.obj
obj\i386\cd3dxblt.obj
obj\i386\cd3dxcodec.obj
obj\i386\dxtn.obj
obj\i386\pchtex.obj
obj\i386\fontextr.obj
obj\i386\fontoutl.obj
obj\i386\shapes.obj
obj\i386\pchshape.obj
obj\i386\loadx.obj
obj\i386\meshutil.obj
obj\i386\cleanmesh.obj
obj\i386\intersect.obj
obj\i386\btri.obj
obj\i386\loadutil.obj
obj\i386\createmesh.obj
obj\i386\quadric.obj
obj\i386\pchmesh.obj
obj\i386\cstack.obj
obj\i386\cpudetect.obj
obj\i386\d3dxmathx86.obj
obj\i386\d3dxmath.obj
obj\i386\pchmath.obj
obj\i386\d3dx8effect.obj
obj\i386\ceffect.obj
obj\i386\ctechnique.obj
obj\i386\cpass.obj
obj\i386\cassignment.obj
obj\i386\cparameter.obj
obj\i386\cvalue.obj
obj\i386\cdeclaration.obj
obj\i386\ccompiler.obj
obj\i386\pcheffect.obj
obj\i386\cd3dxassembler.obj
obj\i386\cd3dxstateblock.obj
obj\i386\cd3dxstack.obj
obj\i386\cd3dxrendertoenvmap.obj
obj\i386\cd3dxrendertosurface.obj
obj\i386\cd3dxresource.obj
obj\i386\cd3dxfile.obj
obj\i386\cd3dxbuffer.obj
obj\i386\cd3dxsprite.obj
obj\i386\cd3dxtext.obj
obj\i386\cd3dxfont.obj
obj\i386\d3dx8dbg.obj
obj\i386\d3dx8core.obj
obj\i386\init.obj
obj\i386\pchcore.obj

Share this post


Link to post
Share on other sites
After reading this, i think i might switch to D3DX....

BTW, to set the projection / view matrix (non-D3DX)
(assuming CVector is a class with members x, y & z)

  
void SetViewMatrix(LPDIRECT3DDEVICE8 pDevice, CVector vPos, CVector vLookat)
{
D3DMATRIX mMatrix;
CVector vForward = (vLookat - vPos).Normalize();
CVector vRight = (CrossProduct(CVector(0,1,0),vForward)).Normalize();
CVector vUp = (CrossProduct(vForward,vRight)).Normalize();

mMatrix[0][0] = vRight.x;
mMatrix[1][0] = vRight.y;
mMatrix[2][0] = vRight.z;
mMatrix[3][0] = 0;
mMatrix[0][1] = vUp.x;
mMatrix[1][1] = vUp.y;
mMatrix[2][1] = vUp.z;
mMatrix[3][1] = 0;
mMatrix[0][2] = vForward.x;
mMatrix[1][2] = vForward.y;
mMatrix[2][2] = vForward.z;
mMatrix[3][2] = 0;
mMatrix[3][0] = -DotProduct(vRight,vPos);
mMatrix[3][1] = -DotProduct(vUp,vPos);
mMatrix[3][2] = -DotProduct(vForward,vPos);
mMatrix[3][3] = 1;

pDevice->SetTransform(D3DTS_VIEW,mMatrix);
}

void SetProjMatrix(LPDIRECT3DDEVICE8 pDevice, float dvNearClip, float dvFarClip, float dvFov)
{
D3DMATRIX mMatrix;
const float fFovCos = (float)cos(dvFov*0.5);
const float fFovSin = (float)sin(dvFov*0.5);
const float Q = fFovSin/(1 - dvNearClip/dvFarClip);

mMatrix[0][0] = fFovCos;
mMatrix[0][1] = 0;
mMatrix[0][2] = 0;
mMatrix[0][3] = 0;
mMatrix[1][0] = 0;
mMatrix[1][1] = fFovCos;
mMatrix[1][2] = 0;
mMatrix[1][3] = 0;
mMatrix[2][0] = 0;
mMatrix[2][1] = 0;
mMatrix[2][2] = Q;
mMatrix[2][3] = fFovSin;
mMatrix[3][0] = 0;
mMatrix[3][1] = 0;
mMatrix[3][2] = -Q*dvNearClip;
mMatrix[3][3] = 0;

pDevice->SetTransform(D3DTS_PROJECTION,mMatrix);
}
[source]

2p
Steve


Steve
DirectX Programmer
Soon to be the new Bill Gates

Share this post


Link to post
Share on other sites