# D3DXVec3Normalize

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

## Recommended Posts

The D3DXVec3Normalize function isn't working for me. I put in vectors like this: D3DXVECTOR3(0.0f, 10000.0f, -2000.0f); and it gives me (0.0f, 0.0f, 0.0f). Not always, though. Every once in a while, one of the numbers will be 1. Did I set it so it rounds the floats to integers? Are the numbers too big or something? Please help!

##### Share on other sites
Some vectors are meant to be normalized (for instance, surface normals) and some vectors are NOT meant to be normalized (for instance, camera position in world space coordinates). That vector doesn't look like the type you should be normalizing in the first place. What are you using that vector for?

##### Share on other sites
D3DXVec3Normalize will handle your example vector correctly, so the problem must be somewhere in your code. Show us the code that returns the incorrect value and show us what the input values are that result in an incorrect value.

##### Share on other sites
I'm using the normal for terrain generation. Each quad of the terrain has a normal, which is generated from two vectors on the quad. The vectors are pretty big, so when I do a cross product, the normal is even bigger.

// build two vectors on the quad
D3DXVECTOR3 u = getUEntry(x, z);
D3DXVECTOR3 v = getVEntry(x, z);

// find the normal by taking the cross product of two
D3DXVECTOR3 n;
D3DXVec3Cross(&n, &u, &v);
D3DXVec3Normalize(&n, &n);
return n;

"getUEntry" returns one of the vectors on the quad, and "getVEntry" returns the other. "x" and "y" are the indices to the quad in the terrain. "n" looks fine all the way up to the point where it gets normalized.

##### Share on other sites
What values does n have when it enters D3DXVec3Normalize? Because your functions might make the crossproduct yeild a 0, 0, 0 vector and normalizing that would certainly result in a 0, 0, 0 =)

##### Share on other sites
Usually something like {2000.0f, 10000.0f, 1000.0f}. I thought maybe it's too big for DX or something, but I don't know...

##### Share on other sites
Well, just try to make tiny console app and see what happens if you use d3dxvec3normalize... if everything's still 0 i'd suggest reinstalling the sdk :S

i just wrote 3 lines of code and well, no problems here

D3DXVECTOR3 vec(100000.f, -200000.f, 100000.f);
D3DXVec3Normalize(&vec, &vec);
printf("x:%f, y:%f, z:%f\n", vec.x, vec.y, vec.z);

D3DXVECTOR3 Awww(D3DXVECTOR3* out, D3DXVECTOR3* in) { return D3DXVECTOR3(0.f, 0.f, 0.f); }

You never know ^_~

##### Share on other sites
No, no one redefined D3DXVec3Normalize. I know because I also tried this:

n /= D3DXVec3Length(&n);

And it gave me the same thing. Maybe I'll try finding the length of the normal myself and see what happens.

[edit:] I also reinstalled the sdk =) didn't work.

##### Share on other sites
What do u and v look like just before the cross product is calculated? I'm not sure how it would handle that if they were the same vector.

EDIT: Nevermind, I just read that you said the normal looked fine going into the Normalize function.

Chris

##### Share on other sites
Just try writing a small app like i did and see if the functions work or not...

1. 1
Rutin
47
2. 2
3. 3
4. 4
5. 5

• 10
• 27
• 20
• 9
• 20
• ### Forum Statistics

• Total Topics
633405
• Total Posts
3011681
• ### Who's Online (See full list)

There are no registered users currently online

×