About the math functions from DirectX

Started by
6 comments, last by adriano_usp 20 years, 7 months ago
Hi All, I''m writing a collision routine and I have some doubts about DX functions. I can to make my own functions in C++ to calculate distances, planes, intersections, cross-product, normals... Sometimes, a DX function with many parameters calculates more things than I really need. So, my question is: Is there a good reason to use DX functions? Do DX functions (like D3DXVec3Cross, D3DXIntersect, D3DXPlaneIntersectLine,...) have a optimized code (for example: a piece written in assembly)? Thanks.
Advertisement
The Direct3DX functions are optimised for various CPU technologies like 3DNow and SSE.

Why you shouldn''t use iostream.h - ever! | A Good free online C++ book
Yes, they''re very optimal. Stick with D3DX math.

I like pie.
[sub]My spoon is too big.[/sub]
quote:Original post by adriano_usp
Is there a good reason to use DX functions?


Here''s the biggest reason: The DX math functions are written, maintained, and debugged by somebody else, liberating you from the tedium of reinventing the wheel.
John BoltonLocomotive Games (THQ)Current Project: Destroy All Humans (Wii). IN STORES NOW!
quote:Original post by siaspete
The Direct3DX functions are optimised for various CPU technologies like 3DNow and SSE.

Just a reminder: The C versions are, the C++ overloads aren''t (the C++ overloads are inlined in d3dx9math.inl, as far as I recall).


quote:Original post by Coder
Just a reminder: The C versions are, the C++ overloads aren''t (the C++ overloads are inlined in d3dx9math.inl, as far as I recall).

Though whenever the code is non-trivial, the C++ overload is just an inlined call to the optimized C code. The *= overload just calls D3DXMatrixMultiply, as an example.



Stay Casual,

Ken
Drunken Hyena
Stay Casual,KenDrunken Hyena
Hi, thanks all for reply.

Just one more doubt:

Supposes that you want to add two vectors.

In this simple case, should I still prefer to use

D3DXVec3Add(&v3,&v1,&v2)

than:

v3.x = v1.x + v2.x
v3.y = v1.y + v2.y
v3.z = v1.z + v2.z
or
v3 = v1 + v2 ?
If you are going to do many of them in a row, you should probably use the D3DX functions, as they will exploit SIMD cpu''s and do many additions at the same time!
CYer, Blitz

This topic is closed to new replies.

Advertisement