D3DXVec3Normalize

Started by
14 comments, last by evanofsky 19 years, 1 month ago
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!
Advertisement
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?
_____________________________http://www.deepbluefuture.com"Set Phasers to neuter...""2+2=5 for sufficiently large values of 2."
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.
John BoltonLocomotive Games (THQ)Current Project: Destroy All Humans (Wii). IN STORES NOW!
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
// vectors on the quad.
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.
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 =)
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...
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);

Maybe someone haxxored your code and made a #define D3DXVec3Normalize Awww

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

You never know ^_~
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.
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
Chris ByersMicrosoft DirectX MVP - 2005
Just try writing a small app like i did and see if the functions work or not...

This topic is closed to new replies.

Advertisement