Archived

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

adriano_usp

About the math functions from DirectX

Recommended Posts

adriano_usp    396
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.

Share this post


Link to post
Share on other sites
JohnBolton    1372
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.

Share this post


Link to post
Share on other sites
Muhammad Haggag    1358
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).

Share this post


Link to post
Share on other sites
DrunkenHyena    805
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

Share this post


Link to post
Share on other sites
adriano_usp    396
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 ?

Share this post


Link to post
Share on other sites
Blitz_Krieg    122
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

Share this post


Link to post
Share on other sites