#### Archived

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

# Source code for D3DX math functions

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

## 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 on other sites
Just look in the header files.

##### 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 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 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 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

1. 1
2. 2
Rutin
19
3. 3
4. 4
khawk
15
5. 5
A4L
13

• 13
• 26
• 10
• 11
• 44
• ### Forum Statistics

• Total Topics
633743
• Total Posts
3013644
×