Archived

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

Source code for D3DX math functions

This topic is 5648 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Does anyone have the source for the D3DX math functions? Specifically I am look for the source of D3DXVec3Transform and D3DXVec3TransformNormal. I need to know exactly what they do to be able to figure out my mistakes in porting Brett Porter''s ms3d animation code to D3D.

Share this post


Link to post
Share on other sites
I don''t have the source, but it should be plain vector maths:

VecTransform:
float x = V.x;
float y = V.y;
float z = V.z;
float w = 1;
out.x = x*m._11 + y*m._21 + z*m._31 + w*m._41
out.y = x*m._12 + y*m._22 + z*m._32 + w*m._42
out.z = x*m._13 + y*m._23 + z*m._33 + w*m._43
out.w = x*m._14 + y*m._24 + z*m._34 + w*m._44

VecTransformNormal:
float x = V.x;
float y = V.y;
float z = V.z;
out.x = x*m._11 + y*m._21 + z*m._31
out.y = x*m._12 + y*m._22 + z*m._32
out.z = x*m._13 + y*m._23 + z*m._33

The above should give exactly the same results...


--
Simon O''Connor
Creative Asylum Ltd
www.creative-asylum.com

Share this post


Link to post
Share on other sites
okonomiyaki: Please take a look at them yourself before giving an answer like that. If you take a good look you''ll notice that some functions are inlined while others aren''t. The two functions I asked for are in the latter category.

s1ca: Thanks. This is what I was thinking too, but I just would like to be sure that that is the case.

Share this post


Link to post
Share on other sites
quote:
s1ca: Thanks. This is what I was thinking too, but I just would like to be sure that that is the case.


The simplest way to check would be to put both functions (D3DX and a hand written one) up against each other and compare the outputs. You could even do an automated check which created random vectors and matrices and do a memcmp() between the results if you were really paranoid

On some CPUs there may be a tiny difference in precision and rounding between the straight C++ code and the version used by D3DX - this is due to the fact that D3DX will use 3DNow!, SSE or SSE2 where present to do some matrix/vector maths.

IIRC there''s a registry key to disable PSGP (Processor Specific Graphics Pipeline) in D3DX to force it to use the straight scalar FPU instructions.


--
Simon O''Connor
Creative Asylum Ltd
www.creative-asylum.com

Share this post


Link to post
Share on other sites
Thank you s1ca! After a bit of testing I have finally come to terms with that it is probably as you suggested. However, this means that I must now seek the bug in my program somewhere else

Share this post


Link to post
Share on other sites