• Advertisement
Sign in to follow this  

[DirectX9 C++] - D3DXVec3Normalize returns inaccurate results

This topic is 2896 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

Good day, I have found that by using D3DXVec3Normalize() an inaccurate result is returned. Theoretically a normalized vector pointing in the +y direction should be (0.0,1.0,0.0) However sometimes D3DXVec3Normalize() returns (0.0,0.99999994,0.0) This definitely isn't a normalized vector although the error is very small. Unfortunately this also leads to further errors, like comparing 2 vectors etc. Is there a way to get around this? Is there any better function than D3DXVec3Normalize which i can use? Thanx in advance, stakon

Share this post


Link to post
Share on other sites
Advertisement
That's a margin of error of 0.000006%, which is more than adequate for floating point values...

You can't directly compare floating point values anyway due to the way they work, I really wish operator== would give a warning. If you're comparing two floating point values, you should use an epsilon value anyway, e.g. instead of:
if(x == 1.0f)
Use:
static const float EPSILON = 0.00001f;
if(x > 1.0f-EPSILON && x < 1.0f+EPSILON)

Share this post


Link to post
Share on other sites
Thanx!

Such a warning would be useful indeed.

I think i'll use a slight variation of your method:

static const float EPSILON = 0.00001f;
float a,b; //floats to compare

if(abs(a - b) <EPSILON)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement