#### Archived

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

# D3DX or not

## Recommended Posts

DXplayah    122
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 on other sites
Tessellator    1394
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 on other sites
DXplayah    122
Ok thanks =) Then I guess I''ll use the damn D3DX lib

That just speeded up my coding progress a great deal

##### Share on other sites
okonomiyaki    548

##### Share on other sites
Cybertron    122
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 on other sites
RapidStunna    122
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 on other sites
DXplayah    122
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 on other sites
TheMuuj    122
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 on other sites
Cybertron    122
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 on other sites
DrunkenHyena    805
The D3DX 8.1 is significantly larger than the 8.0 version. I think having 5 or so version of every commonly used function has something to do with it.

Stay Casual,

Ken
Drunken Hyena

##### Share on other sites
EvilDecl81    360
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 on other sites
Cybertron    122
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.resobj\i386\ccapsfile.objobj\i386\cd3dxfile.objobj\i386\sprite.objobj\i386\reglines.objobj\i386\regblts.objobj\i386\convert.objobj\i386\convhelp.objobj\i386\d3du.objobj\i386\texpick.objobj\i386\texture.objobj\i386\helper.objobj\i386\d3duexcept.objobj\i386\cd3ducontext.objobj\i386\calloc.objobj\i386\chelinfo.objobj\i386\cd3dudevice.objobj\i386\cddrawdevice.objobj\i386\cd3duglobals.objobj\i386\init.objobj\i386\pchcore.objobj\i386\shapes.objobj\i386\vbwrap.objobj\i386\teapot.objobj\i386\pchshape.objobj\i386\cstack.objobj\i386\d3dumath.objobj\i386\pchmath.obj

d3dx8.lib (dx8.1 version)

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

##### Share on other sites
Metasquares    122
I''m probably restating what was already said by at least 5 other people, but...

Use it, but know how not to use it.

##### Share on other sites
Evil Bill    126
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]2pSteve

Steve
DirectX Programmer
Soon to be the new Bill Gates